Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enable/Disable Dynamically

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Enable/Disable Dynamically

    I see there is a Disable() function, however, does their also exist an Enable type function? Frequently, following a reboot of MT Trading's server, I get a fill event in my strategy that did not happen. Using CBI.Globals, I can see my true "instrument" position, when the strategy position becomes incorrect, I want to place an order to get flat,then disable the strategy (so current position is reset to 0), then re-enable the strategy.

    I can place the order to get flat, and disable the strategy just fine. However, re-enabling the strategy is proving difficult. Any thoughts on how to accomplish this?

    #2
    Hi frostengine, unfortunately there would be no supported way to create a programmatic reenable - I have added your input to our feedback tracking lists though. Whom are you executing this script with? MBT?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Yes, I am executing with MBT. Most weeks I will only have 1 day where "phantom" trades occur. However, this week, NT has been loosing connection with MBT servers at least once a night. Right after reconnecting, the OnExecution event is triggering for multiple strategies. This causes the strategy Position variable to become set with values that are not true "phantom" positions.

      These phantom positions then become a problem when my strategy logic tries to exit the position,which in reality creates a trade in the opposite direction. Example:

      12:00 AM, I am flat
      12:04 connection lost
      12:05 connection gained
      12:05 OnExecution triggered,Strategy.Position shows as long 1000 (but reality no trades occured, still flat)
      1:30 my strategy generates a signal to exit long based on some exit criteria. Since I was not long 1000 to begin with, I am now short 1000 in reality. My strategy now thinks I am flat as that is what Strategy.Position is reporting. So I have no exit criteria to get out of the short, until I wake up in the Am and realize what happened

      I can see my TRUE account position with CBI.Globals, and since I have each strategy trading a different currency pair, I can compare my CBI.Globals account positions with the Strategy.Position to detect mismatches.

      Is there some way to force my Strategy.Position to a different value? So that I can manually set it to the correct value when it becomes incorrect after MBT server connections? First thought was to enable/disable to clear it, but if there is another way to reset the Strategy.Position, that would work as well...

      Comment


        #4
        Thanks frostengine, yes you're running unfortunately into a known limitation on the MBT interface here, which is will give you tracking issues for your strategy position, since MBT position update events would be sent before the execution. This would be point 4 in our connection disclaimer for MBT, just for completeness.

        As auch you can't rely on this tracking and the standard sequence of events (Execution before the Positions update).

        Here's what I would look into - create a real-time only trading script of your strategy, so that you can execute a historical strategy entry then, which would be what you queried from your live aco**** via the Cbi.Globals - reasoning here is that if no order processing is done your strategy position would be flat in historical, which would be the period before you reconnect to continue trading. In this case you can execute a trade then to mimic your live account a few bars before (determined via CurrentBars & Count).
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks for the reply. I am slightly confused by the concept you proposed. Can you elaborate a little further?

          Are you essentially saying, once I detect the positions are out of sync, to execute a historical entry on that strategy to compensate and cause the strategy Position to reflect current real time values? How do you execute a historical strategy entry while running real time in a live account? Sounds like this should work, just fuzzy on how I would actually place a historical order like this?

          Comment


            #6
            It would need a reenable cycle as well (to process on the historical bar), but then you could either make a user input for the historical qty to submit or use your mentioned snippet to query this from the account. If you would like to keep the strategy running, you would need to employ custom tracking to 'know' your current position - so you don't have to rely on the Strategy position to be correct - that would be likely the best way for continuing to run, but will take more work unfortunately.

            This item for our MBT adapter is also in on the list to review and potentially enhance for our next major NT update.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              It appears at least on backtesting, that I can do:
              this.Position.MarketPosition=MarketPosition.Flat;
              this.Position.Quantity=0;

              And the logic thinks I am flat from that point. What are the ramifications of doing this live? If another OnExecution triggers (such as the next time I place an order), does it add from that variable at 0. Or is there an internal variable that keeps track of the position?

              Example:
              12:05 Error happens and this.Position.Quantity shows 1000 long
              12:05 I reset Quantity=0 and position = flat
              3:30 I send an order to go long 1000

              Will my strategy now think it is long 1000, or long 2000?

              Comment


                #8
                Hello,

                I would not advise you to set these as these are managed by the core and you may run into unexpected behavior.

                -Brett

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by samish18, Today, 06:16 AM
                0 responses
                3 views
                0 likes
                Last Post samish18  
                Started by rezamerik, 08-23-2023, 10:33 AM
                10 responses
                1,594 views
                0 likes
                Last Post mfzillln  
                Started by giogio1, 12-02-2024, 03:18 AM
                6 responses
                39 views
                0 likes
                Last Post giogio1
                by giogio1
                 
                Started by Blaze212, Yesterday, 10:05 PM
                0 responses
                13 views
                0 likes
                Last Post Blaze212  
                Started by ntbone, 07-18-2019, 12:15 PM
                14 responses
                255 views
                0 likes
                Last Post BarzTrading  
                Working...
                X