Why is my strategy not trading? Question from a beginner user.

 

Hey guys! 


This is my first post here as I am new to MQL. I have been trying to create a simple strategy, which trades based on indicators gathered from the "semafor123Triangles" custom indicator. Long story short, as you can see in my code, semafor indicator has 7 "spots" which give values. These values can either be 0 or give a current currency price. 

My assumption is: if this indicator give values:

0 0 0 0 ">0" 0 0 0 then buy

and if gives 0 0 0 0 0 ">0" 0 0 then sell.


Unfortunately although i receive appropriate values of the indicator, the strategy doesnt work. 

Could you please help me with this? I would really appreciate any tips or suggestions. 


double semafor123TrianglesHandle0,semafor123TrianglesHandle1,semafor123TrianglesHandle2, semafor123TrianglesHandle3,semafor123TrianglesHandle4,semafor123TrianglesHandle5,semafor123TrianglesHandle6,semafor123TrianglesHandle7; 
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[];


int OnInit()

   
  {
  Print("Version 1.6");
//--- indicator buffers mapping
   SetIndexBuffer(0,semafor123TrianglesLabelBuffer0,INDICATOR_DATA);
   SetIndexBuffer(1,semafor123TrianglesLabelBuffer1,INDICATOR_DATA);
   SetIndexBuffer(2,semafor123TrianglesLabelBuffer2,INDICATOR_DATA);
   SetIndexBuffer(3,semafor123TrianglesLabelBuffer3,INDICATOR_DATA);
   SetIndexBuffer(4,semafor123TrianglesLabelBuffer4,INDICATOR_DATA);
   SetIndexBuffer(5,semafor123TrianglesLabelBuffer5,INDICATOR_DATA);
   SetIndexBuffer(6,semafor123TrianglesLabelBuffer6,INDICATOR_DATA);
   SetIndexBuffer(7,semafor123TrianglesLabelBuffer7,INDICATOR_DATA);
   ResetLastError();
   
   SetIndexBuffer(0,semafor123TrianglesNewLabelBuffer0,INDICATOR_DATA);
   SetIndexBuffer(1,semafor123TrianglesNewLabelBuffer1,INDICATOR_DATA);
   SetIndexBuffer(2,semafor123TrianglesNewLabelBuffer2,INDICATOR_DATA);
   SetIndexBuffer(3,semafor123TrianglesNewLabelBuffer3,INDICATOR_DATA);
   SetIndexBuffer(4,semafor123TrianglesNewLabelBuffer4,INDICATOR_DATA);
   SetIndexBuffer(5,semafor123TrianglesNewLabelBuffer5,INDICATOR_DATA);
   SetIndexBuffer(6,semafor123TrianglesNewLabelBuffer6,INDICATOR_DATA);
   SetIndexBuffer(7,semafor123TrianglesNewLabelBuffer7,INDICATOR_DATA);
   
   SetIndexBuffer(0,reversalAlertLabelBuffer0,INDICATOR_DATA);
   SetIndexBuffer(1,reversalAlertLabelBuffer1,INDICATOR_DATA);
   SetIndexBuffer(2,reversalAlertLabelBuffer2,INDICATOR_DATA);
   SetIndexBuffer(3,reversalAlertLabelBuffer3,INDICATOR_DATA);
   SetIndexBuffer(4,reversalAlertLabelBuffer4,INDICATOR_DATA);
   SetIndexBuffer(5,reversalAlertLabelBuffer5,INDICATOR_DATA);
   SetIndexBuffer(6,reversalAlertLabelBuffer6,INDICATOR_DATA);
   SetIndexBuffer(7,reversalAlertLabelBuffer7,INDICATOR_DATA);   
   
   SetIndexBuffer(7,zigZagLabelBuffer0,INDICATOR_DATA);   
   SetIndexBuffer(7,zigZagLabelBuffer1,INDICATOR_DATA);   
   SetIndexBuffer(7,zigZagLabelBuffer2,INDICATOR_DATA);   
   SetIndexBuffer(7,zigZagLabelBuffer3,INDICATOR_DATA);   
   SetIndexBuffer(7,zigZagLabelBuffer4,INDICATOR_DATA);   
   SetIndexBuffer(7,zigZagLabelBuffer5,INDICATOR_DATA);   
   SetIndexBuffer(7,zigZagLabelBuffer6,INDICATOR_DATA);   
   SetIndexBuffer(7,zigZagLabelBuffer7,INDICATOR_DATA);   
   

   return(INIT_SUCCEEDED);
   }
