OBJ_STDDEVCHANNEL GetValue Issue

 
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int BarTotal=200;

   string name="st";

   int chart_ID=0;
   double ChannelLevel;

   MqlRates date[];
   ArraySetAsSeries(date,true);
  CopyRates(NULL,PERIOD_CURRENT,0,210,date);

   datetime time=date[1].time;
   static datetime timestandart=date[2].time;

   if(time!=timestandart)
     {

      timestandart=time;

      ObjectDelete(chart_ID,name);


         if(ObjectCreate(chart_ID,name,OBJ_STDDEVCHANNEL,0,date[BarTotal].time,0,date[1].time,0))
           {


            ObjectSetDouble(chart_ID,name,OBJPROP_DEVIATION,1);

            ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,STYLE_SOLID);

            ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,3);

            ObjectSetInteger(chart_ID,name,OBJPROP_FILL,false);

            ObjectSetInteger(chart_ID,name,OBJPROP_BACK,true);

            ObjectSetInteger(chart_ID,name,OBJPROP_RAY_LEFT,false);

            ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,false);
            ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clrBlue);





           }
      ChannelLevel =NormalizeDouble(ObjectGetValueByTime(chart_ID,name,date[1].time,1),_Digits);
      Print(ChannelLevel);
     }





  }
//+------------------------------------------------------------------+

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

Hello,

I created an expert advisor based on the StdDev Channel. If it goes down, the system will look for sell trades, and if it goes up, it will look for buy trades. However, I had a problem with getting the values of the beginning and end points. Every time I run the expert advisor on backtesting, it gives different results, and I found out that it gives different results for the STDDev Channel. Then I simplified the code just to get the value of the STDDev Channel and print it every time a new bar came, but it keeps giving different values every time I run the system. I saved logs and an Excel file, and then compared the details. Please help me figure this out.

Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
 
You are updating the channel on each new candle. Why are you surprised you get different values ?
 
Alain Verleyen #:
You are updating the channel on each new candle. Why are you surprised you get different values ?

Every candle gives a different value, there is no problem with that. But after I saved backtesting results and ran it again a second time, the results did not match the backtesting results before.

The table below shows the same parameters and 2 different backtesting results, just one minute after I ran the first test.



 
Emre Cayir #: Every candle gives a different value, there is no problem with that. But after I saved backtesting results and ran it again a second time, the results did not match the backtesting results before. The table below shows the same parameters and 2 different backtesting results, just one minute after I ran the first test.

Please note that the Strategy Tester does not support the use of Graphical Objects, except in the visual testing mode. For an EA to work properly in the Strategy Tester and optimisations, it must not depend on graphical objects in any way for its decision logic.

Graphical Objects in Testing

During testing/optimization graphical objects are not plotted. Thus, when referring to the properties of a created object during testing/optimization, an Expert Advisor will receive zero values.

This limitation does not apply to testing in visual mode.

So, if you wish to make a reliable EA that will work flawlessly in the Strategy Tester, you will have to emulate what the Standard Deviation Channel would do and calculate the values in the EA code and not depend on the graphical object.

The same applies for MQL4:

Forum on trading, automated trading systems and testing trading strategies

EA Works on live & demo markets but not Tester

Fernando Carreiro, 2023.03.29 14:42

It does not work in the tester or optimiser because your EA depends on graphical objects for its decision logic.

The Strategy Tester does not support the use of Graphical Objects, except in the visual testing mode but only partially.

EDIT: For an EA to work properly in the Strategy Tester and optimisations, it must not depend on graphical objects in any way for its decision logic.

Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference

Graphical Objects in Testing

During visualization, the Expert Advisor interacts with a real chart. In case there is no visualization, the Expert Advisor works with a "virtual" chart that is not displayed. The former case has some peculiarities. During optimization, working with graphical objects is not supported.


Documentation on MQL5: MQL5 programs / Testing Trading Strategies
Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
Testing Trading Strategies - MQL5 programs - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: