Question from a beginner pt.2

 

Hi guys!

I am trying to create a trading strategy, which follows a simple rule:


If Reversal Indicator prints some specific values and we have less than 10 open positions then we open a Sell position. 

If Reversal Indicator prints these values but we have 10 open positions, then the strategy should close ALL active Sell positions.


Although no error appears, my code is not working. The strategy even stopped printing Reversal Alert's values, which is odd.

Could you please give me some advice on how to fix this? I guess it involves some error with brackets? 

I would be extremly grateful for any help.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

//input int TakeProfit = 10;
//input int StopLoss = 30;
//input double volume = 0.1;



double semaforHandle0,semaforHandle1,semaforHandle2, semaforHandle3,semaforHandle4,semaforHandle5,semaforHandle6,semaforHandle7; 
double reversalAlertHandle0,reversalAlertHandle1,reversalAlertHandle2,reversalAlertHandle3,reversalAlertHandle4,reversalAlertHandle5,reversalAlertHandle6,reversalAlertHandle7;
double SemafornewHandle0, SemafornewHandle1,SemafornewHandle2,SemafornewHandle3,SemafornewHandle4,SemafornewHandle5,SemafornewHandle6,SemafornewHandle7; 
double zigZagHandle0,zigZagHandle1,zigZagHandle2,zigZagHandle3,zigZagHandle4,zigZagHandle5,zigZagHandle6,zigZagHandle7;

double semafor123TrianglesLabelBuffer0[],semafor123TrianglesLabelBuffer1[],semafor123TrianglesLabelBuffer2[],semafor123TrianglesLabelBuffer3[],semafor123TrianglesLabelBuffer4[],semafor123TrianglesLabelBuffer5[],semafor123TrianglesLabelBuffer6[],semafor123TrianglesLabelBuffer7[];
double semafor123TrianglesNewLabelBuffer0[],semafor123TrianglesNewLabelBuffer1[],semafor123TrianglesNewLabelBuffer2[],semafor123TrianglesNewLabelBuffer3[],semafor123TrianglesNewLabelBuffer4[],semafor123TrianglesNewLabelBuffer5[],semafor123TrianglesNewLabelBuffer6[],semafor123TrianglesNewLabelBuffer7[];
double reversalAlertLabelBuffer0[],reversalAlertLabelBuffer1[],reversalAlertLabelBuffer2[],reversalAlertLabelBuffer3[],reversalAlertLabelBuffer4[],reversalAlertLabelBuffer5[],reversalAlertLabelBuffer6[],reversalAlertLabelBuffer7[];
double zigZagLabelBuffer0[],zigZagLabelBuffer1[],zigZagLabelBuffer2[],zigZagLabelBuffer3[],zigZagLabelBuffer4[],zigZagLabelBuffer5[],zigZagLabelBuffer6[],zigZagLabelBuffer7[];


double LastHigh; 
double LastLow; 

int OnInit() 
  {
   Print("Version 1.15");

   return(INIT_SUCCEEDED);
   }                   
int start()
  {
  
  LastHigh = iHigh (NULL,0,1);
  LastLow = iLow(NULL,0,1);
  
  Print("Previous High/Low =" ,  iTime(NULL,0,1),",",
                                 iHigh(NULL, 0,1),",",
                                 iLow(NULL,0,1));
                                
   SemafornewHandle0=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,0,5);
   SemafornewHandle1=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,1,5);
   SemafornewHandle2=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,2,5);
   SemafornewHandle3=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,3,5);
   SemafornewHandle4=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,4,5);
   SemafornewHandle5=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,5,5);       
   Print("Semafor123TriangleNew = ", SemafornewHandle0," ",SemafornewHandle1," ",SemafornewHandle2," ",SemafornewHandle3," ",SemafornewHandle4," ",SemafornewHandle5," ",SemafornewHandle6," ",SemafornewHandle7);

   reversalAlertHandle0=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,0,1);
   reversalAlertHandle1=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,1,1);
   reversalAlertHandle2=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,2,1);
   reversalAlertHandle3=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,3,1);
   reversalAlertHandle4=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,4,1);
   reversalAlertHandle5=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,5,1);
   reversalAlertHandle6=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,6,1);
   reversalAlertHandle7=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,7,1);     
   Print("ReversalAlert = ",reversalAlertHandle0," ",reversalAlertHandle1," ",reversalAlertHandle2," ",reversalAlertHandle3," ",reversalAlertHandle4,"",reversalAlertHandle5," ",reversalAlertHandle6,"",reversalAlertHandle7);  
}

void OnTick()
   {
   if ((reversalAlertHandle0 !=0)&&(reversalAlertHandle2 !=0)&&(reversalAlertHandle4 !=0)&&(OrdersTotal()<10)) 
   
   OrderSend(_Symbol,OP_SELL,0.1,Bid,3,0,(Bid-300*_Point),NULL,0,0,Green);
   
   if ((reversalAlertHandle0 !=0)&&(reversalAlertHandle2 !=0)&&(reversalAlertHandle4 !=0)&&(OrdersTotal()==10))
   
   CloseSellPositions();
   }
 
void CloseSellPositions()
   {
   
   for (int i=OrdersTotal()-1; i >= 0; i--)
   {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   
   string CurrencyPair = OrderSymbol();
   
   if(_Symbol==CurrencyPair)
   
   if(OrderType()==OP_SELL)
   {
   OrderClose(OrderTicket(),OrderLots(),Ask,3,NULL);
   }  
   }
   }
    
      
 
Sebastian Woźniczka:

It looks like the calculations are done in the "start" function, but you don't call that function at all from the OnTick function.

Also, "start" is a reserved keyword in MQL. Since you're using #property strict, this is no big deal, but it's not good practice.

BTW, this  is a lot of repeating code:

   SemafornewHandle0=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,0,5);
   SemafornewHandle1=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,1,5);
   SemafornewHandle2=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,2,5);
   SemafornewHandle3=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,3,5);
   SemafornewHandle4=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,4,5);
   SemafornewHandle5=iCustom(NULL,0,"Semafor + 123Triangles new",true, 12.0,34.0,234.0,15,15,15,500,0,true,0,false,true,0.113225,Orange,DodgerBlue,Red,2,1,0,false,false,5,5);       
   Print("Semafor123TriangleNew = ", SemafornewHandle0," ",SemafornewHandle1," ",SemafornewHandle2," ",SemafornewHandle3," ",SemafornewHandle4," ",SemafornewHandle5," ",SemafornewHandle6," ",SemafornewHandle7);

   reversalAlertHandle0=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,0,1);
   reversalAlertHandle1=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,1,1);
   reversalAlertHandle2=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,2,1);
   reversalAlertHandle3=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,3,1);
   reversalAlertHandle4=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,4,1);
   reversalAlertHandle5=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,5,1);
   reversalAlertHandle6=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,6,1);
   reversalAlertHandle7=iCustom(NULL,0,"ReversalAlert",36.0,60.0,156.0,"",false,false,false,false,true,true,7,1);     
   Print("ReversalAlert = ",reversalAlertHandle0," ",reversalAlertHandle1," ",reversalAlertHandle2," ",reversalAlertHandle3," ",reversalAlertHandle4,"",reversalAlertHandle5," ",reversalAlertHandle6,"",reversalAlertHandle7);  

I'd create a function for each indicator that takes in the parameters that actually change and returns the values you're looking for. From there, create two arrays and then loop through X amount times, calling those functions and filling the arrays up with the values.