Help wanted: Some indicators clones itself in the strategy visulator after adding EA !!!

 

Hi guys,

I am new at the coding and have big problem and need your help:

Lot of custom or default indicator works in my EA well. But some indicators not. For example this amazing indicator (https://www.mql5.com/en/code/21059)  doesnt work when i add to EA and run. It refreshs and clones itself at the strategy visualitor. Its looks like


BB_MACD

My code is:

**********************************************************************************

//////////////

void tickProcess(int index)

  {

 orderClose(index);

  int bbMacdDefinition = iCustom(sympol,0, "BB_MACD");

   double ExtMapBuffer1[]; // bbMACD

   double ExtMapBuffer2[]; // bbMACD color

   double ExtMapBuffer3[]; // Upper band

   double ExtMapBuffer4[]; // Lower band

   double ExtMapBuffer5[]; // Data for "iMAOnArray()"

   double MABuff1[];

   double MABuff2[];

   double bbMACD[];

   ArraySetAsSeries(ExtMapBuffer1, true);

   ArraySetAsSeries(ExtMapBuffer2, true);

   ArraySetAsSeries(ExtMapBuffer3, true);

   ArraySetAsSeries(ExtMapBuffer4, true);

   ArraySetAsSeries(ExtMapBuffer5, true);

   ArraySetAsSeries(MABuff1, true);

   ArraySetAsSeries(MABuff2, true);

   ArraySetAsSeries(bbMACD, true);

   CopyBuffer(bbMacdDefinition,0,0,6,ExtMapBuffer1);

      CopyBuffer(bbMacdDefinition,1,0,6,ExtMapBuffer2);

         CopyBuffer(bbMacdDefinition,2,0,6,ExtMapBuffer3);

            CopyBuffer(bbMacdDefinition,3,0,6,ExtMapBuffer4);

               CopyBuffer(bbMacdDefinition,4,0,6,ExtMapBuffer5);

               CopyBuffer(bbMacdDefinition,5,0,6,MABuff1);

               CopyBuffer(bbMacdDefinition,6,0,6,MABuff2);

               CopyBuffer(bbMacdDefinition,7,0,6,bbMACD);

///////////

******************************************************************************

I asked Mr Rakic for solutions and he shared that code:

 static int bbMACDDefinition=INVALID_HANDLE;

          if (bbMACDDefinition==INVALID_HANDLE) bbMACDDefinition = iCustom(_Symbol,_Period,"BB stops - MACD");    //Doesnt work ! I guess MT bug.

          if (bbMACDDefinition==INVALID_HANDLE) return;

 ***************************************************************************

I added and its look like and doesnt work.


//+------------------------------------------------------------------+

void tickProcess(int index)

  {


   orderClose(index);

   

    static int bbMACDDefinition=INVALID_HANDLE;

          if (bbMACDDefinition==INVALID_HANDLE) bbMACDDefinition = iCustom(_Symbol,_Period,"BB stops - MACD");    //Doesnt work ! I guess MT bug.

          if (bbMACDDefinition==INVALID_HANDLE) return;

 

   

   

  int bbMacdDefinition = iCustom(sympol,0, "BB_MACD");

   double ExtMapBuffer1[]; // bbMACD

   double ExtMapBuffer2[]; // bbMACD color

   double ExtMapBuffer3[]; // Upper band

   double ExtMapBuffer4[]; // Lower band

   double ExtMapBuffer5[]; // Data for "iMAOnArray()"

   double MABuff1[];

   double MABuff2[];

   double bbMACD[];

   ArraySetAsSeries(ExtMapBuffer1, true);

   ArraySetAsSeries(ExtMapBuffer2, true);

   ArraySetAsSeries(ExtMapBuffer3, true);

   ArraySetAsSeries(ExtMapBuffer4, true);

   ArraySetAsSeries(ExtMapBuffer5, true);

   ArraySetAsSeries(MABuff1, true);

   ArraySetAsSeries(MABuff2, true);

   ArraySetAsSeries(bbMACD, true);

   CopyBuffer(bbMacdDefinition,0,0,6,ExtMapBuffer1);

      CopyBuffer(bbMacdDefinition,1,0,6,ExtMapBuffer2);

         CopyBuffer(bbMacdDefinition,2,0,6,ExtMapBuffer3);

            CopyBuffer(bbMacdDefinition,3,0,6,ExtMapBuffer4);

               CopyBuffer(bbMacdDefinition,4,0,6,ExtMapBuffer5);

               CopyBuffer(bbMacdDefinition,5,0,6,MABuff1);

               CopyBuffer(bbMacdDefinition,6,0,6,MABuff2);

               CopyBuffer(bbMacdDefinition,7,0,6,bbMACD);

 

************************************************

What can i do?


  


               

BB Stops - MACD
BB Stops - MACD
  • www.mql5.com
MACD indicator that is using very well known BB Stops instead of using signal line for signals. You can control the % risk based for the signals (the smaller the risk %, the faster the BB Stops are reacting), but some experimenting is advised before using in real trading.
 

Seems that you are not reading the answers.

Your question has been answered. The error is in your code not in the called code nor in the nature of the called code. As soon as you apply the provided example fix (or any similar code correction) to your erroneous code you shall have no such error any more (the bellow example is produced with the code provided to you as a solution to your coding error and as you can see no duplicate instances loaded). Placing a comment that it does not work is a nonsense since that solution (as many other solutions) is working



PS: the mother of all errors is in the assumption that the error lays outside of your own code. Hence the first rule of debugging is to check your own code and then, and only then, when all the possible errors in your own code are eliminated you can start looking for other reasons. The way you are going is not leading into a direction that will keep you interested and productive in real coding for any longer time

 
You have to define the array in the global code and initialize in on init, even arraysetassirie have to define in on init, only copy buffers should be in ontick or someone else
 
cuneytates:

Hi guys,

I am new at the coding and have big problem and need your help:

Lot of custom or default indicator works in my EA well. But some indicators not. For example this amazing indicator (https://www.mql5.com/en/code/21059)  doesnt work when i add to EA and run. It refreshs and clones itself at the strategy visualitor. Its looks like


My code is:

**********************************************************************************

//////////////

void tickProcess(int index)

  {

 orderClose(index);

  int bbMacdDefinition = iCustom(sympol,0, "BB_MACD");

   double ExtMapBuffer1[]; // bbMACD

   double ExtMapBuffer2[]; // bbMACD color

   double ExtMapBuffer3[]; // Upper band

   double ExtMapBuffer4[]; // Lower band

   double ExtMapBuffer5[]; // Data for "iMAOnArray()"

   double MABuff1[];

   double MABuff2[];

   double bbMACD[];

   ArraySetAsSeries(ExtMapBuffer1, true);

   ArraySetAsSeries(ExtMapBuffer2, true);

   ArraySetAsSeries(ExtMapBuffer3, true);

   ArraySetAsSeries(ExtMapBuffer4, true);

   ArraySetAsSeries(ExtMapBuffer5, true);

   ArraySetAsSeries(MABuff1, true);

   ArraySetAsSeries(MABuff2, true);

   ArraySetAsSeries(bbMACD, true);

   CopyBuffer(bbMacdDefinition,0,0,6,ExtMapBuffer1);

      CopyBuffer(bbMacdDefinition,1,0,6,ExtMapBuffer2);

         CopyBuffer(bbMacdDefinition,2,0,6,ExtMapBuffer3);

            CopyBuffer(bbMacdDefinition,3,0,6,ExtMapBuffer4);

               CopyBuffer(bbMacdDefinition,4,0,6,ExtMapBuffer5);

               CopyBuffer(bbMacdDefinition,5,0,6,MABuff1);

               CopyBuffer(bbMacdDefinition,6,0,6,MABuff2);

               CopyBuffer(bbMacdDefinition,7,0,6,bbMACD);

///////////

******************************************************************************

I asked Mr Rakic for solutions and he shared that code:

 static int bbMACDDefinition=INVALID_HANDLE;

          if (bbMACDDefinition==INVALID_HANDLE) bbMACDDefinition = iCustom(_Symbol,_Period,"BB stops - MACD");    //Doesnt work ! I guess MT bug.

          if (bbMACDDefinition==INVALID_HANDLE) return;

 ***************************************************************************

I added and its look like and doesnt work.


//+------------------------------------------------------------------+

void tickProcess(int index)

  {


   orderClose(index);

   

    static int bbMACDDefinition=INVALID_HANDLE;

          if (bbMACDDefinition==INVALID_HANDLE) bbMACDDefinition = iCustom(_Symbol,_Period,"BB stops - MACD");    //Doesnt work ! I guess MT bug.

          if (bbMACDDefinition==INVALID_HANDLE) return;

 

   

   

  int bbMacdDefinition = iCustom(sympol,0, "BB_MACD");

   double ExtMapBuffer1[]; // bbMACD

   double ExtMapBuffer2[]; // bbMACD color

   double ExtMapBuffer3[]; // Upper band

   double ExtMapBuffer4[]; // Lower band

   double ExtMapBuffer5[]; // Data for "iMAOnArray()"

   double MABuff1[];

   double MABuff2[];

   double bbMACD[];

   ArraySetAsSeries(ExtMapBuffer1, true);

   ArraySetAsSeries(ExtMapBuffer2, true);

   ArraySetAsSeries(ExtMapBuffer3, true);

   ArraySetAsSeries(ExtMapBuffer4, true);

   ArraySetAsSeries(ExtMapBuffer5, true);

   ArraySetAsSeries(MABuff1, true);

   ArraySetAsSeries(MABuff2, true);

   ArraySetAsSeries(bbMACD, true);

   CopyBuffer(bbMacdDefinition,0,0,6,ExtMapBuffer1);

      CopyBuffer(bbMacdDefinition,1,0,6,ExtMapBuffer2);

         CopyBuffer(bbMacdDefinition,2,0,6,ExtMapBuffer3);

            CopyBuffer(bbMacdDefinition,3,0,6,ExtMapBuffer4);

               CopyBuffer(bbMacdDefinition,4,0,6,ExtMapBuffer5);

               CopyBuffer(bbMacdDefinition,5,0,6,MABuff1);

               CopyBuffer(bbMacdDefinition,6,0,6,MABuff2);

               CopyBuffer(bbMacdDefinition,7,0,6,bbMACD);

 

************************************************

What can i do?


  


               

put iCustom(...,  and all ArraySetAsSeries(... in OnInit() method....

 

Problem solved.

MT5 has no bug, i am the bug  :)

I moved to indicator adress to OnInit section.