I think my error was that I did not use a different variable for the second quantity.
Fixed code follows if it will of help to anyone in the future.
int start() //hmm, it does update itself on every new tick, so it has the potential to alert in real-time? { double GetRange, GetOC, Range; bool BarUP, Flag; double max=0,oc; int x=1,imax=0,up; if(OnlyLargestRange==true){ for(int y=1; y<LookBack; y++) { GetRange =(High[y]-Low[y]); if(Digits<4) GetRange=GetRange*100; else GetRange=GetRange*10000; oc =(Close[y]-Open[y]); if(Digits<4) oc=oc*100; else oc=oc*10000; if (Open[y]<Close[y]) up=1; else up=0; if(GetRange>max){max=GetRange;x=y;BarUP=up;GetOC=oc;} } //Alert(x); if (max > MinRange){ GetRange=max; if (BarUP==0) { ObjectDelete("L"+x); ObjectCreate("L"+x, OBJ_TREND, 0, Time[x],High[x],Time[x],Low[x] ); ObjectSet("L"+x,10,0); ObjectSet("L"+x,8,PaintBarWidth); ObjectSet("L"+x,6,BEAR); } etc.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Just to clarify I am asking for coding help (to learn) more than a quick fix for this particular issue.
I am modifying an existing indicator that marks any range larger than a minimum value (minRange) over a lookback period. I want it to mark only the largest range of the lookback period.
So I created two new variables. priorRange and newMaxRange.
On line 36 I check priorRange the same way that GetRange does, but I use [x-1] instead of x, which I think should be checking the previous bar. But actually it makes no difference if I use [x+1].
Then on line 37 I say if GetRange is >= priorRange set a value for newMaxRange that is the same as GetRange. In my mind this newMaxRange should only be updated in the loop whenever a new range value is larger than the prior one. This should ensure that newMaxRange is always the largest range value.
However as you can see if you test the code it marks every range that is greater than the minRange just as in the original code. I'm not sure why.
What is the correct way to do this?
Code follows