Hi I'm trying to make an indicator using Jim Slomans formula which is basically this:
Price average movement per unit time = price/ sqrt(totaltime)
for example you want to look at prices 40 bars back and compare them each to the current price like this 0-2, 0-4, 0-6 where the interval, and look back period are user defined. The difference is divided by the square root of the time interval. So for example price MathLog(P)*1000 = 300 over 11 bars. The average bar move is 300 / Mathsqrt(11). Finally you average all of the comparisons and plot your chart.
I don't have a problem getting the logs of the prices, but can't figure out how to store periodic differences divided by the square root of time. I've attached what code I have so far. Thanks , Dustin
//+------------------------------------------------------------------+
//| d.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//|
http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int period=40;
extern int interval=1;
extern bool fibo;
double ExtMapBuffer1 [];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle (0,DRAW_LINE);
SetIndexBuffer (0, ExtMapBuffer1);
string short_name = "It's working";
IndicatorShortName (short_name);
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
if (counted_bars<0) return (-1);
if (counted_bars>0) counted_bars--;
int count2=0, pos = Bars-counted_bars;
double pricearray[];
double logprice[];
double pricedif[][];
double pricesum;
double priceave;
double difsum, difave;
while (pos>=0)
{
pricearray[pos] = (Close[pos]*1000);
logprice[pos] = MathLog(pricearray[pos]*1000);
while (count2 <= period*interval)
{
pricedif[pos][count2] = logprice[pos]-logprice[pos-count2*interval];
pricesum = pricedif[pos][count2] + pricesum;
count2++;
}
priceave = pricesum/period; //sum of bars divided by total number
ExtMapBuffer1[pos] = priceave;
pos--;
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+