EA calls iCustom for each new bar and overwrites the indicator

 

Hi everyone!

I've made an simple indicator that prints the volume of the last 100 bars, inside that bar

The same indicator also has a buffer that holds 1 for a long signal and 2 for a short signal.

When I call this indicator from inside the EA with the iCustom function to get the long/short values it works ok.

The problem that I have is that for each bar, and new iCustom call, I see the volume numbers printed again. It's like the loop runs again for 100 bars instead of only once.

How the EA, iCustom and the indicator should work together so I print the volume of the last 100 bars only once and then the volume of each new bar?

I attached the code.

Thank you! 

Edited to add the the correct EA file.

Edit 2:

What I want to see: volume printed for the last 100 bars and then only for the last formed bar (bar 1)

link

What is happening: the volumes are printed again for all the bars, every time a new bar appears (I moved a couple of them, but the rest are duplicated as well)

link

Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
iCustom - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
indi.mq4  6 kb
ea.mq4  2 kb
 
theodore: The problem that I have is that for each bar, and new iCustom call, I see the volume numbers printed again. It's like the loop runs again for 100 bars instead of only once.

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code.

 

I attached by mistake the ex.4 file instead of mq.4 

And corrected it now. 

Thank you!

 
theodore #: And corrected it now.
double signal = iCustom(NULL, 0, "4.Indicators_2022\\Trading\\test\\indi", 0, 1);  // buffer 0, brick 1
  1. Do you really have a “«DataFolder»/MQL4/Indicators/4.Indicators_2022/Trading/test/indi.ex4”?

    File (Alt+F) → Open Data Folder and verify you put it in the correct location.

  2. Don't hard code constants. Write self-documenting code.
    Indicator
    EA
    SetIndexBuffer(0, signal_value);
    SetIndexBuffer(1, bars_volume);
    enum IndiBuff { signal_value, bars_volume}
    ⋮
    const string indi ="4.Indicators_2022\\Trading\\test\\indi";
    double signal = iCustom(NULL, 0, indi, signal_value, 1);
 

Yes, I have the indi.ex4 file in the "MQL4/Indicators/4.Indicators_2022/Trading/test/" location.

And I changed the constants.

But the problem remains... Thanks for taking the time, William!

 

I solved my own problem by modifying the for loop to work with Renko bars.

For some reason, the EA doesn't overwrites the values anymore.

I'll attach it, in case anyone will find it helpful.

Files: