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
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;
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!