Help with EA CODE

[Deleted]  

My EA compiles with no error, but for some reason It will not start test in the strategy tester? Is there any error in my code that creates a bug.

I downloaded the pivot points from https://www.mql5.com/en/code/8685. My server is GMT +2, so my input for using iCustom() with pivots is -2.

here is my code


int start()
  {
//----
     R2 = iCustom(Symbol(),PERIOD_M30,"Pivot Points Daily(Shifted)",-2,1,0);
     R3 = iCustom(Symbol(),PERIOD_M30,"Pivot Points Daily(Shifted)",-2,0,0);
     S2 = iCustom(Symbol(),PERIOD_M30,"Pivot Points Daily(Shifted)",-2,5,0);
     S3 = iCustom(Symbol(),PERIOD_M30,"Pivot Points Daily(Shifted)",-2,6,0);
     cci = iCCI(Symbol(),PERIOD_M30,20,PRICE_TYPICAL,0);
     Hcci_1 = iCCI(Symbol(),PERIOD_M30,20,PRICE_HIGH,1);
     Hcci_2 = iCCI(Symbol(),PERIOD_M30,20,PRICE_HIGH,2);
     Hcci_3 = iCCI(Symbol(),PERIOD_M30,20,PRICE_HIGH,3);
     Lcci_1 = iCCI(Symbol(),PERIOD_M30,20,PRICE_LOW,1);
     Lcci_2 = iCCI(Symbol(),PERIOD_M30,20,PRICE_LOW,2);
     Lcci_3 = iCCI(Symbol(),PERIOD_M30,20,PRICE_LOW,3);
     int i = 0;
     //check time 
     if( Hour() != 10 )
     {
       while(10 != iTime(Symbol(),PERIOD_M30,i) )i++;
       cciLow = iCCI(Symbol(),PERIOD_M30,20,PRICE_TYPICAL,0);
       for(int j = 0; j<i; j++)cciLow = MathMin(cciLow,iCCI(Symbol(),PERIOD_M30,20,PRICE_LOW,j));
       for( j = 0; j<i; j++)cciHigh = MathMax(cciHigh,iCCI(Symbol(),PERIOD_M30,20,PRICE_HIGH,j));
     }
     
     HpercentCCI = (0.9*cciHigh);
     LpercentCCI = (0.9*cciLow);
     
     //********************************************************  SIGNAL ONE  FOR BULL/BEAR *********************************************************
    // while(iBarShift(Symbol(),PERIOD_M30,);
     if( (Close[1] > iCustom(Symbol(),PERIOD_M30,"Pivot Points Daily(Shifted)",-2,1,0))&&(Close[1] < iCustom(Symbol(),PERIOD_M30,"Pivot Points Daily(Shifted)",-2,1,0) )&&(iCCI(Symbol(),PERIOD_M30,20,PRICE_TYPICAL,0)>= HpercentCCI) )
     {
        BULLsig1 = true;
        Qhour = Hour() + 2;
        if( MathMod((Minute() + 30),60) < Minute())
        {
          Qminute = MathMod((Minute() + 30),60);
          Qhour++;
        } 
        else Qminute = Minute() + 30;
        //sets the time we must wait to set up second signal
        QtimeConst = StringConcatenate(Year(),".",Month(),Day()," ",Qhour,":",Qminute);
        Qtime = StrToTime(QtimeConst);
     }
     else BULLsig1 = false;
     
      if( (Close[1] < iCustom(Symbol(),PERIOD_M30,"Pivot Points Daily(Shifted)",-2,5,0))&&(Close[1] > iCustom(Symbol(),PERIOD_M30,"Pivot Points Daily(Shifted)",-2,5,0) )&&(iCCI(Symbol(),PERIOD_M30,20,PRICE_TYPICAL,0)<= LpercentCCI) )
      {
        BEARsig1 = true;
        if( MathMod((Minute() + 30),60) < Minute())
        {
          Qminute = MathMod((Minute() + 30),60);
          Qhour++;
        } 
        else Qminute = Minute() + 30;
        //sets the time we must wait to set up second signal
        QtimeConst = StringConcatenate(Year(),".",Month(),Day()," ",Qhour,":",Qminute);
        Qtime = StrToTime(QtimeConst);
      }
      else BEARsig1 = false;
      
     
     
     //******************************************************   SIGNAL TWO FOR BULL/BEAR ************************************************************
     Ctime = StrToTime( StringConcatenate(Year(),".",Month(),Day()," ",Hour(),":",Minute()));
     if( (Ctime > Qtime)&&(BULLsig1 == true) )
     {
         for(int k = 0; k < 5; k++)
         {
             if(Close[k] > R2)TC++;
         }
         if(TC >= 5)BULLsig2 = true;
         else BULLsig2 = false;
     }
     
      if( (Ctime > Qtime)&&(BEARsig1 == true) )
     {
         for( k = 0; k < 5; k++)
         {
             if(Close[k] < S2)TC++;
         }
         if(TC >= 5)BEARsig2 = true;
         else BEARsig2 = false;
     }
      
    //************************************************* SIGNAL THREE FOR BULL/BEAR***********************************************
    
    if( (BULLsig2 == true)&&(High[0]> R3 - 0.0006)&&(cci < 100) )
    {
       BULLsig3 = true;
       
    }
    
    if( (BEARsig2 == true)&&(Low[0]< S3 + 0.0006)&&(cci > 100*(-1) ) )
    {
       BEARsig3 = true;
       
    }
    //************************************************* SIGNAL FOUR FOR BULL/BEAR***************************************************
    
    if( (BULLsig3 == true)&&(Hcci_1 <100)&&(Hcci_2 <100)&&(Hcci_3 <100) )
    {
      BULLsig4 = true;
    }
    else BULLsig4 = true;
    
     if( (BEARsig3 == true)&&(Lcci_1 > 100*(-1))&&(Lcci_2 > 100*(-1))&&(Lcci_3 > 100*(-1)) )
    {
      BULLsig4 = true;
    }
    else BEARsig4 = true;
    
    
    //*********************************************** ORDER PLACEMENT ***************************************************************
   //code for bull order
    if( (BULLsig4 == true)&&(orderset) )
    { 
     
      //SL = Ask - 0.0024;
             RiskAmount = AccountEquity()*(EquityPercent / 100);
              TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
              if(Point == 0.001 || Point == 0.00001)TickValue *= 10;
              
              CalcLots = (RiskAmount/StopLoss) / TickValue;
              LotSize = CalcLots;
      
      SL = Bid + (StopLoss*PipPoint(Symbol()));
      TP = (R3 + R2)/2;
     // TP = MarketInfo("EURUSD",MODE_ASK) + (TakeProfit*PipPoint("EURUSD"));
      Ticket1 = OpenSellOrder(Symbol(), LotSize, GetSlippage(Symbol(),Slippage),SL,TP, MagicNumber,  "Buy Order");
      Ticket2 = OpenSellOrder(Symbol(), LotSize, GetSlippage(Symbol(),Slippage),SL,0, MagicNumber,  "Buy Order");
      orderset = true;
        
    }
    
    if( (BEARsig4 == true)&&(orderset) )
    { 
     
      
             RiskAmount = AccountEquity()*(EquityPercent / 100);
              TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
              if(Point == 0.001 || Point == 0.00001)TickValue *= 10;
              
              CalcLots = (RiskAmount/StopLoss) / TickValue;
              LotSize = CalcLots;
      
      SL = Ask - (StopLoss*PipPoint(Symbol()));
      TP = (S3 + S2)/2;
     
      Ticket1 = OpenBuyOrder(Symbol(), LotSize, GetSlippage(Symbol(),Slippage),SL,TP, MagicNumber,  "Buy Order");
      Ticket2 = OpenBuyOrder(Symbol(), LotSize, GetSlippage(Symbol(),Slippage),SL,0, MagicNumber,  "Buy Order");
      orderset = true;
        
    }
    
    
    
   //***************************************************** IF TARGET HIT BRING STOP TO BREAKEVEN AND AIM HIGHER(modify order)*******************
//----
if(TotalOrderCount(Symbol(), MagicNumber)>0 )
    {
      if(OrderSelect(Ticket2,SELECT_BY_TICKET,MODE_TRADES ))
      {
      
          if(OrderType() == OP_BUY)
          {
            TP2 = R2*(1.05);
             SL2 = OrderOpenPrice();
          }
          else
          {
              TP2 = S2*(0.95);
             SL2 = OrderOpenPrice();
          }
      
         while(breakeven != true)
         {
          breakeven =   AddStopProfit(Ticket2, SL2, TP2);
         }
      }
    }
    //****************************************************  CHECK IF ORDERS ARE CLOSED TO RESEST STRATEGY variables for future trade*******************************
    if((OrderSelect(Ticket1,SELECT_BY_TICKET)== true)&&(OrderSelect(Ticket2,SELECT_BY_TICKET)== true))
    {
       Ticket1 = -1;
       Ticket2 = -1;
       BULLsig1 = false;
       BULLsig2 = false;
       BULLsig3 = false;
       BULLsig4 = false;
       
       BEARsig1 = false;
       BEARsig2 = false;
       BEARsig3 = false;
       BEARsig4 = false;
       TP = 0;
       SL = 0;
       TP2 = 0;
       SL2 = 0;
       breakeven = false;
       orderset = false;
       
       Qhour = 0;
       Qminute = 0;
        Qtime =0;//Qualifying time
        Ctime = 0;//current time
        QtimeConst = "notime";
    }
    
   return(0);
  }
Simon Gniadkowski
17393
Simon Gniadkowski  
When you saved the Indicator did you rename it from Pivot Points - Daily (Shifted).mq4 to something else ?
[Deleted]  
RaptorUK:
When you saved the Indicator did you rename it from Pivot Points - Daily (Shifted).mq4 to something else ?

I downloaded it twice. I have one called Pivot Points - Daily (Shifted).mq4 and one called Pivot Points. Neither work when I put it in the code
Simon Gniadkowski
17393
Simon Gniadkowski  
jeemba2012:

I downloaded it twice. I have one called Pivot Points - Daily (Shifted).mq4 and one called Pivot Points. Neither work when I put it in the code

But you are not calling either of them in your code . . you are calling Pivot Points Daily(Shifted).mt4

iCustom(Symbol(),PERIOD_M30,  "Pivot Points Daily(Shifted)"  ,-2,1,0)
William Roeder
25064
William Roeder  
jeemba2012:
My EA compiles with no error, but for some reason It will not start test in the strategy tester? Is there any error in my code that creates a bug.
I downloaded the pivot points from https://www.mql5.com/en/code/8685.
  1. Not starting has nothing to do with the iCustom. Look in the journal. Add a Print to start so you know if it is starting or not.
  2. R2 = iCustom(Symbol(),PERIOD_M30,"Pivot Points Daily(Shifted)",-2,1,0);
    From https://www.mql5.com/en/code/8685 name of the file is "Pivot Points - Daily (Shifted).mq4" not "Pivot Points Daily(Shifted).mq4"
    Thats "Pivot Points - Daily (Shifted).mq4" unless you renamed it.
    #define PPD_S "Pivot Points - Daily (Shifted)"
    R2 = iCustom(Symbol(),PERIOD_M30,PPD_S,-2,1,0);
    R3 = iCustom(Symbol(),PERIOD_M30,PPD_S,-2,0,0);
    S2 = iCustom(Symbol(),PERIOD_M30,PPD_S,-2,5,0);
    S3 = iCustom(Symbol(),PERIOD_M30,PPD_S,-2,6,0);
[Deleted]  
RaptorUK:

But you are not calling either of them in your code . . you are calling Pivot Points Daily(Shifted).mt4


R2 = iCustom(Symbol(),PERIOD_M30,"Pivot Points - Daily(Shifted)",-2,1,0);


I changed it to this but it still does not work

[Deleted]  
WHRoeder:
  1. Not starting has nothing to do with the iCustom. Look in the journal. Add a Print to start so you know if it is starting or not.
  2. From https://www.mql5.com/en/code/8685 name of the file is "Pivot Points - Daily (Shifted).mq4" not "Pivot Points Daily(Shifted).mq4"
    Thats "Pivot Points - Daily (Shifted).mq4" unless you renamed it.

I tried this suggestion. But how will the print statements help if it the strategy tester will not start the EA. is there another way to use the print statements?

I deleted all my pivot point indicators and downloaded fresh without renaming it. and tried your suggestion but it still did not work.

 R2 = iCustom(Symbol(),PERIOD_M30,PPD_S,-2,1,0);
     R3 = iCustom(Symbol(),PERIOD_M30,PPD_S,-2,0,0);
     S2 = iCustom(Symbol(),PERIOD_M30,PPD_S,-2,5,0);
     S3 = iCustom(Symbol(),PERIOD_M30,PPD_S,-2,6,0);
[Deleted]  
jeemba2012:

I tried this suggestion. But how will the print statements help if it the strategy tester will not start the EA. is there another way to use the print statements?

I deleted all my pivot point indicators and downloaded fresh without renaming it. and tried your suggestion but it still did not work.


Could it be that I dont have an ex.4 file for the Pivot Points - Daily (Shifted) indicator?
Simon Gniadkowski
17393
Simon Gniadkowski  
Did you copy the Pivot Points Daily(Shifted).mq4 file into your \experts\indicators directory and then restart MT4 ? when MT4 starts it will compile the mt4 file and make an ex4 file.
[Deleted]  
RaptorUK:
Did you copy the Pivot Points Daily(Shifted).mq4 file into your \experts\indicators directory and then restart MT4 ? when MT4 starts it will compile the mt4 file and make an ex4 file.

Yes I did do that. So I guess I cant find the problem
Simon Gniadkowski
17393
Simon Gniadkowski  
jeemba2012:

Yes I did do that. So I guess I cant find the problem
Can you go through what you are doing to get this EA to run in the Strategy tester . . . for example, do you have history data for the date period you are trying to run ?