Announcement

Collapse
No announcement yet.

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 yeikson89, Today, 02:53 PM
        2 responses
        10 views
        0 likes
        Last Post yeikson89  
        Started by sdauteuil, Today, 01:06 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by trumpy, 03-09-2017, 02:11 PM
        30 responses
        3,224 views
        0 likes
        Last Post foxthorn  
        Started by shani77, Today, 09:58 AM
        1 response
        23 views
        0 likes
        Last Post NinjaTrader_Eleanore  
        Started by cjanau, Yesterday, 11:07 AM
        1 response
        31 views
        0 likes
        Last Post NinjaTrader_ThomasC  
        Working...
        X