Using a horizontal line as part of your trigger for EA to take a trade

To add comments, please log in or register
Jowin6789
76
Jowin6789  

Hey,

I have written the following code that describes a pin bar and a subsequent bar that closes above the pin bar to confirm it, I would like to control the EA taking these trades by having a horinzontal line on the chart named "trigger" that I can manually move to support and resistance levels. I have managed to get it to draw the line but am now struggling to get the EA to recognise the Hline when i refer to it with "High[2]>trigger".

ObjectCreate("Trigger", OBJ_HLINE, 0, Time[0], Bid, 0, 0);
 double Trigger; 
 Trigger = OBJ_HLINE;   
   
//--- Finding bear Pin Bar Pattern, 
   if(body<maxsize 
      && Open[3]<Low[2]
      //&& Open[2]>Close[2]
      && Open[2]-Low[2]<maxsize
      && High[2]>High[3]
      && High[2]>High[4]
      && Close[1]<Low[2]
      && High[1]<High[2]
      && High[2]>Trigger    //High of the pin is above the horizontal line
      && Close[1]<Trigger)  //close of the last bar is below the horizontal line
      if(lastbarsize<1000*_Point)//limit size of last bar
        if(pinbarsize<1000*_Point) // limit size of pin bar
         
     {
      
      double  selllot = ((AccountBalance()*RiskPercent)/((sellSL-sellPrice)/ _point));
      OrderOpenF(Symbol(),OP_SELLSTOP,selllot,sellPrice,slippage,sellSL,sellTP,NULL,magic,_ExpDate,Blue);
      OrderOpenF(Symbol(),OP_BUYSTOP,selllot,CountersellPrice,slippage,CountersellSL,CountersellTP,NULL,Countermagic,_ExpDate,Blue);
     }


I also tried this but that didn't work either:


double Trigger =ObjectCreate("Trigger", OBJ_HLINE, 0, Time[0], Bid, 0, 0); 
  
   
//--- Finding bear Pin Bar Pattern, 
   if(body<maxsize 
      && Open[3]<Low[2]
      //&& Open[2]>Close[2]
      && Open[2]-Low[2]<maxsize
      && High[2]>High[3]
      && High[2]>High[4]
      && Close[1]<Low[2]
      && High[1]<High[2]
      && High[2]>Trigger    //High of the pin is above the horizontal line
      && Close[1]<Trigger)  //close of the last bar is below the horizontal line
      if(lastbarsize<1000*_Point)//limit size of last bar
        if(pinbarsize<1000*_Point) // limit size of pin bar
         
     {
      
      double  selllot = ((AccountBalance()*RiskPercent)/((sellSL-sellPrice)/ _point));
      OrderOpenF(Symbol(),OP_SELLSTOP,selllot,sellPrice,slippage,sellSL,sellTP,NULL,magic,_ExpDate,Blue);
      OrderOpenF(Symbol(),OP_BUYSTOP,selllot,CountersellPrice,slippage,CountersellSL,CountersellTP,NULL,Countermagic,_ExpDate,Blue);
     }

Is there a way to achieve what I'm trying to do here?


Many thanks for any help!!

Anthony Garot
1942
Anthony Garot  
Trigger = OBJ_HLINE;

That sets Trigger to an internal constant.

double Trigger =ObjectCreate("Trigger", OBJ_HLINE, 0, Time[0], Bid, 0, 0); 

That sets Trigger to the return value of ObjectCreate(), which is a boolean. This is specified in the documentation:

https://www.mql5.com/en/docs/objects/objectcreate


To get the price, try something like this (in MQL5):

Print(StringFormat("price is [%.5f]", ObjectGetDouble(0, "elmo", OBJPROP_PRICE, 0)));
Jowin6789
76
Jowin6789  
Anthony Garot:

That sets Trigger to an internal constant.

That sets Trigger to the return value of ObjectCreate(), which is a boolean. This is specified in the documentation:

https://www.mql5.com/en/docs/objects/objectcreate


To get the price, try something like this (in MQL5):


Ah i see! Thanks, I have MQL4 as using MT4.. is there anything that would work for this in MT4?

Jowin6789
76
Jowin6789  
Jowin6789:

Ah i see! Thanks, I have MQL4 as using MT4.. is there anything that would work for this in MT4?


cancel that, i managed to do it with this:

double Trigger = ObjectGetDouble(0,"Trigger",OBJPROP_PRICE,0);

thanks for your help !

To add comments, please log in or register