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

Accessing Indicator from a Strategy

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

    Accessing Indicator from a Strategy

    Hi,

    My indicator uses Volumetric data. I set Range as period type.

    I added the Indicator in the strategy. How do i set/configure to take the data series as Volumetric and Range values to an Indicator added in the Startegy when I call it ?

    Below code snippet is from my indicator and I am getting Bartype is null error when i run the strategy with AddChartIndicator method. Can you please help me how to set the data series to an Indicator which called from a Strategy?

    barsType = BarsArray[0].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
    if (barsType == null){
    Print("barsType is null: " + CurrentBars[0]);
    return;
    }​
    Last edited by greenhollow803; 11-22-2023, 12:36 PM.

    #2
    Hello greenhollow803,

    Is the chart set to use Volumetric bars (primary bars)?

    If so, both the strategy and the indicator would have access to the bars.

    Attached is a test script that prints the volumetric bar info from a strategy and from a hosted indicator.
    VolumetricHostTest_NT8.zip

    Did you add a volumetric series with AddVolumetric()?

    If so, use BarsArray[1] instead of BarsArray[0].
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for queick response and for sharing the example.

      I am using Volumetric as primary. Not via via AddDataSeries.

      You used as a class variable instead of using the AddChartIndicator.

      So I tried similar way but I got the below error. How can I fix this?
      BSKBot2.cs 'NinjaTrader.NinjaScript.Strategies.Strategy.BSKSi gnal2(bool, int, bool, int, bool, bool, bool, int, int, double, int, int, int, int, double, long, long, long, long, int, int, int, int, int, int, bool, bool, bool, bool, bool)' is a 'method' but is used like a 'type' CS0118 32 12

      Comment


        #4
        Hello greenhollow803,

        Are you calling the indicator as an indicator method?

        Or are you attempting to use the 'new' keyword?

        Is the indicator extending the Indicator class?

        The example I provided has a working hosted indicator that is called by the strategy.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I exactly followed the below example.




          Added the indicator as shown below

          if (State == State.DataLoaded)
          {
          AddChartIndicator(BSKSignal3());
          }​

          When I try to compile then got the below error.
          BSKBot2.cs No overload for method 'BSKSignal3' takes 0 arguments CS1501 329 25

          Comment


            #6
            Hello greenhollow803,

            The custom indicator appears to have parameters that need to be supplied for the overload signature.

            There also may be an issue with the indicator itself.

            Are you certain this is an indicator?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Yes. I developed myself and working well on the chart showing the signals. As of now I am copying the code to separate strategy to test various settings for multiple days.

              Instead of that I would like to just call the indicator so that I no need to duplicate my efforts.

              Are there any specific config information you want me to share related to my indicator.

              Comment


                #8
                I added all the input parameters as shown to the Indicator then from startegy it got triggered successfully. However failed to recognise the Volumetric Bar.

                AddChartIndicator(BSKSignal2(false,10,false,5,true ,false,false,2,1,1000,6,6,20,10,100,10,10,10,1000, 299,299,40,2,3,5,false,false,true,true,false));


                In indicatgor it exactly failed at the below code and printed null. So it was not able to pick the Volumetric series which is primary for both Indicator and Startegy. I can change it to secondary by adding as data series in Indicator. Will it cause any performance issues ?

                barsType = BarsArray[0].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
                if (barsType == null){
                Print("barsType is null: " + CurrentBars[0]);
                return;
                }​

                Comment


                  #9
                  Hello greenhollow803,

                  The public variables (inputs) using NinjaScriptProperty you have added to the indicator will become overload parameters which must be supplied to the method call.

                  For example the MACD has 3 inputs: a fast, slow, and smooth input.
                  MACD(int fast, int slow, int smooth)
                  Calling this would appear as MACD(12, 26, 9)

                  Place the cursor in-between the parenthesis and press Ctrl + spacebar and the intelliprompt will appear and show the overload signature.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    After cleaning up all unnecessary input parameters it worked now. Thanks for all your help

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bc24fl, 08-30-2019, 01:58 PM
                    3 responses
                    253 views
                    0 likes
                    Last Post PaulMohn  
                    Started by tradingnasdaqprueba, 04-09-2024, 09:52 AM
                    6 responses
                    27 views
                    0 likes
                    Last Post tradingnasdaqprueba  
                    Started by PaulMohn, Today, 02:06 AM
                    1 response
                    3 views
                    0 likes
                    Last Post PaulMohn  
                    Started by Mindset, Today, 01:27 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by EB Worx, 03-07-2023, 05:05 AM
                    4 responses
                    99 views
                    1 like
                    Last Post cls71
                    by cls71
                     
                    Working...
                    X