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

Order management problem in strategy with custom bars type that is not price based

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

    Order management problem in strategy with custom bars type that is not price based

    Edit: relates to NT8 and not NT7, sorry

    Hi,

    thanks to the fantastic feature of NT of allowing custom bar types, I was able to create my own. It doesn't represent price and can go negative.
    Unfortunately the problem is that when I utilize it in a strategy as an additional data series to a time based one the order management fail.
    It looks like NT will use the closing price of my custom bars to determine exits.
    Is there a way in either the bar type itself or when adding the data series to let NT know that it should not base trades on the bars output?

    Code:
                    AddDataSeries(
                        new BarsPeriod{
                          BarsPeriodType = (BarsPeriodType) 16
                        , Value = BarsPeriod.Value
                    } )
    
    ...
    
    
                    SetProfitTarget(signalName, CalculationMode.Ticks, 20);
                    SetStopLoss(signalName, CalculationMode.Ticks, 20, false);
                    EnterLong(1, 0, signalName);
    Error: Calculated target order price was smaller/equal 0. No target order placed

    If I change the logic to CalculationMode.Price no error occurs but just like with ticks the strategy analyzer shows millions in profits or losses on just 1 YM lot and 1000 trades within 4 months.
    My assumption is:
    1. entering on primary series YM close at 22000
    2. custom bar closes at 5
    3. NT exits with a 21995 ticks loss

    Entering on primary or secondary BarsInProress doesn't make any difference and trying to supply a MarketDataType to AddDataSeries was without success.
    Since there are other bar types like the heiken ashi that do not strictly follow price, is there a simple way to bypass the problem?

    Thanks in advance.
    Last edited by MojoJojo; 04-27-2020, 06:43 AM.

    #2
    Hello MojoJojo,

    Thanks for your post.

    NinjaTrader will use the OHLC of the data series that the order is submitted to to simulate how the order fills. I would recommend adding a single tick data series to the strategy and then to submit orders to that data series. For example, if the single tick data series is the 2nd added data series to the script, submit orders to BarsInProgress 2.

    I.E.

    EnterLong(2, 1, signalName);

    Backtesting with intrabar granularity (NinjaTrader 8) - https://ninjatrader.com/support/help...ipt_strate.htm

    Backtetsing with intrabar granularity (NinjaTrader 7) - https://ninjatrader.com/support/help...ipt_strate.htm

    Set methods cannot be specified a specific BarsInProgress for order fills, so you could consider using Exit methods like the example below, and changing the BarsInProgress index that the order is submitted to.

    SampleOnOrderUpdate (NinjaTrader 8) - https://ninjatrader.com/support/help...and_onexec.htm

    SampleOnOrderUpdate (NinjaTrader 7) - https://ninjatrader.com/support/help...and_onexec.htm

    Exit methods do not allow specifying OCO strings, but this is possible using the Unmanaged Approach. I have attached an example Unmanaged strategy that may be helpful.

    Unmanaged Approach (NinjaTrader 8) - https://ninjatrader.com/support/help...d_approach.htm

    Unmanaged Approach (NinjaTrader 7) - https://ninjatrader.com/support/help...d_approach.htm

    I look forward to assisting.
    Attached Files
    Last edited by NinjaTrader_Jim; 04-27-2020, 06:53 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim,

      thanks a lot, that helped, oddly enough I used quantity in the position of the BarsInProgress for weeks after I switched from
      Code:
      EnterLong(quantity, signal)
      to

      Code:
      EnterLong(barsInProgress, quantity, signal)
      NT never complained about the 0 and ran the tests with quantity 1.

      But thanks to the outstanding support, the problem trade management problem is solved.

      Edit:
      The primary bars series was sufficient, ticks were not required.
      Last edited by MojoJojo; 04-27-2020, 07:12 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by JoMoon2024, Today, 06:56 AM
      0 responses
      6 views
      0 likes
      Last Post JoMoon2024  
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      17 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      5 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,786 views
      0 likes
      Last Post Leafcutter  
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Working...
      X