Indicator not refreshing. Help is needed.
- Arrows not updating/refreshing in real time (mql5)
- How to open order
- Send order at closure of the candle
My knowledge of the mql5 programming language is minimal. But I wrote a simple custom indicator, the task of which is to display arrows near candles that meet certain conditions. First, all points with index i are found that satisfy the condition high[i]>high[i-1] && high[i]>high[i+1] (or low). then, for the selected candles, the same check is performed for comparison with neighbors (2th order) . And again (3rd order). But my indicator does not update with new candles, and my knowledge is not enough to understand how to fix it. Please, help.
CArrayInt *firstorderhigh=new CArrayInt; CArrayInt *firstorderlow=new CArrayInt; CArrayInt *secondorderhigh=new CArrayInt; CArrayInt *secondorderlow=new CArrayInt;
My knowledge of the mql5 programming language is minimal. But I wrote a simple custom indicator, the task of which is to display arrows near candles that meet certain conditions. First, all points with index i are found that satisfy the condition high[i]>high[i-1] && high[i]>high[i+1] (or low). then, for the selected candles, the same check is performed for comparison with neighbors (2th order) . And again (3rd order). But my indicator does not update with new candles, and my knowledge is not enough to understand how to fix it. Please, help.
for(i=limit; i<rates_total-1 && !IsStopped(); i++)
I would take Dominiks advice and move the array objects to OnInit
//global definitions CArrayInt *firstorderhigh; CArrayInt *firstorderlow; CArrayInt *secondorderhigh; CArrayInt *secondorderlow; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0,ArrBuffUp,INDICATOR_DATA); SetIndexBuffer(1,ArrBuffDown,INDICATOR_DATA); SetIndexBuffer(2,ArrThirdOrderUp,INDICATOR_DATA); SetIndexBuffer(3,ArrThirdOrderDown,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_ARROW,ArrowCodeUp); PlotIndexSetInteger(1,PLOT_ARROW,ArrowCodeDown); PlotIndexSetInteger(2,PLOT_ARROW,ThirdOrderCodeUp); PlotIndexSetInteger(3,PLOT_ARROW,ThirdOrderCodeDown); //--- Set the vertical shift of arrows in pixels PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-ArShift); PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,ArShift); PlotIndexSetInteger(2,PLOT_ARROW_SHIFT,-ArShift-10); PlotIndexSetInteger(3,PLOT_ARROW_SHIFT,ArShift+10); //--- Set as an empty value 0 PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE); IndicatorSetString(INDICATOR_SHORTNAME,"PivotPoints Second Order"); firstorderhigh=new CArrayInt; firstorderlow=new CArrayInt; secondorderhigh=new CArrayInt; secondorderlow=new CArrayInt; return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Clean up and release memory delete firstorderhigh; delete firstorderlow; delete secondorderhigh; delete secondorderlow; return; }
Can you be clear about what you mean by saying that the indicator does not update? It does not update when changing the timeframe? or it does not update arrow signals with time? I'm having an issue myself with one of my MA indicators whereby the MA plot slopes down horizontally away from the chart on occasion, and I have to click the refresh button on the chart to fix it.
You should probably initialize the arrays on every calculation and not just only when prev_calculated < 3, so move this code out of the condition
//--- clean up arrays ArrayInitialize(ArrBuffUp,EMPTY_VALUE); ArrayInitialize(ArrBuffDown,EMPTY_VALUE); ArrayInitialize(ArrThirdOrderDown,EMPTY_VALUE); ArrayInitialize(ArrThirdOrderUp,EMPTY_VALUE); if(prev_calculated<3) { limit=2; } else limit=rates_total-2;
I made some other changes and I'm attaching the script, but can't tell if the signals update with time as the market is currently closed. The buffers refresh a lot faster now when changing between timeframes
It's a good idea to not only unload the indicator, but close the chart where you added the indicator as well to remove the memory leaks when unloading the indicator/changing timeframe (you had to deallocate the memory on the heap with OnDeInit if you declare pointers to the object)
You can avoid using pointers entirely and then you can avoid manual memory management...please see this version of the script, I also tested it to see that it works fine.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use