Problem with restart FLAG (==false) on order ..

 

Hello,


I have problem with my EA to reset a flag ( in this sample = false ). I build Auto EA stop loss modify and dont know how to reset flag when is order close or come to stop loss.


Exsample EA:


i buy at price 1.4000

* when price come to 1.4020 (in that exsample is 20pips profit) - EA must change stop loss to 1.4010 that is diffrend from OpenPrice - Bid/2 and EA make new buy limit order on OPEN PRICE from this order!

* when price come to 1.4040 (in this exsample is 40pips of profit) - Ea change agen stop loss to 1.4020 - - OpenPrice - Bid/2


But the problem witch i get is if price come to stop loss and come to NEW BUY limit and order is agen buy in 1.4000 the EA dont track it !

...


At start i give flag to false :


bool Set1=false,
Set2=false;

than my IF :

if (OrderType()==OP_BUY)
{
diff=Bid-OrderOpenPrice();
if (diff>=20 && Set20==false) // first is order in false that meen EA will change stop loss ! But problem is when this order is close on STOP LOSS and new order is open EA dont track it !
{
sl=OrderOpenPrice()+(diff*Point/2);
tp=Bid+(100*Point);
openLimit(OP_BUYLIMIT,OrderOpenPrice());
Set20=true; // if EA change this stop loss and make new pending limit order its make Flag to TRUE ... just to save if price come back to 20pips to ea dont change stop loss agen !
}
if (diff>=40 && Set40==false)
{
sl=OrderOpenPrice()+(diff*Point/2);
tp=Bid+(100*Point);
Set40=true;
}

}


Can i make one more IF like this :


if (Bid<=OrderOpenPrice)
Set2=fasle;
if (Bid<=sl)
Set2=fasle;


And then will EA change false and track new order ?


Thanks

Luka
 

My ea if somebody know what is wrong !


I have open 3 trades exsample on buy .. but i wonna when first order come to +20 profit to track him and change STOP loss /2 .. and if price come to STOP LOSS or order open price to restart flag to FALSE !


Please help !


Thanks




My attached - EA 20-40-60-80-100-120-150 stop loss changer :

Files:
lukaqmody.mq4  30 kb
Reason: