How to code this exit strategy?
Posted: Jan 06 2017
Hi
I would like to code a strategy based on barssinceentry:
exit the position while barssinceentry is larger than 30 bars, if the position is at a loss.
I tried to write it but got a bit stuck, since I just started learning Easy Language.
this is my previous version:
say I have a long position,
However if it was at a profit *at* the 30th bar, it would not sell, and the code would not sell after the 30th bar even at a loss.
Any help would be appreciated!
I would like to code a strategy based on barssinceentry:
exit the position while barssinceentry is larger than 30 bars, if the position is at a loss.
I tried to write it but got a bit stuck, since I just started learning Easy Language.
this is my previous version:
Code: Select all
input: positiontime(30);
condition1 = barssinceentry = positiontime;
condition2 = contractprofit < 0;
if condition1 and condition2 and MarketPosition <> 0 then begin;
Sell ("Time Exit LX") all contracts next bar at market;
Buytocover ("Time Exit SX") all contracts next bar at market;
end;
However if it was at a profit *at* the 30th bar, it would not sell, and the code would not sell after the 30th bar even at a loss.
Any help would be appreciated!