This ProBuilder code snippet demonstrates how to execute a sell order for one contract after a specified number of bars have elapsed since entering a long position. The code ensures that the sell order is only placed if the conditions are met, specifically after two bars from the entry of the trade.
If Not OnMarket then i = 0 Endif
i = max(i,CountOfLongShares)
if barindex-tradeindex(i)=2 then
sell 1 contracts at market
endif
Explanation of the Code:
This snippet is a practical example of how to manage trade exits based on the number of bars elapsed, which is a common strategy in trading systems to capture quick market movements or to limit exposure.
Check out this related content for more information:
https://www.prorealcode.com/topic/cumulate-orders-and-close-with-barindex-tradeindex/#post-157944
Visit Link