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

Declaring multiple integers - error

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

    Declaring multiple integers - error

    For some reason, when I swap line 1 for line 3, my indicator stops plotting... No clue on my end, please help!

    int SwingLowBar = MRO(() => Low[0] == DonchianChannel1.Lower[0],1, 100);
    //****WANT TO NEXT LINE INSTEAD OF PREVIOUS LINE****
    //int SwingLowBar1 = MRO(() => Low[0] < DonchianChannel1.Lower[1],1, 100);
    int SwingHighBar = MRO(() => High[0] > DonchianChannel1.Upper[1],1, 100);​


    #2
    Hello jimmythesuit,

    Thank you for your inquiry.

    Do any errors regarding the strategy appear in the log tab of the Control Center? If so, what is the full text of the error?

    Are you ensuring you have at least 1 bar to look back to by checking the following at the top of OnBarUpdate:

    if(CurrentBar < 1)
    return;

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Yeah, got that... Is this how it's supposed to be?

      }

      protected override void OnBarUpdate()
      {

      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 1)
      return;

      Comment


        #4
        Another item, I don't know how to do this but, I am working on a zig zag / wave theory type of indicator... I can get it to display all the trend lines with " + currentbar", but then I get all the lines, and if I delete that I only get the most recent up trend line and one down trend line.

        Is there a way to have it plot only the most recent of each trend line? See image...

        Click image for larger version

Name:	image.png
Views:	137
Size:	73.5 KB
ID:	1215821

        Comment


          #5
          Oh, sorry and no errors in the messages.

          Comment


            #6
            Hello jimmythesuit,

            Thank you for your reply.

            We'd really need to test on our end - can you provide the indicator in question? You can export it from Tools > Export > NinjaScript Addon. Do not check the box to export as a compiled assembly or I will not be able to review the logic. Please attach the resulting .Zip file to your reply.

            Thanks in advance; I look forward to assisting you further.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hi Kate,

              Here you go! Let me know what you find out. Thanks!
              Attached Files

              Comment


                #8
                Hello jimmythesuit,

                Thank you for your reply.

                First, the issue with the code in your initial post is that you are commenting out int SwingLowBar and replacing it with a line with an int called SwingLowBar1 - but then you're still referencing SwingLowBar when assigning to WaveDOWN[0], which doesn't exist. If you're going to comment out that top line in favor of the 3rd, name the int in that line SwingLowBar instead of SwingLowBar1.

                As far as the last of each trend line, I'm not sure what you mean there - if you take out the Current Bar in the tag, it would draw the most recent up and most recent down trend lines only, is that not the intention?

                Thanks in advance; I look forward to assisting you further.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Kate,

                  Yes, I understand swapping all references to the different name - SwingLowBar1
                  Either way, when I change from "Low[0] == DonchianChannel1.Lower[0]" TO "Low[0] < DonchianChannel1.Lower[1]" it stops plotting everything.
                  Doesn't make sense to me because the inverse, "High[0] > DonchianChannel1.Upper[1]" works just fine.


                  In terms of the lines, you saw what it looks like. If I take away "+ currentbar" it only plots the last two which is great for the current waves, but I want it to plot previous lines from past swings as well.

                  Here's what I want it to look like.

                  Click image for larger version

Name:	image.png
Views:	85
Size:	31.3 KB
ID:	1215863


                  Here's what it looks like without "+ currentbar" | Only two lines plot.

                  ​​​​​​​Click image for larger version

Name:	image.png
Views:	81
Size:	12.4 KB
ID:	1215862

                  Attached Files

                  Comment


                    #10
                    Hello jimmythesuit,

                    Thank you for your note.

                    I'm attaching a revised version that is working for me on a 1 minute ES chart. As far as the lines go, the trick is to have the same tag while the line is drawing in one direction or another. So, when we initially draw it, we grab the current bar where it starts drawing, save that to a variable, and then use that variable in the tag instead so it's not constantly changing:

                    Code:
                    private bool DrawUp;
                    private bool DrawDown;
                    private int DrawTag;
                    
                    //in on bar update below:​
                    
                    //WAVE UP
                    if (High[0] == DonchianChannel1.Upper[0]
                    && DonchianChannel1.Upper[0] > DonchianChannel1.Upper[1])
                    
                    {
                    if (DrawUp == false)
                    {
                    DrawTag = CurrentBar;
                    DrawUp = true;
                    DrawDown = false;
                    }
                    if(DrawUp == true)
                    
                    Draw.Line(this, "Upwave" + DrawTag, 0, WaveUP[0], SwingLowBar, WaveDOWN[0], Brushes.Black);
                    
                    //continue plotting swing low until broken
                    //update swing high
                    }
                    //WAVE DOWN
                    if (Low[0] == DonchianChannel1.Lower[0]
                    && DonchianChannel1.Lower[0] < DonchianChannel1.Lower[1])
                    
                    {
                    
                    if (DrawDown == false)
                    {
                    DrawTag = CurrentBar;
                    DrawUp = false;
                    DrawDown = true;
                    }
                    if(DrawDown == true)
                    
                    Draw.Line(this, "Downwave" + DrawTag, 0, WaveDOWN[0], SwingHighBar, WaveUP[0], Brushes.Black);
                    //this is the swing low until broken or until new swing low
                    //continue plotting swing high until swing high is broken
                    
                    }​
                    Please let us know if we may be of further assistance to you.
                    Attached Files
                    Kate W.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Kate,

                      This is amazing, thanks!!!

                      One question, can I add multiple conditions for MRO? How would I do that?
                      I've tried to research, but I am not finding anything.

                      Here's what I have, but I want to add more than just the one condition....
                      E.g.
                      int SwingLowBar1 = MRO(() => Low[0] < DonchianChannel1.Lower[1],1, 100);


                      Thanks again!



                      Comment


                        #12
                        Hello jimmythesuit,

                        Thank you for your reply.

                        Yes, you can do that. Something like this would work:

                        int SwingLowBar1 = MRO(() => (Low[0] < DonchianChannel1.Lower[1] && Open[0] < Close[0]),1, 100);

                        I'd suggest wrapping the whole condition set in parenthesis to make it easier to read.

                        Please let us know if we may be of further assistance to you.
                        Kate W.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by DayTradingDEMON, Today, 09:28 AM
                        4 responses
                        21 views
                        0 likes
                        Last Post DayTradingDEMON  
                        Started by geddyisodin, Yesterday, 05:20 AM
                        9 responses
                        50 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by George21, Today, 10:07 AM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_ChristopherJ  
                        Started by Stanfillirenfro, Today, 07:23 AM
                        9 responses
                        24 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by navyguy06, Today, 09:28 AM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X