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

OnEachTick indicator and strategy OnBarClose

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

    OnEachTick indicator and strategy OnBarClose

    Working in an strategy with an indicator running OnEachTick, but I am trying order entry OnBarClose when conditions are met.

    Two Codes

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1
    || CurrentBars[1] < 0)
    return;

    // Set 1
    if ((Close[0] < EMA1[0])
    && (IndOnEachTick[0] > Limite))
    {
    if (IsFirstTickOfBar && Position.MarketPosition == MarketPosition.Flat)
    EnterShortLimit(Convert.ToInt32(DefaultQuantity), (Close[1] + (Ticks_Lmt_Short * TickSize)) , @"ShortEntryStrong");
    }

    In this first case the order is launched in the bar where conditions are met.



    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((Close[1] < EMA1[1])
    && (IndOnEachTick[1] > Limite))
    {
    if (IsFirstTickOfBar && Position.MarketPosition == MarketPosition.Flat)
    EnterShortLimit(Convert.ToInt32(DefaultQuantity), (Close[1] + (Ticks_Lmt_Short * TickSize)) , @"ShortEntryStrong");
    }

    In this second case the order is launched two bars later the conditions are met.

    Any idea how can I solve this issue?

    #2
    Hello Impeeza,

    Thank you for your post.

    On the second one you're checking the Close, EMA1 and IndOnEachTick of the previously closed bar, so I would expect this not to enter until a bar later than the one above it. Is that not what you're seeing occur?

    If you're not seeing entries when you're expecting, the first thing I'd recommend is adding some prints to the code so you can verify the values of the variables you're checking in your conditions for entry.

    This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction.

    https://ninjatrader.com/support/foru...ns-not-working

    If you run into issues like we saw here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently. With the printout information you can assess what is different between the two.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks, Kate

      And what about the first one? Why in that case the order is launched during the bar the conditions are met and not in the next? I supposed using IsFirstTickOfBar is used in sucha situation...

      Comment


        #4
        Hello Impeesa,

        Thank you for your reply.

        Since you are evaluating the conditions for that currently forming bar on the first tick of the bar, if the conditions are true, the order would be submitted immediately on that same bar when the first tick comes in. This would be expected.

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by r68cervera, Today, 05:29 AM
        0 responses
        1 view
        0 likes
        Last Post r68cervera  
        Started by geddyisodin, Today, 05:20 AM
        0 responses
        3 views
        0 likes
        Last Post geddyisodin  
        Started by JonesJoker, 04-22-2024, 12:23 PM
        6 responses
        33 views
        0 likes
        Last Post JonesJoker  
        Started by GussJ, 03-04-2020, 03:11 PM
        12 responses
        3,239 views
        0 likes
        Last Post Leafcutter  
        Started by AveryFlynn, Today, 04:57 AM
        0 responses
        6 views
        0 likes
        Last Post AveryFlynn  
        Working...
        X