Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SwingRays Indicator Issue

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

    SwingRays Indicator Issue

    Hi,

    I'm trying to use the SwingRays2b indicator in a strategy to provide that the last swinglow using this indicator. I used the Strategy Builder to get the basic code, but when I transfer it into my strategy, I'm not getting any results. So then I tried to just get it to plot the indicator and I'm getting an error. Here is my code.

    Under Startup:
    private SwingRays2b SwingRays2b1;

    Under State Date Loaded:
    SwingRays2b1 = SwingRays2b(Close, 5, false, false, 1);
    AddChartIndicator(SwingRays2b1);

    Here is the error I get.
    Indicator 'SwingRays2b': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.

    The strategy does run, but it does not plot the SwingRays. Eventually I want to get the last SwingLow using this indicator. I'm not sure that is an option, but first things first as I'm just trying to get it to plot the inidcator.

    Thanks,
    Lee

    Last edited by lee612801; 03-08-2021, 10:47 AM.

    #2
    Hello Lee,
    You can add below code in OnBarUpdate() :
    Code:
    if (CurrentBar < 12)
    return;
    Then your code, it should work. If you go thru the SwingRays indicator code it says :
    Code:
    if(CurrentBar < 2 * Strength + 2)
    return;
    Now since you're using Strength as 5, you should ignore first 12 bars & so the error which is not plotting anything.
    Hope it helps!
    Last edited by s.kinra; 03-08-2021, 11:36 AM.

    Comment


      #3
      Hello lee612801, thanks for writing in.

      You can use Visual Studio debugging to see the exact line where the indicator is failing:

      https://ninjatrader.com/support/help..._debugging.htm

      Once you attach Visual Studio to the NinjaTrader process, run the strategy so that is re-creates the error. Visual Studio will break on the line that caused the exception.

      Does the error go away if you remove AddChartIndicator and only use the data from the indicator? It seems the indicator needs some parameter that is not being given by the default constructor of the indicator. In that case we would need to know what object is not initialized in SwingRays2b.

      Kind regards,
      -ChrisL
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        Hi s.kinra,

        Thank you for that as I missed it. I added the return code using 12 bars, but it still is coming up with the same error and not plotting the indicator. Any other suggestions or recommendations?

        Thanks,
        Lee

        Comment


          #5
          Hello Lee,
          I had another look on its code, it has no Plots so you can't use it in Strategy anyways, not sure if it can plot on the chart thru strategy. I believe there are no parameters exposed which can be used in Strategy so you need to find another way to work with it. I'll try to add it tomorrow & see if I get some clue for you.

          Comment


            #6
            Hi s.kinra,

            Thanks for the info. Its disappointing that this cannot be used within strategies, but that very well sounds like the issue. I was also looking at using the Swing indicator, but it does not remove the broken highs and lows like the SwingRay indicator. does. Any help is greatly appreciated.

            Thanks,
            Lee

            Comment


              #7
              Hello Lee,
              Yes it does remove Swing Highs & Lows, if you're not noticing you can keep broken lines (check box in indicator settings) so it will let you when the High or Low is broken. Quite possible Calculation mode is set to OnBarClose, you can change it to OnEachTick or OnPriceChange so just double check that. For me its working fine.

              I added it to a test strategy & wasn't getting any errors while running the strategy, though strategy wasn't doing anything. The possible issue could be your condition in Strategy Builder, you can remove the condition & it should work without errors. The reason being the same there is no parameter defined so no condition can be applied.
              Last edited by s.kinra; 03-08-2021, 10:08 PM.

              Comment


                #8
                Hi s.kirna,

                Are you referring to the SwingRays2b indicator or the Swing indicator?

                If you are referring to the SwingRays2b, were you able to get it to plot the indicator in a strategy as I thought you said it did not have any Plots?

                Thanks,
                Lee

                Comment


                  #9
                  Hello Lee,
                  I am referring to SwingRays2b indicator, it works fine with me. Highs / Lows are broken as expected.

                  I tried to add it thru strategy but it couldn't plot anything as there is no plot. Though you can get rid of the error you were facing by removing the if condition. It can stay there idle. I just wanted to confirm it so I did. Hope it helps!

                  Comment


                    #10
                    Hi s.kirna,

                    The indicator itself works fine for me as well. But I still cannot get it to work when I add it to a strategy. Can you share your strategy check where you added the SwingRays2b indicator?

                    Thanks,
                    Lee

                    Comment


                      #11
                      Here you get it.
                      SwingTest.zip

                      Comment


                        #12
                        Hi,

                        I tried the strategy provided and it produced no result which is the same as what I found using the strategy builder.

                        I guess my simple question is, can the SwingRays2b indicator be used to plot swingrays or provide swingrays to compare price against within the strategy?

                        Thank you,
                        Lee

                        Comment


                          #13
                          Hello Lee,
                          I already told you you can't do that as there is no parameter defined in the indicator. I also stated you can't get it plotted thru Strategy but the error you were getting can be avoided by skipping any condition / comparison as there is nothing that can be compared or checked. There no way to find Swing High or Low from this indicator as of now.
                          What I can try to help you is work on this indicator a bit to get the values of Swing High / Low so it can be used in Strategy. Again I am not sure if it will work as I haven't done it before, this weekend probably I'll give it some time. Hope that clarifies your doubts.

                          Comment


                            #14
                            Ok, thank you for that clarification.

                            Another thought, is there a way to use the standard Swing indicator to effectively do the same thing as the SwingRays... I will see what I can with my limited coding ability as well.

                            Regards,
                            Lee

                            Comment


                              #15
                              Hello Lee,
                              Yes, you can use Default Swing Indicator for Swing High & Low, you can use SwingHigh & SwingLow for this.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kawalecld, Today, 12:21 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post kawalecld  
                              Started by farzibopsu, Today, 11:52 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post farzibopsu  
                              Started by exjayess, Today, 11:04 AM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by robertlaub, Today, 11:11 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by sdauteuil, Today, 10:28 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post sdauteuil  
                              Working...
                              X