Here are my bookmarks links on indicators:
https://www.mql5.com/en/articles/1500
https://www.mql5.com/en/articles/1503
https://www.mql5.com/en/forum/132447
https://www.mql5.com/en/articles/1411
https://www.mql5.com/en/forum/130907
why are you doing this?
limit=Bars-counted_bars/BarsBack;
Possible divide by zero error?
double BullValue(int i) { int Back = i + BarsBack; double r = 0; double v = 0; for(int j=i; j<Back; j++) { r = r + High[j] - Low[j]; if(Open[j] < Close[j]) v=v+Close[j] - Open[j]; } //MAYBE CHANGE THIS FROM // return(-r/v); // TO if(v==0 || r==0) return(0); else return(-r/v); }
Obviously, the same for the other function
limit=Bars-counted_bars/BarsBack;
Here are my bookmarks links on indicators:
https://www.mql5.com/en/articles/1500
https://www.mql5.com/en/articles/1503
https://www.mql5.com/en/forum/132447
https://www.mql5.com/en/articles/1411
https://www.mql5.com/en/forum/130907
why are you doing this?
Because I didn't know what else to try and came across someone's whacky solution using this technique at http://www.fxfisherman.com/forums/forex-metatrader/indicators/3690-trsi-indicator-issue.html.
Resolved I changed this one line: limit=Bars-counted_bars - RSI_Period; to this: limit=Bars-counted_bars/RSI_Period; and it now draws continually and the chart looks the same as the previous one bit doesn't stop, ran them side by side for a while...
Possible divide by zero error?
Obviously, the same for the other function
Thanks for this. It does appear to have been a zero divide issue. I made the suggested change and that solves the issue.
Thanks for this. It does appear to have been a zero divide issue. I made the suggested change and that solves the issue.
I'm happy that it has helped, but you should still address the other issue mentioned by others as your indi is recalculating many more bars than is necessary.
Thanks GumRai. I'm still trying to understand the advice received regarding indicator bar counting (advice made via a link to a different thread). What is confusing is that step one of said advice (see below) suggests decrementing but step 2 says don't decrement and then points to a thread (which I've for the most part read) where experts debate whether or not to decrement.
With the exception of the "/BarsBack" code inserted at the end of "limit=Bars-counted_bars/BarsBack;" all I did was use as a basis for bar counting the code in the supplied MACD example.
Is that code flawed? If so, what specifically should be changed?
Also, I've inserted code to check for a new bar as follows:
int start() { int limit; int counted_bars=IndicatorCounted(); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; double Value; if(NewBar()) { for(int i=0; i<limit; i++) PowerBuffer[i] = Value(i); } return(0); }
Custom function:
bool NewBar() { static datetime lastbar = 0; datetime curbar = iTime(Symbol(), Period(), 0); if(lastbar!=curbar) { lastbar=curbar; return (true); } else { return(false); } }
Is that the best way to handle new bar checks within an indicator?
Thanks
Bill
---------
- Always count down so you're not repainting
- Don't decrement Contradictory information on IndicatorCounted() - MQL4 forum
- Don't look back past the last candle.
----------
Take look at the source code to some of the standard indicators you will see it is not neccessary to find the newbar yourself in order to make it update bar zero, indicators will continually update themselves thanks to the relationship between IndicatorCounted() and Bars and the way you write the loop.
Typical multi purpose indicator loop, I use this all the time. Automatically updates bar zero on every tick.
int counted_bars=IndicatorCounted(); int i=Bars-1-counted_bars; while(i>=0) { ExtMapBuffer[i] = (High[i] + Low[i])*0.5; //creates a median price line i--; }
If you want to work on indicators a lot you need to fully understand why that works, so you know what to do when you need to limit where it starts counting from or to, there will be occasions when you need to count up instead of down, and even count up at the same time as counting down. You also must understand exactly what IndicatorCounted() does.
Take look at the source code to some of the standard indicators you will see it is not neccessary to find the newbar yourself in order to make it update bar zero, indicators will continually update themselves thanks to the relationship between IndicatorCounted() and Bars and the way you write the loop.
Typical multi purpose indicator loop, I use this all the time. Automatically updates bar zero on every tick.
If you want to work on indicators a lot you need to fully understand why that works, so you know what to do when you need to limit where it starts counting from or to, there will be occasions when you need to count up instead of down, and even count up at the same time as counting down. You also must understand exactly what IndicatorCounted() does.
I don't want or need for bar 0 to update every tick, that's why I insert NewBar().
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm not able to figure out how to get the following indicator code to update. I've tried inserting RefreshRates() and inserted some suggested code around the "limit" line but to no avail. What needs to be changed in order to get this indicator to automatically update on the chart? Thanks. Bill