BackTester Binary Options

 

Good Afternoon.

How can i insert a backtester of the buffers like the image on mt4( for example: if 5minutes after the buffer 1 is greater than start count 1 win else count 1 loss)?

counter

#property copyright "Criado por Renato José"
#property description "A pedido de Jeferson Menchik"
#property description "Utilizar em gráficos M5, o alerta não repintará após fechamento do candle."

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 5
#property indicator_color1 Red
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 5
#property indicator_color2 Lime
#property indicator_label2 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

datetime time_alert; //used when sending alert
extern bool Audible_Alerts = true;
extern bool Push_Notifications = true;
extern bool AlertBackGround = false;

extern string ConfigRsi = "Configuracao RSI";
extern int Sobrevenda = 90;
extern int Sobrecompra = 10;

extern int MaxBars = 0;

extern string BGColorAlert = "Background Alert";
extern color BackgroundBuy = Lime;
extern color BackgroundSell = Red;
extern color BackgroundDefault = Black;

bool useTime = true;
int StartMinute=55;//|-------start hour time filter the week
int EndMinute=59;//|--------end hour time filter the week

extern int CandleSize=90;

double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Rule 1 @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      if(Audible_Alerts) Alert(type+" | Rule 1 @ "+Symbol()+","+Period()+" | "+message);
      if(Push_Notifications) SendNotification(type+" | Rule 1 @ "+Symbol()+","+Period()+" | "+message);
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()

  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 233);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 234);
 
  
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   
if (AlertBackGround)   
  { if ( ObjectFind( "lblChgBg" ) == -1 )   ObjectCreate( "lblChgBg", OBJ_LABEL, 0, 0, 0 );
    
   ObjectSet( "lblChgBg", OBJPROP_XDISTANCE, 0 );
   ObjectSet( "lblChgBg", OBJPROP_YDISTANCE, 0 );  
   ObjectSet( "lblChgBg", OBJPROP_CORNER, 0 );    
   ObjectSet( "lblChgBg", OBJPROP_BACK, true ); }
   
