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

Errant entries on crossover strategy

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

    Errant entries on crossover strategy

    Hi
    I am having an issue with my strategy placing two many orders when reversing from long to a short or vice versa. The strategy is a ma crossover so if 10 crosses above 30 enter long if 10 crosses below 30 enter short.

    This only happens when trading on live account on playback connection all works fine. I have attached a picture of the execution of one such instance. So strategy triggers to enter long now moving average crosses below so I want to close the long and enter a short. But on live data I am ending up with two shorts. In executions I am seeing a close position a sell from my strategy labelled short911 and then another short which leaves me with 2 shorts when I should only have 1. I have to manually place a buy to get back to one short position.

    I do have a exitlong and exit short clause with the strategy but they have a time frame attached to only be active when my entry timeframe has passed to close out the last trade of my session.

    Again on market playback data it all works perfect. But running the live strategy it does not.

    Any help would be appreciated.

    #2
    Hello dpschapper,

    Thanks for your post.

    This will be seen when you mix Enter and Exit methods. If you want to reverse, just call EnterShort when Long and EnterLong when Short. Do not include the Exit methods when reversing.

    If you want to see if the strategy is long or short, please see below on how to make position checks.

    https://ninjatrader.com/support/help...ionComparisons

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      So I believe that is what I have in the strategy. The exitlong condition would not have been active during this period. So the long was exited because of the trigger to enter short. I will update the exit scenario as you mentioned but am thinking I will still get the same result. I will post the conditions of the strategy as well.

      Comment


        #4
        So I downloaded the data from last night and ran the strategy as market replay. No issues so why does running on my live account add an extra execution in the mix. See pic of market replay executions.

        Comment


          #5
          Hello dpschapper,

          Live orders take more time to reach the broker's order routing server and the exchange.

          NinjaScript strategies use execution events to drive the strategy position. If the logic calls Exit and Enter methods at the same time and the order/execution/position information takes longer to reach NinjaTrader and notify the strategy, the Enter methods will submit orders to reverse, and the Exit method will also exit the position. This is less often seen with Sim and Playback because those orders are simulated on the PC.

          So, the extra order would appear live because there is more time passed before order/execution/position information reaches the strategy, and the order submissions were allowed when the strategy logic was processed.

          The solution here is to write specific logic to enter only when Position.MarketPosiiton is MarketPosition.Flat. When you want to reverse, check if Position.MarketPosition is MarketPosition.Long, and then call EnterShort() and ensure ExitLong() cannot be called on the same bar. When you want to exit a position, check if Position.MarketPosition is MarketPositon.Long, and call ExitLong(), and ensure EnterShort() cannot be called on the same bar.
          Last edited by NinjaTrader_Jim; 02-07-2022, 04:26 PM.
          JimNinjaTrader Customer Service

          Comment


            #6
            Ok I will try and add the flat position check and run it again today and see what happens. Thanks for the insights.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Taddypole, 04-26-2024, 02:47 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Eduardo  
            Started by futtrader, 04-21-2024, 01:50 AM
            6 responses
            58 views
            0 likes
            Last Post futtrader  
            Started by sgordet, Today, 11:48 AM
            0 responses
            4 views
            0 likes
            Last Post sgordet
            by sgordet
             
            Started by Trader146, Today, 11:41 AM
            0 responses
            5 views
            0 likes
            Last Post Trader146  
            Started by jpapa, 04-23-2024, 07:22 AM
            2 responses
            19 views
            0 likes
            Last Post rene69851  
            Working...
            X