Hi there,
just something I’ve noticed, and I’m not sure why it’s happening.
I have a strategy, and it should exit after 2 full bars on the market. I have this set up as:
if barindex-tradeindex=2 then
sell at market
endif
Now, there are two different ways that I could run this strategy. Both with
cumulateorders=true
I can either run a 1 position max,
countoflongshares<1
or a 2 position max,
countoflongshares<2
The thing I’ve noticed, is that if I run the countoflongshares<1, then it exits the position after 2 full bars. This is what is intended.
If I run it as countoflongshares<2 and if I buy a second position while the first position is still on, then it doesn’t do 2 separate exits but a combined single exit, and it pushes the first exit out, so that the first trade is on the market for 3 full bars, and not 2.
Please see the attached picture that shows this.
What I want to know, is this normal/is this to be expected?
What will the broker (IG) see and do?
Will it execute as backtested, or will I have two separate exits, and not the single exit that I’m seeing?
Thanks,
Finning
TRADEINDEX(1), or simply TRADEINDEX, always refers to the most recent entry, so 2 bars will be computed from THAT barindex.
Refer to TRADEINDEX(2) for the previous entry and use the partial closure support to exit only the first position entered.
(not tested)
i = CountOfLongShares
if barindex-tradeindex(i)=2 then
sell 1 contracts at market
endif
The correct code is:
If Not OnMarket then
i = 0
Endif
i = max(i,CountOfLongShares)
if barindex-tradeindex(i)=2 then
sell 1 contracts at market
endif
Hi Roberto,
Thanks for that!
will test, but it looks good and makes sense.
Cheers,
Finning
Tested, and it works as intended – thanks!
Roberto correct code above added as Log 269 to here …
Snippet Link Library