Hi all,
Coding an EA at the moment to autotrade for me, it's getting towards completion but i can't figure out how to move the stoploss on an open trade. i am posting my code here, if anyone could point out what i'm doing wrong i would greatly appreciate
This is the part of code which opens a LONG position:
PHP Code:
{
if(//long entry criteria met)
{
if (priorbartime == Time[0])
return(0);
priorbartime = Time[0];
Alert("Long Signal");
ObjectCreate(arrowlong, OBJ_ARROW, 0, Time[0], Open[0], 0, 0, 0, 0);
ObjectSet(arrowlong, OBJPROP_ARROWCODE, 233);
ObjectSet(arrowlong, OBJPROP_COLOR, Aqua);
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-StopLoss*Point,Ask+TakeProfit*Point,"am crossing",16677,0,Green); // HDB CHANGED Close TO Ask and SlipPage to 0
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
}
then once the trade is open I want to manage it by moving stop to -5 when the trade is +15, and by moving stop to b/e when trade is +20. this is the code i have come up with so far but it doesnt seem to be working:
PHP Code:
total=OrdersTotal();
if(total>0)
{
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
{
if(Bid-OrderOpenPrice()==Point*15)
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*5,OrderTakeProfit(),0,Blue);
return(0);
}
if(Bid-OrderOpenPrice()==Point*20)
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue);
return(0);
}
}
}
}
As mentioned, this is all for LONG positions.
Thanks for any help!
divergence_trader