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

How to modify order limits for next trading day?

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

    How to modify order limits for next trading day?

    Hi,

    I would like to do following szenario in a 1-minute chart: I set a stop loss oder for an open position at 100. The quote does not fall below the stop. On the next day I want to set it to 99. I use "Bars.IsLastBarOfSession" which works great for backtesting. But in realtime usage (TWS) I run into the problem that the modification is made in the first seconds of the new day. This leads to execution based on the old stop (from previous day at 100).

    My code is quite simple:

    if ( Bars.IsLastBarOfSession && Position.MarketPosition == MarketPosition.Short ) {
    SetStopLoss( "SL", CalculationMode.Percent, NextDaysSL, false );
    SetProfitTarget( "PT", CalculationMode.Percent, NextDaysPT );
    }

    Any ideas or suggestions?

    Martin

    #2
    Hello Martin,

    Your inquiry is that you want to trigger an action at the end of a day before the session closes instead of when the new bar opens at the start of the next session, is this correct?

    Is the script running with Calculate set to 'On bar close'?

    If so, the actions are triggering after the bar has closed and the new bar opens (at the start of new session).

    If you want to trigger actions before the bar closes, you will need Calculate set to 'On each tick', or you would need to add 1 tick intra-bar granularity, and trigger the action before the bar closes.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB,

      yes, the script runs "On bar close".

      What I basically want is that when the trading day is over (and no more tick is going to come) I want to modify the order. So that from the very first tick of the next day the new limits apply.

      I totally get your point with "On each tick" but how do I know when the day is over?

      Is there a way to set a timer? Somthing like "on Midnight modify orders"...

      Martin

      Comment


        #4
        Hello Martin,

        OnBarUpdate is driven by data. It triggers when the bar closes when Calculate is 'On bar close', or when the price changes after a tick is received with 'On price change', or every time a tick is received with 'On each tick'.

        If the session is closed, there will no data to cause OnBarUpdate to trigger.

        If you want to trigger actions after the session is closed, you would need to make a timer and have this trigger a method outside of OnBarUpdate.

        Most likely any order submissions or modifications will be rejected by the brokerage if the session is closed.

        Below is a public link to an example of a timer.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,262 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by WeyldFalcon, 12-10-2020, 06:48 PM
        14 responses
        1,429 views
        0 likes
        Last Post Handclap0241  
        Started by DJ888, 04-16-2024, 06:09 PM
        2 responses
        9 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        41 views
        0 likes
        Last Post jeronymite  
        Working...
        X