Please Help move to entry

 
I'm new to programming. I'm building a simple EA. After entry conditions it places two long or two short trades. Here is where I get hung up: After the first trade takes profit, I can't get the second trade to move the stop loss up to entry plus spread for worse case break even. Then activate the trail stop to allow the profit to run.
 

Can change open trade orders with function OrderModify() see MetaEditor help: MQL4 Reference - Trading functions - OrderModify

Also have looksee in MQL4 tutorial book (a Russian -> English translator is in this link)


 

You can do it in two ways:


1. You open two position one with and one without takeprof. You set a Price_flag and a Modify_flag for instance:

double Modify_Price=TakeProfit;

bool ModifyOrder=false;

bool OrderModified=false;

Because you know where take profit stands, you check first if Ask/Bid is above/bellow this level:

if(Bid> Modify_When)

-> then: if true you set the flag ModifyOrder=true;

-> now this means your position is closed and you have to modify the second position to break even and activate the trailing stop: if(ModifyOrder=true && OrderModified!=true) {modify...and enable trailing stop}

-> After you done {OrderModified=true;}


And so on new order -> new sets the flags to false



2. You can use events.It is done as library. It is easyer but you have to know how to integrate it in your EA. Look this: https://www.mql5.com/en/articles/1399


 
Liliput:

You can do it in two ways:


1. You open two position one with and one without takeprof. You set a Price_flag and a Modify_flag for instance:

double Modify_Price=TakeProfit;

bool ModifyOrder=false;

bool OrderModified=false;

Because you know where take profit stands, you check first if Ask/Bid is above/bellow this level:

if(Bid> Modify_When)

-> then: if true you set the flag ModifyOrder=true;

-> now this means your position is closed and you have to modify the second position to break even and activate the trailing stop: if(ModifyOrder=true && OrderModified!=true) {modify...and enable trailing stop}

-> After you done {OrderModified=true;}


And so on new order -> new sets the flags to false



2. You can use events.It is done as library. It is easyer but you have to know how to integrate it in your EA. Look this: 'Events in МetaТrader 4'


Thanks this should help and I'll check out the article.

Reason: