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

BarsArray equivalent within Indicators?

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

    BarsArray equivalent within Indicators?

    Hi,
    I have built a custom Indicator, and then used that within a custom Strategy.

    Within the strategy I have used
    Add(PeriodType.Minute, 15) with BarsArray[1]
    to feed a 15min dataseries through the indicator, against which certain mkt orders are then fired from the strategy (even when the strategy is run on, say, a 5min basis).

    Is there a way to hard code within an indicator itself that it should always run against, say, 15min bars?
    What I would like to do is then chart the (15min) Indicator on my backtesting results chart, even if I am executing the strategy on a 3min or 5min basis.

    If I cannot hardcode the indicator to always be a 15min indicator (I believe the above periodtype "Add" only works within strategies, not indicators? - is there another way to do that?) can you tell me a line of code that will automatically plot the 15min (ie BarsArray[1] index indicator values) on the 5min BT strategy results chart? Is that possible?

    The problem I have currently is that when I run my strategy on a 5min basis, and then plot the Indicator on the BT chart (which is perforce on the same 5min basis), there is a visual mismatch between the buys and sells that the strategy generated (which ran off 15min bars per my barsarray index=1) and the indicator lines plotted on the chart which are based off 5min bars. This makes it hard to visually verify that the buys/sells are correct as the indicator is not showing the actual levels on the chart that were used to generate the orders.

    many thanks

    #2
    Update

    Quick Update:
    I thought I had possibly found a way to plot my custom indicator within my custom strategy code, adapting some code from the reference sample code written by Josh ("SampleEnterOnceEveryTick").

    The code I tried to adapt is the following:

    // Set the plot colors.
    LinReg(Median, 10).Plots[0].Pen.Color = Color.RoyalBlue;
    SMA(Median, 10).Plots[0].Pen.Color = Color.Red;

    // Add indicators to the chart.
    Add(LinReg(Median, 10));
    Add(SMA(Median, 10));

    However if I replace the LinReg and SMA indicator names in the code above with my own custom indicator name it gives an error, stating that they are methods, and not valid in this context. (Prefixing them with "Indicator." does not help either.)

    Does that mean that only standard (pre-loaded by ninja?) indicators can be called in this way?
    If I can call my custom indicators in this (or similar) way then I hope to be able to pass the BarsArray[1] with them in order to force my own period selection onto the strategy chart for that indicator. thanks again.

    Comment


      #3
      Hello Pourleau,

      You are correct that MultiSeries is currently only available within a strategy. We are changing this in our upcoming version 7 to allow multiseries plotting in an indicator.
      Version 7 info.

      You should be able to plot your own custom indicators in a strategy. The reference sample below should help with this.
      Plotting from within a NinjaScript strategy.
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        OK many thanks. I note that this solution (Value.Set) does not work within the strategy analyzer however, but only in realtime charts.
        It was really within the analyzer that I would like to plot that - is there any other way that is compatible within the analyzer that you could recommend for v6.5?

        Also I have a similar problem in trying to mix calculations made on tick updates vs those made on bar close. Reading the reference sample code "Strategy: Separating logic to either calculate once on bar close or on every tick", I see that this coding solution also only works in realtime and not with historical data within the Strategy Analyzer.

        Is there anyway to treat tick data within the Strategy Analyzer? Would the above code that uses "FirstTickOfBar" work if I was to pass tick data through the analyser (and is that possible)?

        thanks again

        Comment


          #5
          That's correct. Currently you are unable to plot indicators based on secondary series within the strategy analyzer chart. This will change for our upcoming version 7.


          For backtesting in the strategy analyzer, all calculations are done on bar close. Please see the article below on discrepancies between real-time and a backtest.
          http://www.ninjatrader-support.com/HelpGuideV6/DiscrepanciesReal-TimeVsBacktest.html


          You may be interested in the approach outlined in the reference sample below.
          Backtesting NinjaScript Strategies with an intrabar granularity.
          Ryan M.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by gentlebenthebear, Today, 01:30 AM
          2 responses
          13 views
          0 likes
          Last Post gentlebenthebear  
          Started by Kaledus, Today, 01:29 PM
          2 responses
          8 views
          0 likes
          Last Post Kaledus
          by Kaledus
           
          Started by frankthearm, Yesterday, 09:08 AM
          13 responses
          45 views
          0 likes
          Last Post frankthearm  
          Started by PaulMohn, Today, 12:36 PM
          2 responses
          16 views
          0 likes
          Last Post PaulMohn  
          Started by Conceptzx, 10-11-2022, 06:38 AM
          2 responses
          56 views
          0 likes
          Last Post PhillT
          by PhillT
           
          Working...
          X