int start()
  {
   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,1);
   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,1);
   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,1);
   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,1);
   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,1);
   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,1);
   SemafornewHandle6=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,6,1);  
   SemafornewHandle7=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,7,1);

   semafor123TrianglesHandle0=iCustom(NULL,0,"Semafor+123Triangles",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,1);
   semafor123TrianglesHandle1=iCustom(NULL,0,"Semafor+123Triangles",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,1);
   semafor123TrianglesHandle2=iCustom(NULL,0,"Semafor+123Triangles",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,1);
   semafor123TrianglesHandle3=iCustom(NULL,0,"Semafor+123Triangles",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,1);
   semafor123TrianglesHandle4=iCustom(NULL,0,"Semafor+123Triangles",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,1);
   semafor123TrianglesHandle5=iCustom(NULL,0,"Semafor+123Triangles",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,1);
   semafor123TrianglesHandle6=iCustom(NULL,0,"Semafor+123Triangles",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,6,1);
   semafor123TrianglesHandle7=iCustom(NULL,0,"Semafor+123Triangles",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,7,1);
   
   zigZagHandle0=iCustom(NULL,0,"ZigZag",12,5,3,0,1);
   zigZagHandle1=iCustom(NULL,0,"ZigZag",12,5,3,1,1);
   zigZagHandle2=iCustom(NULL,0,"ZigZag",12,5,3,2,1);
   zigZagHandle3=iCustom(NULL,0,"ZigZag",12,5,3,3,1);
   zigZagHandle4=iCustom(NULL,0,"ZigZag",12,5,3,4,1);
   zigZagHandle5=iCustom(NULL,0,"ZigZag",12,5,3,5,1);
   zigZagHandle6=iCustom(NULL,0,"ZigZag",12,5,3,6,1);
   zigZagHandle7=iCustom(NULL,0,"ZigZag",12,5,3,7,1);


   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);  
   Print("ZigZag = ",zigZagHandle0," ",zigZagHandle1," ",zigZagHandle2," ",zigZagHandle3,zigZagHandle4,zigZagHandle5,zigZagHandle6,zigZagHandle7);
   Print("Semafor123Triangle = ", semafor123TrianglesHandle0," ",semafor123TrianglesHandle1," ",semafor123TrianglesHandle2," ",semafor123TrianglesHandle3," ",semafor123TrianglesHandle4," ",semafor123TrianglesHandle5," ",semafor123TrianglesHandle6," ",semafor123TrianglesHandle7);
   Print("Semafor123TriangleNew = ", SemafornewHandle0," ",SemafornewHandle1," ",SemafornewHandle2," ",SemafornewHandle3," ",SemafornewHandle4," ",SemafornewHandle5," ",SemafornewHandle6," ",SemafornewHandle7);



CheckForOpen();
   Print ("InsideStartAfterCheckForOpen");
return (0);
   }


void CheckForOpen()


   {
   Print ("InsideCheckForOpen");
   int    res;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
 
    if( (semafor123TrianglesLabelBuffer0[0] ==0) &&
      (semafor123TrianglesLabelBuffer1[1] ==0 )&&
      (semafor123TrianglesLabelBuffer2[2] ==0 )&&
      (semafor123TrianglesLabelBuffer3[3] ==0) &&
      (semafor123TrianglesLabelBuffer4[4] >0) &&
      (semafor123TrianglesLabelBuffer5[5] ==0) &&
      (semafor123TrianglesLabelBuffer6[6] ==0) &&
      (semafor123TrianglesLabelBuffer7[7] == 0))
   {
 res=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-20*Point,Ask+40*Point,"SEMA",0,0,clrNONE);
 Print("semafor123TrianglesLabelBufferValuesBuy = ",semafor123TrianglesLabelBuffer0[0]," ",semafor123TrianglesLabelBuffer1[1]," ",semafor123TrianglesLabelBuffer2[2]," ",semafor123TrianglesLabelBuffer3[3]," ",semafor123TrianglesLabelBuffer4[4],"",semafor123TrianglesLabelBuffer5[5]," ",semafor123TrianglesLabelBuffer6[6],"",semafor123TrianglesLabelBuffer7[7]); 



   }
         
     
   if ( (semafor123TrianglesLabelBuffer0[0] == 0) &&
      (semafor123TrianglesLabelBuffer1[1] ==0 )&&
      (semafor123TrianglesLabelBuffer2[2] == 0 )&&
      (semafor123TrianglesLabelBuffer3[3] ==0 )&&
      (semafor123TrianglesLabelBuffer4[4] == 0 )&&
      (semafor123TrianglesLabelBuffer5[5] >0 )&&
      (semafor123TrianglesLabelBuffer6[6] == 0 )&&
      (semafor123TrianglesLabelBuffer7[7] ==0))
   {  
      res=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid+20*Point,Ask-40*Point,"SEMA",0,0,clrNONE);
      Print("semafor123TrianglesLabelBufferValuesSell = ",semafor123TrianglesLabelBuffer0[0]," ",semafor123TrianglesLabelBuffer1[1]," ",semafor123TrianglesLabelBuffer2[2]," ",semafor123TrianglesLabelBuffer3[3]," ",semafor123TrianglesLabelBuffer4[4],"",semafor123TrianglesLabelBuffer5[5]," ",semafor123TrianglesLabelBuffer6[6],"",semafor123TrianglesLabelBuffer7[7]); 
   }

     
      return;
   }     
     
 
  1. You need to dedicate a lot more time to learning about the basics of programming and then even more about MQL programming. At the moment, your current coding skill level is very low and it's the main reason why you are having so many difficulties.
  2. Don't mix old style MQL4 code with the newer MQL4+ code that is more compatible to MQL5. "start()" is old style, and you should use OnCalculate() for Indicators and OnTick() for EAs.
  3. You cannot mix Indicator code with Expert Advisor (EA) code. They have to be separated. The code you have used in OnInit() is mostly for use in the development of an Indicator.
  4. An Indicator cannot carry out trading functions. Only EAs (or Scripts) can do that.
  5. There is a lot more wrong with your code, but fix the above points first.
 

Also, you posted in the wrong section. Your code is for MQL4 and that section is at the very end of the forum with the title: MQL4 and MetaTrader 4  

EDIT: A moderator will most probably soon move it into the correct section for you.