I can’t test it with manual trading because I don’t have a Demo Account with IG.
With Automatic Trading being Long and Short within one Instrument is rubbish as the commands for it don’t exist. Look at this example :
DefParam CumulateOrders = True
if BarIndex > 100 then
IF NOT LongOnMarket THEN // ???
BUY 1 CONTRACTS AT MARKET
ENDIF
If LongOnMarket THEN
//SELL AT MARKET
ENDIF
if BarIndex > 110 then
IF NOT ShortOnMarket THEN // ???
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
IF ShortOnMarket THEN
//EXITSHORT AT MARKET
ENDIF
endif
endif
Graph CountOfLongShares coloured(0,220,0,255) // Green.
Graph CountOfShortShares coloured(220,0,0,255) // Red.
Look at the // ??? remarks in that code. Also envision two positions, one Long and one Short. So Yes I would be Long and Yes I would be Short.
ehhh …
No. Not within one instrument for the same Strategy. Two different Strategy’s is fine (with the fun that this can not exist manually).
Anyway, I tried all the combinations of the Force Open setting, together with CumulateOrders (DefParam), but I can’t manage to do it in code. Mind you, this is already because I can not wrap my head around the thinking on the “how to”. So, be happy to change this little program for your own testing (just backtest) and see that you just don’t know what to do or tweak. Again, it requires a command set which is not there. A Position Qualifier or how to name it.
Of course in the end this is about this 1000 times people asked “how to hedge a Long with a Short”, which just can not exist in PRT for the same Strategy and Instrument in AutoTrading. But this can be done manually because the Broker can take it, and the “qualifier” I mentioned is the Order itself. You can see that PRT is not really made for it, but it works (at least it did two years or so ago). Don’t ask me about the conditions and settings – I forgot and they may have changed.
Anyway, this was not even the subject of the topic. The subject also was not about whether it is possible to have two Strategies both having opposite positions (they just can *because* they don’t know anything of each other).
Option 1 = also the second Algo takes a long position, disregarding the fact that there is already a position on the market for the same product (as it has been taken by another Algo)
I think I now know how to answer your question and the answer would be Option 1 because
Option 2 = the second Algo does not take the long position and goes in Abend and Quit, having the product an active position on the market – and interfering with the second strategy.
Option 2 can not exist. Again, the both Strategies won’t know of each other, so the second can’t know that the first has a Long position already.
However …
It surely would be possible to code this, the one Strategy also parsing the code of the other, where it keeps track of the virtual position of the other. Thus, both Strategies would know each other’s positions by means of emulating what the other does. It would be relatively difficult to make this water proof, but definitely doable. See second attachment where this actually happens; Red/Green is the real Strategy, Purple/Brown is the virtual environment doing exactly the same and proving it at the 1 second level. And yes, if you think about this, this is just simple BackTesting. But not that simple, because if things get out of sync you may and up in hell (because out of pre-designed control).