Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Where to start if I want to create a strategy on a trading set-up?

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

    Thanks Brett. I did more trouble-shooting and identified the indicator (entry condition) in question.

    My codes are as follows:

    sMomentum.Set(Momentum(FIMA2Type.SMA,8).averageTyp e[0]; OR
    sMomentum.Set(Momentum(FIMA2Type.SMA,8).Average[0];

    Both resulted in the same error message, ie

    NinjaTrader.Indicator.Momentum.averageType is inaccessible due to its protection level
    OR NinjaTrader.Indicator.Momentum.Average is inaccessible due to its protection level.

    Appreciate any tips to fix it. Thank you.

    Comment


      belecona, I'll have Brett get back to you tomorrow.
      AustinNinjaTrader Customer Service

      Comment


        This is likely due to declaring those variables as private.

        The best practice here, if they are DataSeries, is to link the private variable with a public one. You can see an example of this here:


        Follow the same structure used for the bool series BearIndication and BullIndication, with the private declared in variables region starting with lower case letter, and the public linked to this in the properties region starting with an upper-case letter.
        Ryan M.NinjaTrader Customer Service

        Comment


          Thanks Ryan. I used the Bool Series sample to create my second indicator successfully, Unfortunately, it does not do the same trick on the third one, ie the indicator only works when CalculateOnBarClose@True. When it's @False (more real-time), it does not plot unless I press F5 (Reload NinjaScript). You can tell from the following that I have 3 entry requirements:

          World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


          I did some trouble-shooting and identified the Momentum condition has caused non-plotting when CalculateOnBarClose@False. Any idea on how to fix it please?

          I have another Momentum indicator with which I tried over the weekend, That's the one that gave me the "Inaccessible due to its protection level" message. Scary when I simply changed private to public. Almost screwed up the original indicator which I really need for trading. Luckily I got a backup version.

          I am thinking it maybe easier to resolve the CalculateOnBarClose@False myth. Else I will prepare another post capturing the codes I used for my weekend attempt. Thank you for helping me out.

          Comment


            With COBC, you'll want to be sure that you do not assign this anywhere in your called indicators. Safest is remove any COBC assignments, but if you must assign - It should only be in the calling indicator or strategy.

            Called / calling distinction with your script names:
            sMomentum.Set(Momentum(FIMA2Type.SMA,8).Average[0]; //This is the called indicator.

            The script you're accessing that value from is the calling one.
            Ryan M.NinjaTrader Customer Service

            Comment


              I will go through my indicators again (with COBC and protection myths) and see if I can make one of them work. Need to learn some Web meeting applications this afternoon. You will hear from me when I have a big head not knowing how to solve the myth. It's been over a week + I spent the weekend with no luck .. oh well

              Comment


                Hi Ryan

                I finished my Web application learning earlier than expected. Now resume working on my indicator. Not sure how to fix the COBC one even it's a straight-forward entry condition (signal line ><0 for Long/Short). Back to the more advanced one with "Inaccessible because of its protection level". Hoping if I can resolve the Protection issue, the indicator may get triggered with COBC@False. Here it comes a recap on what I did:

                protected overrride void Initialize()

                - I removed CalculateOnBarClose = false;
                - I added sMomentum = new DataSeries(this);

                protected overrride void OnBarUpdate()

                - I added sMomentum.Set (Momentum(FIMA2Type.SMA,8).averageType[0]; (I also tried sMomentum.Set (Momentum(FIMA2Type.SMA,8).Average[0]

                for Entry Conditions
                - I added sMomentum[0]><0 for Long/Short respectively

                Within the Momentum indicator,

                Variables

                - private DataSeries Average;

                protected override void Initialize()

                Average = new DataSeries(this);


                protected override void OnBarUpdate()

                if(Average[0]>=0)
                PlotColors[0][0] = upColor;
                else
                PlotColors[0][0] = downColor;

                Properties (I was under the impression that these codes have made the private DataSeries Average accessible to the public?!)

                [Description("Average type for Momentum")]
                [GridCategory("Parameters")]
                [Gui.Design.DisplayNameAttribute("Average Type")]
                public FIMA2Type AverageType
                {
                get {return averageType;}
                set {averageType = value;}
                }

                Still getting "Momentum.averageType is inaccessible due to its protection level" error message when I tried to compile. Any suggestion please .. sigh .. Thank you.

                Comment


                  Yes, you'll want to follow guidelines in my first post this morning if you're getting protection level messages. I've highlighted below the components from the reference sample on this. Once you set it up like this, when you reference these variables from another script, you use the public upper-case one.

                  Variables Region:
                  /* We declare two BoolSeries objects here. We will expose these objects with the use of
                  public properties later. When we want to expose an object we should always use the associated
                  IDataSeries class type with it. This will ensure that the value accessed is kept up-to-date. */
                  private BoolSeries bearIndication;
                  private BoolSeries bullIndication;

                  Initialize() Method:

                  bearIndication = new BoolSeries(this);
                  bullIndication = new BoolSeries(this);

                  Properties Region:
                  [Browsable(false)]
                  [XmlIgnore()]
                  public BoolSeries BearIndication
                  {
                  get { return bearIndication; } // Allows our public BearIndication BoolSeries to access and expose our interal bearIndication BoolSeries
                  }

                  [Browsable(false)]
                  [XmlIgnore()]
                  public BoolSeries BullIndication
                  {
                  get { return bullIndication; } // Allows our public BullIndication BoolSeries to access and expose our interal bullIndication BoolSeries
                  }
                  Last edited by NinjaTrader_RyanM1; 06-21-2011, 01:04 PM.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    Hi Ryan

                    My trillion thanks for the additional tips. I don't know how I did it after modifying it 10+ more times .. I just succeeded in making the indicator worked with COBC@False .. hooray! Will monitor it this week.

                    My next assignment will be combining two of my three indicators into a multi-timeframe one. Thank you Ryan!

                    Comment


                      Hi Ryan

                      Now that my new indicator behaves "normal", I would like to learn how to create a mult-timeframe indicator. Not sure if it's easy?! I am thinking if I may just add a few Moving Average conditions on a 9-Range chart to the indicator I use on a lower timeframe chart.

                      I have been reading the Sample MultiTimeFrame (MTF) strategy which I found from the Forum. Are there some samples on creating a MTF indicator? Appreciate your suggestion. Thank you. Have a great day. (Here it's quite humid .. felt like 40 degr C.)

                      Comment


                        Glad you were able to sort it out.

                        Indicators use the same structure as strategies for multi time frames, so you can use the built in one available from Tools > Edit NinjaScript > Strategy. One additional item you may need is the line below. You need a CurrentBar check like this for each series to prevent the script from accessing bars before they exist.

                        if (CurrentBar < 0 || CurrentBars[1] < 0) return;

                        Ryan M.NinjaTrader Customer Service

                        Comment


                          Thanks Ryan for your prompt response. I created 1 MTF strategy and 1 MTF indicator based on the sample and suggested MTF help guide.

                          Good news:

                          1. Both compiled successfully.
                          2. MTF strategy did trigger trades and it's slightly green.

                          Not so-good news: My MTF indicator plots nothing on the chart.

                          I will do some trouble-shooting before sharing my script for your kind comments/tips. Thank you!

                          Comment


                            Hi Ryan

                            I did more changes to my non-functional MTF indicator and it's still not plotting .. sigh .. I'm going to outline what I did and would appreciate your suggestion to make it functional.

                            I have an indicator which I use on a 5-Range chart. It will plot Up/Down arrows and optional audio alert when the specified entry conditions are met either real-time or upon completion of the signal candle (COBC@True/False). To turn it into a MTF indicator, I have been trying to add some Moving Average conditions to be met on 9-Range as follows:

                            protected override void Initialize()
                            Add(PeriodType.Range,5); // Not sure if I need this since I will put the indicator on a 5-Range chart
                            Add(PeriodType.Range,9);

                            protected override void OnBarUpdate()
                            if (CurrentBar<0 || CurrentBars[1]<0) // I replaced (CurrentBar ==0) with this and am not sure if it will affect the 5-Range conditions. Even I stayed with (CurrentBar==0), my MTF indicator did not plot

                            if (SMA(BarsArray[2],10)[0]-SMA(BarsArray[2],6)[0]<=4*TickSize && Highs[2][0]>SMA(BarsArray[2],10)[0]
                            && Rising(SMA(BarsArray[2],10)) && Rising(SMA(BarsArray[2],6)))
                            //these are the 9R conditions and I added the code right before the existing 5-Range ones, ie
                            - SMA(10) - SMA(6) <= 4 pips
                            - High[0] > SMA(10)[0]
                            - Rising(SMA(10))
                            - Rising(SMA(6))

                            Note: I added similar conditions (for Short) to the 5-Range conditions which started with else if ..

                            The indicator did compile successfully. When I put it on a 5-Range chart, it's not plotting = not working. I must have missed something. Please enlighten me. Thanks Ryan!
                            Last edited by belecona; 06-27-2011, 10:22 AM.

                            Comment


                              belecona,

                              if (CurrentBar<0 || CurrentBars[1]<0)

                              Your code effectively has 3 bars series so you would actually need to make that line this instead:

                              if (CurrentBars[0] < 0 || CurrentBars[1] < 0 || CurrentBars[2] < 0)

                              Normally I would also not recommend checking it versus 0. Instead I would check it against BarsRequired, but that distinction is up to you to decide what you want the behavior to be for your code.
                              Josh P.NinjaTrader Customer Service

                              Comment


                                Thanks Josh for your prompt response. The revised script was compiled successfully (using your suggested code) and it's still not plotting. There's no error message under the Log tab. Where should I look please?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                651 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                370 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                574 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                577 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X