Indicator not plotting on strategy tester

 

Hi,

I wrote an indicator that works fine with live data, but it doesn't draw forward on the strategy tester (prints attached).

Can someone please point out what am I getting wrong? I'm looking for answers for days but couldn't find any..

Thank!


//+------------------------------------------------------------------+
//|                                                       prev_v7.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots   7
//--- plot A
#property indicator_label1  "A"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLimeGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot B
#property indicator_label2  "B"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Signal_Long
#property indicator_label3  "Signal Long"
#property indicator_type3   DRAW_ARROW
#property indicator_color3  clrWhite
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- plot Signal_Short
#property indicator_label4  "Signal Short"
#property indicator_type4   DRAW_ARROW
#property indicator_color4  clrDodgerBlue
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
//--- plot Exit_Long
#property indicator_label5  "Exit Long"
#property indicator_type5   DRAW_ARROW
#property indicator_color5  clrWhite
#property indicator_style5  STYLE_SOLID
#property indicator_width5  1
//--- plot Exit_Short
#property indicator_label6  "Exit Short"
#property indicator_type6   DRAW_ARROW
#property indicator_color6  clrDodgerBlue
#property indicator_style6  STYLE_SOLID
#property indicator_width6  1
//--- plot EMA
#property indicator_label7  "EMAA"
#property indicator_type7   DRAW_NONE
#property indicator_color7  clrDodgerBlue
#property indicator_style7  STYLE_SOLID
#property indicator_width7  1
//---
double         ABuffer[];
double         BBuffer[];
double         Signal_LongBuffer[];
double         Signal_ShortBuffer[];
double         Exit_LongBuffer[];
double         Exit_ShortBuffer[];
double         EMA_Buffer[];
int            MA_handle;

input int lb = 10;
input double sig = 3.5;
input double exit = 1.5;
input int ema = 500;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ABuffer,INDICATOR_DATA);
   SetIndexBuffer(1,BBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,Signal_LongBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,Signal_ShortBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,Exit_LongBuffer,INDICATOR_DATA);
   SetIndexBuffer(5,Exit_ShortBuffer,INDICATOR_DATA);
   SetIndexBuffer(6,EMA_Buffer,INDICATOR_DATA);

   MA_handle = iMA(_Symbol,_Period,ema,0,MODE_EMA,PRICE_CLOSE);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
      
   int limit = rates_total-prev_calculated;
   
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
   CopyBuffer(MA_handle,0,0,to_copy,EMA_Buffer);
   
   for(int i = lb -1; i<limit ;i++)
   {
      double u = 0, d = 0, s_long = 0, s_short = 0, e_long = 0, e_short = 0, ema_v = 0;
      
      for(int j=0; j<lb; j++)
      {
         if(close[i-j]>open[i-j]) u += close[i-j]-open[i-j];
         if(close[i-j]<open[i-j]) d += open[i-j]-close[i-j];
         
         ema_v = EMA_Buffer[i];
         
         
         if(u>(sig*d) && close[i]>ema_v) s_long = u+50;
            else {
                  s_long = EMPTY_VALUE;
                 }
         
         if(d>(sig*u) && close[i]<ema_v) s_short = d-50;
            else {
                  s_short = EMPTY_VALUE;
                 }
         
         if((d*exit)>u) e_long = u+20; 
            else {
                  e_long = EMPTY_VALUE;
                 }
         
         if((u*exit>d)) e_short = d-20 ;
            else {
                  e_short = EMPTY_VALUE;
                 } 
        
      ABuffer[i] = u;
      BBuffer[i] = d;
      Signal_LongBuffer[i] = s_long;
      Signal_ShortBuffer[i] = s_short;
      Exit_LongBuffer[i] = e_long;
      Exit_ShortBuffer[i] = e_short;
       }
    
   }
   

//--- return value of prev_calculated for next call
   return(rates_total-1);
  }
//+------------------------------------------------------------------+
Files:
unnamed.png  13 kb
live_chart.PNG  42 kb
tester.PNG  91 kb
 
mbsa:

Hi,

I wrote an indicator that works fine with live data, but it doesn't draw forward on the strategy tester (prints attached).

Can someone please point out what am I getting wrong? I'm looking for answers for days but couldn't find any..

Thank!


