Need help setting automated SL and TP

 

Hello everyone !


I'm setting up an script using the following code to make a buy on market price:


               trade.Buy(lote,_Symbol,0,0,0,"buy");


I'd like to set this action with an automated SL and TP line, aprox. 100 points above and below the buying point.

something like this :


               trade.Buy(lote,_Symbol,0,price-100,price+100,"Compra a mercado");


               trade.Buy(lote,_Symbol,0,SL,TP,"buy");

where: 

SL = price - 100

TP = price + 100


I guess it should be an easy task but I'm really just learning the basics by now and I can't figure out how to reference this in the script.

Can anyone shed a light on this?


Thanks in advance!

 
blocowow:

Hello everyone !


I'm setting up an script using the following code to make a buy on market price:


               trade.Buy(lote,_Symbol,0,0,0,"buy");


I'd like to set this action with an automated SL and TP line, aprox. 100 points above and below the buying point.

something like this :


               trade.Buy(lote,_Symbol,0,price-100,price+100,"Compra a mercado");


               trade.Buy(lote,_Symbol,0,SL,TP,"buy");

where: 

SL = price - 100

TP = price + 100


I guess it should be an easy task but I'm really just learning the basics by now and I can't figure out how to reference this in the script.

Can anyone shed a light on this?


Thanks in advance!

What you need, is to open a buy trade when ea starts with 100 pips sl and tp? If yes, use this 

if(OrdersTotal()<=0)
 {
  trade.Buy(Lots,NULL,Ask,SL,TP,"Buy Condition");
 }

Where, Lots is your costant, NULL is TimeFrame, SL and TP are costant like Lots. To create the constant, use this

double SL = Ask-100*_Point;
double TP = Ask+100*_Point;
double Lots = 0.01;
 

That helped Simone! 

Thanks!

Reason: