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

newbie question

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

    newbie question

    for example i have this script,

    if (Open[0] < Low[period])
    {
    upwardbreak = Low[period];
    }

    if the condition is not met, how do i say "do nothing"? Or I don't have to write a script for "do nothing"?

    The reason why I ask this is because the script is suppose to "do something" when a certain condition is met. If you look at the attached chart, that green square, to me, is some number plucked from somewhere! BTW script is also attached.
    Attached Files
    Last edited by kaywai; 01-21-2010, 11:21 AM.

    #2
    kaywai, depends on your script and logic - if you do not change the value (condition not met) it would keep the assigned one.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      To do nothing, just don't code anything and it won't do anything.

      What your code is doing right now is setting variables to highs and lows. Then you are drawing the dots on every single bar. Even if no new high/low is set, it is still drawing the dots with the old values. You need to place them inside the if-statement if you don't want them to draw.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Josh, I understand what you are saying but not quite sure how to achieve that end? Would you mind helping? The script is attached to the initial posting

        Comment


          #5
          Like this -
          Code:
           
           
          if ((Open[0] < Low[period]))
             {
              upwardbreak = Low[period];
              DrawSquare("tag1", true, 0, upwardbreak, Color.Green);
             }
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Bertrand, It certainly looks a lot better now!

            Question I have now is how do i give instructions so that if either of the conditions is not met, the square doesn't print at all?

            Comment


              #7
              Use bool variables. Only when both bool variables are true do you draw the dot, otherwise don't draw.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                guys, would you mind giving some pointers on how to begin with bool? tried something along the lines of:-

                private BoolSeries myBoolSeries;
                myBoolSeries = new BoolSeries(this);

                myBoolSeries.Set(Open[0] < Low[period] ? true : false);

                got stuck after that...

                Comment


                  #9
                  kaywai,

                  No need to go to a BoolSeries. A simple bool would do.

                  In Variables region you can go:
                  Code:
                  private bool condition1 = false;
                  private bool condition2 = false;
                  Then in your OnBarUpdate():
                  Code:
                  if (Open[0] < Low[period])
                  {
                       condition1 = true;
                  }
                  else
                  {
                       condition1 = false;
                  }
                  
                  if (some other condition)
                  {
                       condition2 = true;
                  }
                  else
                  {
                       condition2 = false;
                  }
                  
                  if (condition1 == true && condition2 == true)
                  {
                       DrawSquare(...);
                       DrawSquare(the other square...);
                  }
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thank you very much for your help Josh!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by maybeimnotrader, Today, 05:46 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post maybeimnotrader  
                    Started by quantismo, Today, 05:13 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post quantismo  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    8 responses
                    166 views
                    0 likes
                    Last Post jeronymite  
                    Started by cre8able, Today, 04:22 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post cre8able  
                    Started by RichStudent, Today, 04:21 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post RichStudent  
                    Working...
                    X