Two Algo trading the same product

Forums ProRealTime English forum General trading discussions Two Algo trading the same product

Viewing 13 posts - 1 through 13 (of 13 total)
  • #179209

    Hello, I am wondering if any fellow trader has experienced this situation.

    I am currently running live two different Algos – one fast reacting and one slow reacting – both trading the same product (Gold Spot DFB).

    The first Algo gets the signal to enter long and execute the trade.

    Then also the second Algo gets the signal to enter long. The code I am using is:

    IF NOT ONMARKET and cdelta  THEN
    BUY size PERPOINT AT MARKET

    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)

    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.

    Thanks for helping,Warm regards. Gaby

     

    #179210

    Strategies are unaware of one another, so they can both open a position (same product) in the same direction.

    They can also open opposite positions, provided you have enabled it by setting FORCE OPEN with IG.

     

    #179213

    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.

    I think you are saying that something goes plain wrong (Abend). But personally I can’t sort out what causes which. Could you rephrase all ?

    N.b.: The fact that a strategy errors out and leaves the position open, is a setting (you can reach that by means of one of the links in the form that allows to start a strategy).

    #179214

    They can also open opposite positions, provided you have enabled it by setting FORCE OPEN with IG.

    Maybe not important for the issue, but :
    I think you wanted to say : ONE and the same strategy can also open opposite positions, provided …

    #179215

    A single strategy cannot open trades in opposite directions.

    Different strategies can, on the same traded product, provided FORCE OPEN is enabled, otherwise IG won’t allow that.

     

    #179238

    Then my answer was totally wrong. Apologies.

    The answer sprung from the fact that I am not aware of this limitation at all. Not sure whether it matters, but I work with a PRT Sponsored account with IG. You are almost suggesting (in my mind that is) that I never noticed because all opposite trades were rejected (without me seeing that) while the same direction trades worked out ?
    In any event, I never set the FORCE OPEN setting to Enabled (it is Disabled) as I never had the urge.

    Still, please see the attachment. The setting exists, but under Manual Trading (which is what I ever back tested and it works (with a lot of confusion regarding the order tags)).
    N.b.: For PRT-IB this setting does not exist at all, which is exactly how I have all in mind (no opposite trading possible for IB).

    #179270

    Thanks you both for your contributions.

    @ Peter,

    In IG force open exists at trade level but since last release now it exists also as a default setting.

    See here for instructions:

    https://www.ig.com/uk/help-and-support/platforms/web-trading-platform/how-do-i-set-my-preferences#information-banner-dismiss

    If you have a strategy that calls long and short and you want to keep both positions opened I recommend you test it in your demo account first (activating the Force Open in default setting and then running the strategy). It should work… but please let me know the outcome of your test, as I am interested, too.

    Gaby

    #179271

    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 :

    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).

     

    #179294

    Hi Peter,

    I still recommend you to open your IG DEMO account, as it comes with a second installation of ProRealcode and will help you keeping all tests (good and bad) in one place (the DEMO Prorealcode instance) and promoting to the LIVE IG and the LIVE ProRealCode only the good and back-tested ones that you want to run LIVE (using Export / import functionality). Of course you can survive also with one Prorealcode installation only (the LIVE), but if you do a lot of back-testing / programming as I do, the list of them will start to be messy, with many of them…

    FORCE OPEN

    Yes, one easy solution is to break the program into two, but I don’t like it too.

    BUT let me try an alternative (forgive me if it does not work, as I did not test it for you):

    Line 10 with the // remarks: you are using the instruction SELL AT MARKET that is the Prorealcode instruction to CLOSE A LONG TRADE.

    Why not using SELLSHORT instead and see how the program react, if it opens two trades?

    Of course you need to preset in IG the default flag “FORCE OPEN” as activated… as we said before.

    Hope it works, Gaby

     

     

    #179301

    Hey Gaby,

    Why not using SELLSHORT instead and see how the program react, if it opens two trades?

    But I did ! (line 16)
    And you can see in the attachment (previous post) that it nets.

    Off topic :

    I still recommend you to open your IG DEMO account, as it comes with a second installation

    Haha, thank you for the good advice, but I think I have more accounts than I can manage. My AutoTrade development is done with PRT-IB**, including a Demo Account there. BackTesting with PRT-IB is 5-10 times faster.
    **) Actually a Demo Account via ProRealTime bears no broker – you open an account via http://www.prorealtime.com and without a connected account with a broker, International Brokers (IB) provides the data.
    Please notice that the trades for IG vs IB don’t work out the same at all because of using spreads without commission (IG) vs commission with hardly any spread (IB). But with some practicing and adaption in the code  you can come sufficiently close.

    #179308

    OK gotcha; then the only option is to break the Algo into two programs …but I don’t like it too: as you cannot read properly drawdown, RRR, in general all performances. And of course double maintenance…

    Maybe we ask ProrealCode Programmers to enhance the current version with a new instruction to enable Force Open… Should be a simple instruction.

    Re your note: “My AutoTrade development is done with PRT-IB**… BackTesting with PRT-IB is 5-10 times faster” ==> this sounds very interesting to me… as currently my back-testing is very time demanding on my algos… I will try a go with your suggestions!

    Take care, Gaby

     

    #180285

    Roberto,

    Are you sure about this? I am asking because last Friday I was long in Gold already with a discretionary trade. My algo also got the signal to enter long, but it didn’t take the trade.This would have passed unnoticed, however the exact same Algo runs also in a second live account. And in the second one the Algo executed the trade as per code. Please note: in my second account there was no running positions in Gold.

    Initially I thought it was a problem of code versioning / disalignement – but after checking and back-testing again during this weekend I realized they are identical; there is no version problem between the two.

    Therefore my conclusion is: the instruction IF NOT ONMARKET is not limited to the strategy itself but it checks that the product overall hasn’t any running trade – independently from which strategy has initiated it. Therefore I know now the right answer for my question is Option 2 (on my initial message), not Option 1. There is no way two strategies can can both open a position (same product) in the same direction as one of the two will be preceding and the second will not execute the trade because of the instruction IF NOT ONMARKET. This is what happened last Friday on my live account.

    Warm Regards, Gaby

     

    #180289

    Strategies are unaware of one another, so any restriction is applied to each single strategy, not the whole bunch you you have.

    The restrictions you are experiencing may be due to some kind of special account; I am not sure about this, but if you have a limited risk account this can be a cause. You should check with the broker.

     

Viewing 13 posts - 1 through 13 (of 13 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login