Can't backtest an EA on the strategy tester, the strategy compares price action between 4 pairs in order to buy strong and sell weak

 

The EA is working in realtime, opening order and providing comments, it is still in developement. But I need to know how it performs in backtest in order to spot more coding errors if there might be. If anyone who can suggest a solution to this would give me a great deal of help as I am very new to programming in general, started since 3 weeks.


Thank you

Files:
 

The change ratios are only calculated once upon startup, this cannot work. You need to do the calculation in OnTick, and only once per bar to keep it performant.

https://www.mql5.com/en/forum/5762

How to detect a new bar
How to detect a new bar
  • 2011.12.29
  • www.mql5.com
Hi All, I'm a complete newbie to MQL5 but I've done a fair bit of coding for other platforms...
 
lippmaje:

The change ratios are only calculated once upon startup, this cannot work. You need to do the calculation in OnTick, and only once per bar to keep it performant.

https://www.mql5.com/en/forum/5762

Thank you so much, I just noticed that I didn't put them on the Ontick()
 
Samir Ahmane:

The EA is working in realtime, opening order and providing comments, it is still in developement. But I need to know how it performs in backtest in order to spot more coding errors if there might be. If anyone who can suggest a solution to this would give me a great deal of help as I am very new to programming in general, started since 3 weeks.

Not just what @lippmaje pointed out... When you attach the EA to EURJPY for example, you're effectively  using the Bid and Ask of EURJPY, and using the same SL and TP, to open orders for EURJPY, EURUSD, GBPUSD, GBPJPY, USDJPY and EURGBP... you won't get meaningful results be it real time or backtest...

 
  1. You can't trade other symbols in the MT4 tester.

  2. Seng Joo Thio: using the Bid and Ask of EURJPY,
    Exactly. On MT4 also, Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing prices.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

    The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero the first call.

  3. double Eur_Usd_End = iClose("EURUSD",Time_Frame,End_Index);
    double Eur_Gbp_End = iClose("EURGBP",Time_Frame,End_Index);
    Global and static variables work exactly the same way in MT4/MT5/C/C++.
    1. They are initialized once on program load.
    2. They don't update unless you assign to them.
    3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5 (or MT4 with strict which you should always use.)

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
    4. Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
                external static variable - Inflation - MQL4 programming forum
 
Samir Ahmane:

Can't backtest an EA on the strategy tester,

Also do not assume that other symbols have the same index as the current one. Always use iBarShift.
Reason: