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

Trade being entered on incorrect bar, the bar following the EnterShort/Long Function?

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

    Trade being entered on incorrect bar, the bar following the EnterShort/Long Function?

    Hi,

    I would really appreciate someone's help with this problem on a strategy I am testing?

    I'm new to csharp and really impressed with the strategy builder and everything Ninja and getting familiar with using the Builder.

    Does anyone have any idea why the entry order seems to always be on the bar after the bar I would expect the order to execute on,

    It's s a little hard to see but notice after the "Exit Order On Session Close: you will see the LE 1 @ 4075.00 for long entry on what looks to the bar following where my long condition was satisfied and this code executed:

    Here is the code it's happening on both long and short entries, the exits are perfect as is the Exit On session Close.

    I am also checking for a market position long or short to paint the background
    If short condition exists. I'm really hoping I can get this to execute on the prior as it's only 1 bar but seems to effect the strategies profitability.
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), @"SE");
    BackBrush = Brushes.MistyRose;

    }

    if ((Position.MarketPosition == MarketPosition.Short)
    && (Close[0] > Open[0]))
    {
    ExitShort(Convert.ToInt32(DefaultQuantity), @"SX", "");
    }
    if (Position.MarketPosition == MarketPosition.Long)
    {
    BackBrush = Brushes.Honeydew;
    }
    if (Position.MarketPosition == MarketPosition.Short)
    {
    BackBrush = Brushes.MistyRose;
    }

    }
    Last edited by demarcog; 04-08-2021, 05:59 PM.

    #2
    Hi demarcog,
    Your strategy is set to "Calculate.OnBarClose", isn't it? Thus, Ninja checks after the bar closed, if your conditions are true. The earliest possible time to then react accordingly, is with the open of the next bar. If you want less "lag", you will have to change your strat to Calculate.OnPriceChange or Calculate.OnEachTick. This will still not fire on the same tick, but with the open of the next. However, the "delay" will be significantly shorter. Of course, this will have a significant impact on the CPU load because the number of calculations will greatly increase.
    NT-Roland

    Comment


      #3
      NT-Roland,


      Thanks you for the response. If I set the strategy to calculate on each tick or price close in the past on other platforms the indicators and criteria like Close[0] became very dynamic and in particular the back test would always report a huge profit but in real time this was not the case. DO you thin the same issues will occur? It's also something I could test in playback mode thank you.

      Comment


        #4
        Hello demarcog, thanks for your reply.

        If Calculate is set to OnEachTick or OnPriceChange the OnBarUpdate method will run much more often than OnBarClose. The strategy you wrote must account for that. One good way to control the logic of each bar is to use a boolean flag or keep track of the CurrentBar property. See the "BuySellVolume" indicator as an example.

        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          ChrisL,

          Thanks for the response I will take a look Do you think it's worth the effort in terms of strategy performance vs. OnBarClose()?

          thank you

          glen

          Comment


            #6
            Hello Glen, thanks for your reply.

            If you want the strategy to be able to read intrabar prices and open/close trades within a single bar the strategy must calculate either OnEachTick or OnPriceChange. If that is not required, use OnBarClose.

            Kind regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Chris,

              One question is there a what takes precedence Calculate = in the strategy or the strategy settings.

              II's easier enough to test so I'll give it a try and thank you for the BuySellVolume reference what a beautiful piece of code.

              Thank you very much.

              glen

              Comment


                #8
                Hello Glen, thanks for your reply.

                The Calculate setting set from the user interface will override the setting that is set in State.SetDefaults.

                Kind regards,
                ​​​​​​​-ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  ChrisL,

                  Really that's not what I expected but certainly makes sense. The designers and developers of this product IMHO have to be some of the best coders in the world and I mean that quite literally.
                  I know I'm the broken record, but workind in IT development at Financial Firms on "Wall St" for decades what these guys have done I would have said was impossible and beyond anything I've ever seen and I've seen the front end trading systems used by firms whose name we all know.

                  Thanks again,

                  glen

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by jclose, Today, 09:37 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post jclose
                  by jclose
                   
                  Started by WeyldFalcon, 08-07-2020, 06:13 AM
                  10 responses
                  1,413 views
                  0 likes
                  Last Post Traderontheroad  
                  Started by firefoxforum12, Today, 08:53 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post firefoxforum12  
                  Started by stafe, Today, 08:34 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post stafe
                  by stafe
                   
                  Started by sastrades, 01-31-2024, 10:19 PM
                  11 responses
                  169 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X