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

Arrow: Draw Only Once / doOnce

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

    Arrow: Draw Only Once / doOnce

    hi!
    try to build an indicator and therefore i'm using the strategy builder at first.
    the arrows i want to be drawn are drawn, but not only once, rather each time the signal is valid.
    as i just want to see the first valid signal being signed with an arrow, i tried what i found in forum here:



    but, i assume because it's NT7, it's not working for NT8...

    how do i have to do that in NT8?
    btw: it's not the case that the describe "doOnce" is not working in a strategy, but in an indicaotr, or?
    thank you very much!

    #2
    Hi Tradexxx, thanks for your post.

    It's happening because the Tag string is not unique. Append the CurrentBar value. In the drawing tool>Tag>Set>Add>Set>Misc>select Current Bar and click OK.

    This will append the CurrentBar value to the Tag string so that each tag is unique.

    Please let me know if I can assist any further.

    Chris L.NinjaTrader Customer Service

    Comment


      #3
      hi chris,
      thank you for your answer.

      the CurrentBar value is set.
      but the first error appears when i try to build : "private bool doOnce = true;"

      the indicator i'm using is an oscillator. but that shouldn't be a problem, or?

      attached you'll find a quick testcross strategy, drawing an arrow at each cross.
      when i try to add the expression "private bool doOnce = true;" the same error appears....

      thank you for your assistance
      Attached Files

      Comment


        #4
        Hi Tradexxx, thanks for your reply.

        So the issue is your getting multiple signals on a single bar but only one draw object is showing up (the last one)? You would need to append the Price onto the Tag to make the intra-bar draw objects unique in this case. The post you linked is making it such that only one draw object is made per bar.

        I look forward to hearing from you.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          hi chris,
          thanks for your replay.

          the point is i'm getting one arrow per bar.
          after the first arrow appears(the one i'd like to see), each following candle is also being painted with an arrow, as long as the condition 1 is valid.

          therefore i'd like to use "doOnce" to take the other arrows out, as long as another condition is going to end condition 1.

          pls. see attached screen.


          Attached Files

          Comment


            #6
            activation of line 58 in the file above, shows the error, i'm talking about

            Comment


              #7
              Hi Tradexxx, thanks for your reply.

              If you need to reset that boolean reset it based on the CurrentBar.
              Code:
              int PrevCurrentBar = 0;
              
              OnBarUpdate()
              {
                  if(PrevCurrentBar != CurrentBar)
                  {
                      PrevCurrentBar = CurrentBar
                      doOnce = false
                  }
              }
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                hi chris,
                unfortunately, it's not working....
                errors appear at
                - PrevCurrentBar = CurrentBar AND
                - doOnce = false;

                Comment


                  #9
                  Hi Tradexxx, thanks for your reply.

                  Could you post what you have so far?
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    hi chris!
                    first of all: thank you for your assistance!
                    perhaps the selected and posted example wasn't the best, because it's based on a "crossabove.." event (happening only once), while the strategy i'm using has the condition to be true unless it's invalid (causing arrows are painted again and again..)
                    so i have changed the example above from 'crossabove' to 'greater' to see better what's happening.

                    pls. see attached file.
                    i have added your suggestions, but it's not working like expected.
                    Attached Files
                    Last edited by Tradexxx; 02-19-2020, 03:12 AM.

                    Comment


                      #11
                      Hello Tradexxx,

                      Please consider the following:

                      Code:
                      private EMA EMA1;
                      private EMA EMA2;
                      private bool doOnce;
                      
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description                                    = @"Enter the description for your new custom Strategy here.";
                              Name                                        = "Testcross2";
                              Calculate                                    = Calculate.OnBarClose;                        
                          }
                          else if (State == State.DataLoaded)
                          {                
                              EMA1                = EMA(Close, 14);
                              EMA2                = EMA(Close, 21);
                              doOnce                = false;
                          }
                      }
                      
                      protected override void OnBarUpdate()            
                      {
                          if (EMA1[0] > EMA2[0] && !doOnce)
                          {
                              Draw.ArrowUp(this, @"Testcross2 Arrow up_1 " + Convert.ToString(CurrentBars[0]), false, 0, (Low[0] + (-3 * TickSize)) , Brushes.Lime);
                              doOnce = true;
                          }
                          else if (EMA1[0] <= EMA2[0])
                          {
                              doOnce = false;
                          }
                      }
                      1. doOnce is false
                      2. If doOnce is false and condition is met, Draw object and set doOnce to true. The condition will no longer become true because doOnce is true, and we are checking if it is false.
                      3. On a reversal condition, we set doOnce back to false so the logic above can become true again.

                      We look forward to assisting.
                      JimNinjaTrader Customer Service

                      Comment


                        #12
                        hi jim,
                        thank you very much for the explanation!!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by rdtdale, Today, 01:02 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post rdtdale
                        by rdtdale
                         
                        Started by alifarahani, Today, 09:40 AM
                        3 responses
                        15 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by RookieTrader, Today, 09:37 AM
                        4 responses
                        18 views
                        0 likes
                        Last Post RookieTrader  
                        Started by PaulMohn, Today, 12:36 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post PaulMohn  
                        Started by love2code2trade, 04-17-2024, 01:45 PM
                        4 responses
                        40 views
                        0 likes
                        Last Post love2code2trade  
                        Working...
                        X