|
Moving average of Moves
Ok need a bit of help with code, I am looking to determine a set of average moves around a MA, so from the oldest BAR, I look for the moves above and below, put them into an array then average that array.
here is the code I am starting with, looking for a bit of assistance to get it done.
double AverageMove()
{
int cbars = iBars(Symbol(),EntryTimeFrame);
int counted_bars = 0,RangeCounter=0,ndx=0,iLimit=0;
double retval,averagemove,pHValue,pLValue,MAvalue,RangeVa lue[],EntryPoint,cHigh,cLow;
bool reset,TradeShort,TradeLong;
iLimit=Bars-1;
if(Symbol() != "AUDNZD") return(0);
for(ndx=0; ndx<iLimit; ndx++)
{
MAvalue = iMA(Symbol(),EntryTimeFrame,EntryMAInterval,0,Movi ngAverageType,PRICE_MEDIAN,ndx);
pHValue = High[ndx];
pLValue = Low[ndx];
if(MAvalue < pHValue && MAvalue > pLValue)
{
if(Symbol() =="AUDNZD") Print("MAValue="+MAvalue+" pHValue="+pHValue+" plValue="+pLValue);
reset = true;
if(EntryPoint > 0 && cHigh > 0)
{
RangeCounter++;
RangeValue[RangeCounter]=cHigh - EntryPoint;
}
if(EntryPoint > 0 && cLow > 0)
{
RangeCounter++;
RangeValue[RangeCounter]=EntryPoint - cLow;
}
EntryPoint = MAvalue;
}
if(pHValue < MAvalue && reset) TradeShort = true;
if(pLValue > MAvalue && reset) TradeLong = true;
if(TradeLong)
{
reset = false;
cHigh = pHValue;
}
if(TradeShort)
{
reset = False;
cLow = pLValue;
}
}
ArraySetAsSeries(RangeValue,true);
retval=iMAOnArray(RangeValue,RangeCounter,13,1,PRI CE_MEDIAN,0);
Print("Average Move"+retval);
}
|