else ObjectDelete("lblChgBg");  
     
   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;
   if (MaxBars>0 && MaxBars<Bars) limit = MaxBars;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;      
       
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
   
   if(useTime)
         if( (TimeMinute(Time[i])>=StartMinute&&TimeMinute(Time[i])<=EndMinute)
         )
           
   
     {
      if (i >= MathMin(50000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
              
                        
            double RS = iRSI(NULL,0,3,0,i);
            double RS1 = iRSI(NULL,0,3,0,i+1);
            double RS2 = iRSI(NULL,0,3,0,i+2);
            double CS3 = iCustom(NULL,0,"Candle_Size_Alert",CandleSize,0,0,i+3);
            double CS2 = iCustom(NULL,0,"Candle_Size_Alert",CandleSize,0,0,i+2);
            double CS1 = iCustom(NULL,0,"Candle_Size_Alert",CandleSize,0,0,i+1);
            double CS = iCustom(NULL,0,"Candle_Size_Alert",CandleSize,0,0,i);
            double CL1 = iClose(NULL,0,i+1);
            double CL2 = iClose(NULL,0,i+2);
            
            
      //Indicator Buffer 1
      
      if((RS<Sobrecompra||RS1<Sobrecompra||RS2<Sobrecompra)&&RS<45&&CL1>CL2
      
      )
       
       {Buffer1[i] = Close[i] - iATR(NULL, PERIOD_CURRENT, 14, i);if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy Rule 1"); time_alert = Time[0]; }}                 
           
       
      else {Buffer1[i] = 0;}
        
      //Indicator Buffer 2 
      
      if((RS>Sobrevenda||RS1>Sobrevenda||RS2>Sobrevenda)&&RS>55&&CL1<CL2

       )
       
       {Buffer2[i] = Close[i] + iATR(NULL, PERIOD_CURRENT, 14, i);if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Sell Rule 1"); time_alert = Time[0]; }}                 
 
      else { Buffer2[i] = 0; }
      
      
        if ( Buffer1[i] )        ObjectSetText( "lblChgBg", "ggg", 600, "Webdings", BackgroundBuy );
   else if ( Buffer2[i] )   ObjectSetText( "lblChgBg", "ggg", 600, "Webdings", BackgroundSell );
   else          ObjectSetText( "lblChgBg", "ggg", 600, "Webdings", BackgroundDefault ); 
     }
   return(rates_total);
  }
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.
Files:
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
someone?
 
Please?
 

i try make this, but evertime count please i need so much learn this i will go crazy


if(close[i+5]>Buffer1[i]&&i>1){nVit=nVit+1;} else{nDer=nDer+1;}
if(close[i+5]<Buffer2[i]&&i>1){nVit=nVit+1;} else{nDer=nDer+1;}

ObjectCreate("Nome", OBJ_LABEL,0,0,0);// Creating obj.
ObjectSet("Nome", OBJPROP_CORNER, 0);    // Reference corner
ObjectSet("Nome", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Nome", OBJPROP_YDISTANCE, 15);// Y coordinate
ObjectSetText("Nome",Nome_do_indicador,10,"Arial",clrAliceBlue);

ObjectCreate("Vitórias", OBJ_LABEL,0,0,0);// Creating obj.
ObjectSet("Vitórias", OBJPROP_CORNER, 0);    // Reference corner
ObjectSet("Vitórias", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Vitórias", OBJPROP_YDISTANCE, 30);// Y coordinate
ObjectSetText("Vitórias","Vitórias:"+nVit,10,"Arial",clrAliceBlue);

ObjectCreate("Derrotas", OBJ_LABEL,0,0,0);// Creating obj.
ObjectSet("Derrotas", OBJPROP_CORNER, 0);    // Reference corner
ObjectSet("Derrotas", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Derrotas", OBJPROP_YDISTANCE, 45);// Y coordinate
ObjectSetText("Derrotas","Derrotas:"+nDer,10,"Arial",clrAliceBlue);

ObjectCreate("wR", OBJ_LABEL,0,0,0);// Creating obj.
ObjectSet("wR", OBJPROP_CORNER, 0);    // Reference corner
ObjectSet("wR", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("wR", OBJPROP_YDISTANCE, 60);// Y coordinate
ObjectSetText("wR","WinRate:"+MathRound(nWr)+"%",10,"Arial",clrAliceBlue);
 

Like this
Files:
EURAUDM15.png  17 kb
 
Renato Jose:

Like this

I tried your indicator on my machine and it didn't load.

If you don't get the help you had hoped for here, you can hire somebody. People don't work for free you know.

 
mt4ski:

Tentei seu indicador na minha máquina e não carregou.

Se você não conseguir a ajuda que esperava aqui, pode contratar alguém. As pessoas não trabalham de graça, você sabe.

I know, I am not demanding anything from anyone, just asking for help because I believe that there is only one detail missing in the code, in case I do not find any charitable soul to clear this doubt, I will take my measures. thanks for instructing me
 
Renato Jose:

It is not clear what you are trying to do, maybe because English is not your first language.

You may find help by posting in the Portuguese forum.

 
Keith Watford:

Não está claro o que você está tentando fazer, talvez porque o inglês não seja sua primeira língua.

Você pode encontrar ajuda postando no fórum português.

it would just be an accountant with the following logic

for call (buffer1) if (the closing value of the fifth candle after a signal is greater than the closing value of this signal) adds 1 victory on the counter;

else (sum 1 loss)

for put (buffer2) vice versa

this for all arrows (indicator buffers)

 

my try

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[])
  {...

for (int i = limit-1; i>=0; i--)
if (i >= MathMin(50000-1, rates_total-1-50)) continue;
...

static double nVit = 1.00;
static double nDer = 1.00;

if (rates_total == prev_calculated) 
{
       if(Buffer1[6]>0 && Buffer1[6]!=EMPTY_VALUE && Close[1]>Buffer1[6])
        {
         nVit=nVit+1;
        }
      else
        {
         nDer=nDer+1;
        }
     
      if(Buffer2[6]>0 && Buffer2[6]!=EMPTY_VALUE && Close[1]<Buffer2[6])
        {
         nVit=nVit+1;
        }
      else
        {
         nDer=nDer+1;
        }
     }
ObjectCreate("Nome", OBJ_LABEL,0,0,0);// Creating obj.
ObjectSet("Nome", OBJPROP_CORNER, 0);    // Reference corner
ObjectSet("Nome", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Nome", OBJPROP_YDISTANCE, 15);// Y coordinate
ObjectSetText("Nome",Nome_do_indicador,10,"Arial",clrAliceBlue);

ObjectCreate("Vitórias", OBJ_LABEL,0,0,0);// Creating obj.
ObjectSet("Vitórias", OBJPROP_CORNER, 0);    // Reference corner
ObjectSet("Vitórias", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Vitórias", OBJPROP_YDISTANCE, 30);// Y coordinate
ObjectSetText("Vitórias","Vitórias:"+(nVit-1),10,"Arial",clrAliceBlue);

ObjectCreate("Derrotas", OBJ_LABEL,0,0,0);// Creating obj.
ObjectSet("Derrotas", OBJPROP_CORNER, 0);    // Reference corner
ObjectSet("Derrotas", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Derrotas", OBJPROP_YDISTANCE, 45);// Y coordinate
ObjectSetText("Derrotas","Derrotas:"+(nDer-1),10,"Arial",clrAliceBlue);

ObjectCreate("wR", OBJ_LABEL,0,0,0);// Creating obj.
ObjectSet("wR", OBJPROP_CORNER, 0);    // Reference corner
ObjectSet("wR", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("wR", OBJPROP_YDISTANCE, 60);// Y coordinate
ObjectSetText("wR","WinRate:"+NormalizeDouble(((nVit-1)/(nVit+nDer-2)*100),Digits)+"%",10,"Arial",clrAliceBlue);


}

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

my result :(