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 on FDAX open bar

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

    Strategy on FDAX open bar

    Hi! I'm trying to make a strategy on first bar on FDAX index when it breaks out its high or its low but strategy enters after the second bar (on the third bar) and not after the firstbarofsession as I print on the code.

    ¿Any solution for this?

    Thanks!!!



    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (Bars.IsFirstBarOfSession == true)
    {
    Mínimodelas8h = Low[0];
    }

    // Set 2
    if ((CrossBelow(Low, Mínimodelas8h, 1))
    && (Times[0][0].TimeOfDay <= new TimeSpan(8, 30, 0)))
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), @"MBSRacorto");
    }

    // Set 3
    if (Bars.IsFirstBarOfSession == true)
    {
    Máximodelas8h = High[0];
    }

    // Set 4
    if ((CrossAbove(High, Máximodelas8h, 1))
    && (Times[0][0].TimeOfDay <= new TimeSpan(8, 30, 0)))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"MBSRalargo");
    }

    }
    }
    }

    #2
    Hello Eugenio,

    Thanks for your post.

    For live trading, you would need to set your strategy to Calculate.OnEachTick or Calculate.OnPriceChange to enter orders intrabar or when the entry conditions occur. Please note that this will cause your strategy to execute on each tick (or price change) which can cause unexpected results. You may wish to separate your strategy logic so that some parts execute on the close of the bar and other logic to occur on each tick. Here is a link to a reference example of how to do this:http://ninjatrader.com/support/forum...ad.php?t=19387

    If you are backtesting or viewing trades historically then the trades will show as you have seen because the strategy can only run in the Calculate.OnBarClose historically. What happens is that at the end of the bar your code is calculated and if a cross is determined then the entry order is placed but cannot be filled until the next bar. With NinjaTrader8 you can select High order fill processing which would allow you to use a faster secondary series which will provide more On Bar Updates and would allow for intrabar orders.
    Reference: http://ninjatrader.com/support/helpG...ical_fill_.htm
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kujista, Today, 05:44 AM
    0 responses
    5 views
    0 likes
    Last Post kujista
    by kujista
     
    Started by ZenCortexCLICK, Today, 04:58 AM
    0 responses
    5 views
    0 likes
    Last Post ZenCortexCLICK  
    Started by sidlercom80, 10-28-2023, 08:49 AM
    172 responses
    2,281 views
    0 likes
    Last Post sidlercom80  
    Started by Irukandji, Yesterday, 02:53 AM
    2 responses
    18 views
    0 likes
    Last Post Irukandji  
    Started by adeelshahzad, Today, 03:54 AM
    0 responses
    8 views
    0 likes
    Last Post adeelshahzad  
    Working...
    X