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 set to Calculate on Tick but order entries "delayed"?

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

    Strategy set to Calculate on Tick but order entries "delayed"?

    Click image for larger version  Name:	long.PNG Views:	0 Size:	45.8 KB ID:	1122532 Please review the screenshot.

    I have a strategy set to calculate per tick, and to help me visualize, I am painting the bars white where my condition is met.

    As soon as the white bar presents itself, it should enter the long order immediately but this is not happening.

    On the example, you will see that the low of the white bar is 5.98, yet the order is listed at 6.04 which appears to be the close of the entire white candle and not the tick..

    What do I need to change so that the long is triggered on the very first tick of the white bar please and thank you kindly!



    if (State == State.SetDefaults)
    {
    ....
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = true;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = true;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;

    ....

    when the time comes:
    EnterLong(100, "HB");

    Do I need to change the code and use a limit and hit the ask or something?

    Here's another example. Expected to enter on the white candle, right at 5.65 where the crosshair is but it appears to enter after the close of the white candle at 5.67?

    Click image for larger version  Name:	long2.PNG Views:	0 Size:	36.9 KB ID:	1122534


    And on more example, the more data the better, right?

    Expected to enter immediately on the 1st white candle tick, crosshair shows right around 6.38 BUT triggered at 6.41 on close of 1st white candle...

    Click image for larger version  Name:	long3.PNG Views:	0 Size:	43.9 KB ID:	1122537
    Last edited by focus333; 10-13-2020, 02:06 PM.

    #2
    Hello focus333,

    Thanks for your post.

    Using market orders means that the order will fill but the price would be at the convenience of the market.

    Live market orders cannot be filled instantaneously and does require a small amount of internet time to process and price can change within that small time.

    You could use a limit order if you want to get filled at a preferred price, at the risk of not getting filled.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you kindly, NinjaTrader_PaulH .

      Appreciate the quick response. Well, so I changed the code to use limit order to this:

      EnterLongLimit(share_size, Open[0], "HB");


      In the hopes that it would fill right away on the 1st white candle but things got worse... notice that the 1st white bar was missed completely and the second set of whites had even worse entry, missing the 1st 2 white bars? I must be missing something else?

      Also, regarding the previous post:
      You said: "Using market orders means that the order will fill but the price would be at the convenience of the market." <- I get that but should it not, at least, fill on the same bar instead of 1, 2,3 minutes after?


      Thanks again!
      Click image for larger version  Name:	long4.PNG Views:	0 Size:	37.2 KB ID:	1122552


      EnterLongLimit(share_size, Open[0], "HB");

      Comment


        #4
        Hello focus333,

        I am at the end of my day today.

        So I can answer you tomorrow:

        Are you testing on live data, historical data on the chart, historical data on the strategy analyzer or playback with market replay data?
        Does your script access additional data series? (if so please identify)
        Are you using the Strategy Builder or the Ninjascript editor?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi NinjaTrader_PaulH ,

          Started with the strategy builder but then edited it.

          The strategy uses:
          - 2 custom indicators set to
          Calculate.OnEachTick
          - Standard NinjaTrader EMA indicator, which I did not change (could this be the issue? Would I need to copy this and make sure it is set to Calculate.OnEachTick?)

          I am new to the platform and strategy development, so regarding you question bout live data, historical on the chart, etc, I am not sure. How may I accurately check for that?

          I would assume live data as I have my IB feed connected.

          This is what I have on State.SetDefaults
          Calculate = Calculate.OnEachTick;
          EntriesPerDirection = 1;
          EntryHandling = EntryHandling.UniqueEntries;
          IsExitOnSessionCloseStrategy = true;
          ExitOnSessionCloseSeconds = 30;
          IsFillLimitOnTouch = true;
          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
          OrderFillResolution = OrderFillResolution.Standard;
          Slippage = 0;
          StartBehavior = StartBehavior.WaitUntilFlat;
          TimeInForce = TimeInForce.Gtc;
          TraceOrders = true;
          RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
          StopTargetHandling = StopTargetHandling.PerEntryExecution;
          BarsRequiredToTrade = 20;




          And onBarUpdate is simple, only having:
          protected override void OnBarUpdate()
          {
          if ( CurrentBar < 6)
          return;

          .... strategy logic.....
          MovAvg[0] = EMA(Close, 18)[0];
          .... strategy logic.....

          if (condition) {
          SetStopLoss("HB", CalculationMode.Price, my_stop, false); //Set protective orders before the entry is made.
          SetProfitTarget("HB", CalculationMode.Price, ( Close[0] + RR * 1 ), false);
          EnterLongLimit(share_size, Open[0], "HB");
          }

          Comment


            #6
            Hello focus333,

            Thanks for your reply.

            The Calculate setting of the strategy will be the same calculate setting used by any indicators called by the strategy. In this case, you are using calculate.OnEachTick so all indicators used by the indicators will likewise perform as Calculate.OnEachTick, on live data.

            When you apply your strategy to a chart, are you connected to a live data feed? Are your charted examples developed with live data or are they from historical trades that your strategy performs before connecting to live data? To clarify: When you are connected to a live data feed and your charts are showing new bars, if you apply a strategy to the chart, the strategy will perform "Historical trades" (trades that would have occurred if they were live) on the charts historical bars and my question is are we looking at historical trades or are these trades that you watched develop on live data. This is a significant question because historically your strategy will perform one way and live will be different (based on the calculate setting you are using) and to best answer your questions I need to know what we are looking at.

            In your code example showing the stops and entry order, are you also coloring the bars in that same code block? If not, please have the strategy draw an object on the chart when your condition is true. Something like: Draw.Dot(this, "Test"+CurrentBar, 0, Low[0] - 4 *TickSize, Brushes.Gold); This will show on the chart below each bar where your entry conditions are true.



            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by FrancisMorro, Today, 03:24 AM
            0 responses
            1 view
            0 likes
            Last Post FrancisMorro  
            Started by Segwin, 05-07-2018, 02:15 PM
            10 responses
            1,770 views
            0 likes
            Last Post Leafcutter  
            Started by Rapine Heihei, 04-23-2024, 07:51 PM
            2 responses
            31 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by Shansen, 08-30-2019, 10:18 PM
            24 responses
            944 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            11 views
            0 likes
            Last Post Max238
            by Max238
             
            Working...
            X