Moving Avg. on chart when backtesting??

 

Hi All...I searched but can't find an answer. When backtesting an EA I'd like to see Moving Average lines from an indicator on the chart... I know that with Visualization "ON" I can drag the Moving Avg. Indicator onto the chart and run/see it... but when testing for hours, doing many tests...that is a lot of dragging dropping and setting up. Is there a way that I can call the Ma from within the EA so that it automatically loads/shows Moving Avg lines on the chart when backtesting? I have tried adding it and saving the indicator to the chart and making it default.tpl but the EA does not use/show the Ma line during backtests.

 
  1. Start visual test, pause, put indicators on chart, save a template. Next run you can just add the template. Only problem is if the parameters the EA uses changes, chart won't reflect that.
  2. Have EA put lines on chart https://www.mql5.com/en/forum/130907
 

WHR.. Thanks for the reply.. Yes, it is much easier to save multiple indicators to the template and then load the template..great idea. I'll have to study the idea of actually embedding the indicator inside the EA. I was hoping I had missed something easy... like a line of code at the beginning of the EA to load/use a specific template automatically. It seems like the extra code "inside" the EA may effect how fast it runs and tests... Thank you for your help.

 
n8937g:

It seems like the extra code "inside" the EA may effect how fast it runs and tests... Thank you for your help.

Skip ticks that don't affect the EA. Draw the lines only on new bars. Don't draw in testing.
//+------------------------------------------------------------------+
//| Skip useless ticks                                               |
//+------------------------------------------------------------------+
double  CA.below,   CA.above=0;         // Export to start
void    CallAgain(double when){
    if (when>=Bid && CA.above > when) CA.above = when;
    if (when<=Bid && CA.below < when) CA.below = when;
    return;
}
int     start(){
    static datetime Time0;  bool newBar  = Time0 != Time[0],
                                 useless = CA.below <= Bid && Bid <= CA.above;
    if (useless && !newBar) return(0);  Time0 = Time[0];    #define INF 9999999
    if (!useless){
        CA.below = 0;   CA.above = INF;     // Skip additional useless ticks.
        OnTick();                           // Will reset CA's
        OpenNew();                          // Calls ModifyStops.
        if (Show.Objects)   DisplayLines();
    }   // Not useless
    else if (Show.Objects){
        ModifyStops();                      // Update TP/SL lines.
        DisplayLines();
    }
    if (Show.Comments) { ... }
}
int     init(){
    if ( IsTesting() && (!IsVisualMode()) ){    Show.Comments   = false;
                                                Show.Objects    = false;    }
...}
void    ModifyStops(){ ...
    for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS) ){
    &&  OrderMagicNumber() >= Magic.Number     // Only my orders w/
    &&  OrderSymbol()      == Symbol() ){      // and period and symbol
        ...
        if (plTP != oo.TP){ plTP = oo.TP; double ooTPbid=oo.TP+stop.to.Bid;
            pln=Polyline("TP"+(oo.ticket%1000), ooTPbid, Color.TP);
            ObjectSetText(pln, "TP="+DoubleToStr(ooTPbid,Digits), 10);
            CallAgain(ooTPbid +DIR* pips2dbl); }            // closed here.
    }   // Find my open order(s).
}
Reason: