Troubles with CopyBuffer and iCustom in the Strategy Tester Visualisation

 

Hello,

I have the following problem:

In my expert advisor, I sometimes have to call "CopyBuffer" on every tick. This works perfectly in combination with any of the standard indicator handles. However, when applying iCustom to the indicator handle of CopyBuffer, a new indicator window is being created on every single tick when running the EA on the Strategy Tester, which obviously makes it impossible to test the EA. Inititally, I thought this problem could perhaps be related to a mistake in my custom indicator, but even using something like "iCustom(_Symbol,PERIOD_M10,"Examples\\ATR",15)" instead of "iATR(_Symbol,PERIOD_M10,atr_ratchet_bars)" causes the very same problem. The former indicator handle causes trouble and results in 1 new indicator window per tick while testing whereas the latter works fine and results in only 1 indicator window, even if called more than once.

I hope someone can help me with this problem.

Thank you,

Leon

 
I guess I discovered a dirty workaround by changing #property indicator_separate_window to #property indicator_chart_window during the test. Nevertheless, I would be happy to see a cleaner solution to this problem.
 

Declaring an indicator handle variable at the beginning of the source code and then calling that with CopyBuffer solved the problem. I do not understand why, though.

Example:

...

int custom_handle=iCustom(_Symbol,PERIOD_M10,"Custom");
double custom[];

...

void OnTick()
{
        ...
        CopyBuffer(custom_handle,0,0,1,custom);
        ...
}
        


With that solution, everything works as it should.
 
have experienced the same problem here, thanks for your solution! It works fine!
 

I think one solution is:

...

int handle = 0;
int first = 0;

void OnTick(void)
  {
   ...
   if(first == 0)
     {
      first = 1;
      handle = iCustom(_Symbol , PERIOD_CURRENT , "Custom");
     }
  }
 
  1. JacksonClay: I think one solution is:
    1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
                General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
                Messages Editor

    2. Think again. You created the handle, but haven't given the indicator time to create the data before use. Get the handle in OnInit.

  2. l.liesener: Declaring an indicator handle variable at the beginning of the source code and then calling that with CopyBuffer solved the problem. I do not understand why, though.
    Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
              How to call indicators in MQL5 - MQL5 Articles 12 March 2010

Reason: