Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Strategy entering boot loop when running on live chart

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

    Strategy entering boot loop when running on live chart

    Hi there,

    I've drafted a strategy that utilizes specific entry criteria and then takes an entry using an existing ATM strategy. I've introduced a few safeguards to avoid taking multiple trades, such as confirming our position is flat and checking for an active ATM strategy before proceeding with checking our entry criteria.

    Unfortunately, this bug I've been facing has persisted - whenever I initiate this strategy on a live chart, it enters a Buy/Sell loop as soon as an entry is confirmed by my entry criteria. It should only be initiating one entry, but for some reason it tries to initiate an infinite amount. This happens with 'Set Order Quantity' set at 'Strategy' and 'Default Quantity: 1'. I've set 'Entries per Direction' at 1 as well, the issue persists.
    This issue seems to happen immediately when an entry is triggered on a live connection (NinjaTrader 8, Rithmic data connection) or completely randomly when testing using Playback mode. On Playback it mostly runs fine, but once in a blue moon the same entry loop will be triggered with seemingly no difference in the strategy/entry criteria.

    Entry criteria, if it matters:
    Long -
    * fastSMA is above slowSMA
    * price is above fastSMA
    * previous bar or the bar before that opened above the fastSMA and closed red
    * current bar is green and has surpassed the preceding red bar to the upside

    Short - exact opposite
    * fastSMA is below slowSMA
    * price is below fastSMA
    * previous bar or the bar before that closed below the fastSMA and closed red
    * current bar is red and has surpassed the preceding green bar to the downside

    I am pasting my entire strategy code below, as well as a screenshot of the corresponding strategy setup window.


    *deleted*
    Attached Files
    Last edited by lorem; 02-07-2024, 09:41 PM.

    #2
    Hello lorem,

    As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript Add-on...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter the script name in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...nt8/export.htm

    You can attach the export to your post to keep the post text short.



    With AtmStrategyCreate(), these orders are not placed through the strategy and will not affect the strategy position, strategy performance, and will not update order methods like OnOrderUpdate() or OnExecutionUpdate(). Instead you will need to use AtmStrategyMethods to retrieve the status of the position or orders.

    From the help guide:
    "Executions from ATM Strategies will not have an impact on the hosting NinjaScript strategy position and PnL - the NinjaScript strategy hands off the execution aspects to the ATM, thus no monitoring via the regular NinjaScript strategy methods will take place (also applies to strategy performance tracking)"


    You will need to check the position with GetAtmStrategyMarketPosition() after the entry order has filled (GetAtmStrategyEntryOrderStatus()).



    The SampleAtmStrategy included with NinjaTrader has sample code.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ​Thank you for the response! I've incorporated additional GetAtmStrategyMarketPosition() checks, but the issue has persisted. Immediately after making these changes the strategy did successfully take one entry without freaking out which was a first.. but on the subsequent entry, the same infinite loop issue occurred. I am attaching a photo of my chart so you can see how this appears on my end. I am also attaching the updated ColorGameATM code. Please let me know if you see anything that could be causing this loop issue! I am at a loss here.
      Attached Files

      Comment


        #4
        Hello lorem,

        Add prints to understand why the conditions call AtmStrategyCreate() order are evaluating as true multiple times.

        In the script you have provided, there is no check that the entry has filled before checking GetAtmStrategyMarketPosition(). If the entry has not filled, the position will be flat. It looks like your logic when flat before the entry has filled would set atmStrategyId back to null and may cause another order to be submitted, which may cause another to be submitted, which may cause another to be submitted, and so on, in an infinite loop.

        Printing information will give you the answer. Add prints one line above each condition that leads to the AtmStrategyCreate() method being called.
        Print the time of the bar, print CurrentBar, print all values used in the condition along with labels for each value and comparison operator.

        Below is a link to a forum post on using prints to understand behavior.


        Save the output from the output window to a text file (right-click save > as), and attach this to your reply.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I will incorporate those print statements ASAP and report back here. In the meantime, can you give me some guidelines on how to go about determining if an ATM strategy is active but not yet filled?

          Comment


            #6
            Hello lorem,

            Do you mean the entry order has not filled?

            You should do this the same as the SampeAtmStrategy does.
            Under the return for isAtmStrategyCreated, call GetAtmStrategyEntryOrderStatus(). When the status[2] is Working, the entry is working.

            Or did you mean the stop and target orders are still working?
            In which case GetAtmStrategyMarketPosition() will be long or short and GetAtmStrategyStopTargetOrderStatus() will return the status of an order.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by AaronKoRn, Today, 09:49 PM
            0 responses
            7 views
            0 likes
            Last Post AaronKoRn  
            Started by carnitron, Today, 08:42 PM
            0 responses
            9 views
            0 likes
            Last Post carnitron  
            Started by strategist007, Today, 07:51 PM
            0 responses
            10 views
            0 likes
            Last Post strategist007  
            Started by StockTrader88, 03-06-2021, 08:58 AM
            44 responses
            3,980 views
            3 likes
            Last Post jhudas88  
            Started by rbeckmann05, Today, 06:48 PM
            0 responses
            9 views
            0 likes
            Last Post rbeckmann05  
            Working...
            X