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 cls71, Today, 04:45 AM
        0 responses
        1 view
        0 likes
        Last Post cls71
        by cls71
         
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        213 views
        1 like
        Last Post PaulMohn  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        544 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        12 views
        0 likes
        Last Post XXtrader  
        Working...
        X