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 pvincent, 06-23-2022, 12:53 PM
                14 responses
                237 views
                0 likes
                Last Post Nyman
                by Nyman
                 
                Started by TraderG23, 12-08-2023, 07:56 AM
                9 responses
                382 views
                1 like
                Last Post Gavini
                by Gavini
                 
                Started by oviejo, Today, 12:28 AM
                0 responses
                1 view
                0 likes
                Last Post oviejo
                by oviejo
                 
                Started by pechtri, 06-22-2023, 02:31 AM
                10 responses
                125 views
                0 likes
                Last Post Leeroy_Jenkins  
                Started by judysamnt7, 03-13-2023, 09:11 AM
                4 responses
                59 views
                0 likes
                Last Post DynamicTest  
                Working...
                X