I'm looking for a way to find the last high and last low based on moving averages. The arrows in the attached image show what I'm looking for.
I don't use the current moving average trend. I look for the last swings. I've drawn the lines that are the last 2 'swings' in the High and Low.
I've started the code (but I think my stroke is acting up). And I'm getting blanks on moving any further.
I'm not interested in drawing the lines. Just getting the values.
Attached Image
I don't use the current moving average trend. I look for the last swings. I've drawn the lines that are the last 2 'swings' in the High and Low.
I've started the code (but I think my stroke is acting up). And I'm getting blanks on moving any further.
I'm not interested in drawing the lines. Just getting the values.
Inserted Code
void OnStart() { double UpperLevel=0, LowerLevel=0, FastMA=0, SlowMA=0; int CurrentBar=1, CurrentDirection=0, LastDirection=0; bool AllFound=false, StillOnInitialDirection=true, FoundLong=false, FoundShort=false; while(!AllFound) { SlowMA=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,CurrentBar); FastMA=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,CurrentBar); if(CurrentBar==1) //set the inital direction { if(FastMA>SlowMA) { CurrentDirection=1; LastDirection=1; } if(FastMA<SlowMA) { CurrentDirection=2; LastDirection=2; } } if(CurrentBar>1) //Work on current direction { if(FastMA>SlowMA) { CurrentDirection=1; } if(FastMA<SlowMA) { CurrentDirection=2; } } if(StillOnInitialDirection) //See if we're out of the current direction { if(CurrentDirection!=LastDirection) { StillOnInitialDirection=false; } } if(!StillOnInitialDirection) { } } }