How to prevent open reopening after take profit

 

Hi: i am looking for help to stop a trade from reopening after a take profit. Normally I use a shift in the buy/sell open to prevent reopening a trade after a TP but this is not possible with the strategy I am using. What options would I have to prevent this? (Obviously the buy/sell open conditions would still be in play)

Thanks for your help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

Depends on what your conditions are, but essentially you have to check not only that they are true for bar 0, but that they were not true for bar 1, e.g.:

if (iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>0 && iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1)<=0)

Of course, there are different ways to organize code and both conditions need not to be in the same line, but you get the idea.

There is another good reason to check for signal being 'fresh', i.e., conditions being fulfilled for the current bar, but not for the previous bar – to prevent EA from jumping onto an end of a trend once you turn it on.

And final note: with many indicators, you're better off waiting for the cross to confirm, i.e., looking at bar 1 and bar 2, not bar 0.

 
LINE123:

Hi: i am looking for help to stop a trade from reopening after a take profit. Normally I use a shift in the buy/sell open to prevent reopening a trade after a TP but this is not possible with the strategy I am using. What options would I have to prevent this? (Obviously the buy/sell open conditions would still be in play)

Thanks for your help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Would the sleep function work for you ?
 
Drave:

Depends on what your conditions are, but essentially you have to check not only that they are true for bar 0, but that they were not true for bar 1, e.g.:

Of course, there are different ways to organize code and both conditions need not to be in the same line, but you get the idea.

There is another good reason to check for signal being 'fresh', i.e., conditions being fulfilled for the current bar, but not for the previous bar – to prevent EA from jumping onto an end of a trend once you turn it on.

And final note: with many indicators, you're better off waiting for the cross to confirm, i.e., looking at bar 1 and bar 2, not bar 0.


Hey thanks for the info. That is where the problem is the tp will prob happen on the same bar so a shift will not work. I am using a 1h chart with a trend indicator
 
MickGlancy:
Would the sleep function work for you ?

I am not aware of the sleep function...
 

I usually use a static time variable for this. I call it timestamp.

example:1-wait til bar change, if(time[0] > timestamp){ ordersend(); timestamp=time[0]; }

example:2-wait til trigger happens again, if(trigger==1){timestamp=0;}

example:3-stop and reverse, if(buy_timestamp==0 || sel_timestamp>buy_timestamp){buy ordersend; buy_timestamp=timecurrent();}

example:4-wait 1-hour after close, if(timecurrent()>buy_timestamp+60*60){ordersend;}

You can also update the timestamps when orderclose. In example 4, it'll wait 1-hour after orderclosed.

 
ubzen:

I usually use a static time variable for this. I call it timestamp.

example:1-wait til bar change, if(time[0] > timestamp){ ordersend(); timestamp=time[0]; }

Instead of using the timestamp I liked the idea of if(Volume[0]<2) {//first tick of new bar} but unsure of its reliability


 

Instead of using the timestamp I liked the idea of if(Volume[0]<2) {//first tick of new bar} but unsure of its reliability

Yeah, I saw the post when you discovered that solution.

Because I'm currently in the process of reducing the #of variables and duplications within my BACK-TESTS.

I'm experimenting if(Volume[0]==1) instead of creating variable time-stamp which eats resources.

However, we've been warned by WHRoeder here. That's why I didn't include it within this post.

I hope to get all my processes down to within 1-tick. Either way, I'll probably change it back to TimeStamp instead of Volume b4 going live.

 
ubzen:

However, we've been warned by WHRoeder here. That's why I didn't include it within this post.

Thanks, I had my suspisions since an EA is allowed to skip processing a tick when the EA is still working on the previous tick. Sorry about reposting was looking for the answer as to why it could not be used.
 
LINE123:

Hi: i am looking for help to stop a trade from reopening after a take profit. Normally I use a shift in the buy/sell open to prevent reopening a trade after a TP but this is not possible with the strategy I am using. What options would I have to prevent this? (Obviously the buy/sell open conditions would still be in play)

int start(){
   bool signal = ...; static bool tradeAllowed;
   if (!signal)                   tradeAllowed = true;
   elseif (tradeAllowed){         tradeAllowed = false; 
      if (openOrderCount() == 0) OpenOrder(); 
   }
 
YYZ:

Hi: i am looking for help to stop a trade from reopening after a take profit. Normally I use a shift in the buy/sell open to prevent reopening a trade after a TP but this is not possible with the strategy I am using. What options would I have to prevent this? (Obviously the buy/sell open conditions would still be in play)

Thanks for your help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

i have similar issue please @William Roeder, i dont know how to incoporate it in the code

Reason: