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

Closing time

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

    Closing time

    Hello!
    I wrote schedules when the order should be closed! that is, time to exit the market.
    question where to put this code ??

    if((exitSesion1 && ToTime(Time[0]) >= end_time && ToTime(Time[0]) <= start_time_1) || (exitSesion2 && ToTime(Time[0]) >= end_time_1 && ToTime(Time[0]) <= start_time_2))
    {
    ExitLong();
    ExitShort();
    CancelOrder(entryOrder1);
    CancelOrder(entryOrder2);
    }

    OnBarUpdate is not correct as the work on closing the bar and the strategy works a long interval or long renko

    #2
    Hello oscsoft,

    OnBarUpdate would generally be where this type of logic would go, you could also use the other overrides like OnMarketData to have this checked for incoming realtime data. If the reason this cannot go in OnBarUpdate is due to the interval or bars type being used you could make a multi series strategy which has a more granular secondary series such as 10 seconds. That would allow you to execute some logic every 10 seconds and other logic at the rate of the renko.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for the answer !
      honestly, I did not quite understand how to implement this!
      But can I see an example of the implementation of this issue? using an example of a simple strategy.

      thanks

      Comment


        #4
        Hello

        You can see an example of the OnMarketData override here: https://ninjatrader.com/support/help...b=OnMarketData
        OnMarketData is called for market data events, you could execute that code from that override if you wanted to break away from the renko series and OnBarClose. That would only work in realtime so if you need to backtest the strategy this likely is not the best solution as TickReplay would be required.

        Otherwise for an example of a multi series strategy you can see the SampleMultiInstrument or SampleMultiTimeFrame strategies that come with NinjaTrader. Because this is a more complicated subject I would suggest to read the multi series documentation to better understand using multiple series to control logic: https://ninjatrader.com/support/help...lightsub=multi

        After adding a secondary series you would execute the code you had provided from a BarsInProgress condition:

        Code:
        if(BarsInProgress == 1)
        {
        
        }


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by arvidvanstaey, Today, 02:19 PM
        4 responses
        11 views
        0 likes
        Last Post arvidvanstaey  
        Started by samish18, 04-17-2024, 08:57 AM
        16 responses
        61 views
        0 likes
        Last Post samish18  
        Started by jordanq2, Today, 03:10 PM
        2 responses
        9 views
        0 likes
        Last Post jordanq2  
        Started by traderqz, Today, 12:06 AM
        10 responses
        18 views
        0 likes
        Last Post traderqz  
        Started by algospoke, 04-17-2024, 06:40 PM
        5 responses
        48 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X