It's not related to the Strategy Tester. It doesn't update on a live chart either, it only works on history data.

   // On live update this will only be different from 0 on a new candle (=1), is it your intention ?
   int limit=rates_total-prev_calculated;

   int to_copy;
   // Useless as prev_calculated is NEVER greater than rates_total or lower than 0 (this is not allowed by the platform).
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;            
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
   // EMA_Buffer is an indicator buffer, how is it indexed ? What EMA_Buffer values (indexes) the CopyBuffer will update ?
   CopyBuffer(MA_handle,0,0,to_copy,EMA_Buffer);   // ALWAYS check the return value of CopyBuffer(), it can fail.

   ... // I didn't check further
 

1. You need to refuse iXXXX functions (iLow and the like) - all these arrays are in OnCalculate

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

2. You must discard "ArraySetAsSeries (***, true)

   ArraySetAsSeries(BullishBreakerPriceBuffer,true);
   ArraySetAsSeries(BullishBreakerSLBuffer,true);
   ArraySetAsSeries(BearishBreakerPriceBuffer,true);
   ArraySetAsSeries(BearishBreakerSLBuffer,true);

3. You must make a detour not in "+", but in "-"

 

You need to do this:

//--- detect current position
   int limit=prev_calculated-1;
   if(prev_calculated==0)
      {
         limit=3 ;
         ArrayInitialize(BullishBreakerPriceBuffer,NULL);
         ArrayInitialize(BullishBreakerSLBuffer,NULL);
         ArrayInitialize(BearishBreakerPriceBuffer,NULL);
         ArrayInitialize(BearishBreakerSLBuffer,NULL);
      }
    ***
   for(int i=limit;i<total&& !IsStopped() ;i++)
     {
      if(IsBullCandle(i-2,open,close) &&
 

You need to go to "-" -> that is, from the current bar to the left (if you look at the chart)

   int limit=prev_calculated-1;
   if(prev_calculated==0)
     {
      limit=numberOfCandles-1; // for half data divide rates total here and minus the number of candles
      ArrayInitialize(BullishBreakerPriceBuffer,EMPTY_VALUE);
      ArrayInitialize(BullishBreakerSLBuffer,EMPTY_VALUE);
      ArrayInitialize(BearishBreakerPriceBuffer,EMPTY_VALUE);
      ArrayInitialize(BearishBreakerSLBuffer,EMPTY_VALUE);
     }
//--- Bullish Breaker Cycle
   double buyBreakerPrice=EMPTY_VALUE;
   double buySL=EMPTY_VALUE;
   for(int i=limit; i<rates_total && !IsStopped(); i++)
     {
      //---
      BullishBreakerPriceBuffer[i]=EMPTY_VALUE;
      BullishBreakerSLBuffer[i]=EMPTY_VALUE;
      BearishBreakerPriceBuffer[i]=EMPTY_VALUE;
      BearishBreakerSLBuffer[i]=EMPTY_VALUE;
      // Left Most Candle i.e. 3rd && Middle Candle i.e. 2nd && 1st Candle i.e. 1st
      bool bullishPattern1 = IsBullCandle(i,open,close) && IsBearCandle(i-1, open, close) && IsBullCandle(i-2, open, close);
      bool bullishPattern2 = bullishPattern1 && IsBullCandle(i-3,open,close);
      if(bullishPattern1 && close[i-2] > high[i-1])
 
Draw your patterns in the form of pictures - this will make it much clearer.
 
Hafiz Tamur Ahmed:

Is it reason why I'm not having plots and data in tester for time period under testing???

Forum on trading, automated trading systems and testing trading strategies

Indicator not plotting on strategy tester

Vladimir Karputov, 2021.07.11 13:10

Draw your patterns in the form of pictures - this will make it much clearer.

 
Hafiz Tamur Ahmed:

Have you tried this code? That you coded yourself? Cause upon changing it doesn't show anything.

Forum on trading, automated trading systems and testing trading strategies

Indicator not plotting on strategy tester

Vladimir Karputov, 2021.07.11 13:10

Draw your patterns in the form of pictures - this will make it much clearer.

 
Sorry, I'm getting out of this thread: I have asked three times that you show the PICTURE with patterns.
I hope that next time you will be attentive to the requests of those people who want to help you.
 
Hafiz Tamur Ahmed :

Yeah sure the request should be clear enough to covey the message not that unambiguous one. 

Here is the concerned screen shot of one of the pattern that I have code it the indicator. Hope that makes any sense now.

Here is the correct numbering: