Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy only drawing one arrow

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

    Strategy only drawing one arrow

    Hi there,

    I have created a simple strategy with the Strategy Builder, and in the Actions I have it drawing an up arrow when the condition is met.
    I have found that it only draws a single arrow. I would have expected it would draw an arrow in each bar that the condition was met. I suspect this is because the drawing Tag is not unique and so it just updates the existing drawing every time.
    How can I get the strategy to draw an arrow every time the condition is met?

    I have attached an export of the test strategy I created with the Strategy Builder.

    Thanks for your time.



    Attached Files

    #2
    Hello codeowl,

    Thanks for your post.

    You are correct, the tag name needs to be unique to see all occurrences. By using the same tag name, only the latest occurrence would be shown. This is the default behavior with the intent to minimize draw objects.

    You can create unique tag names by adding Misc>CurrentBar to the tag name. Here is a short video that covers how to create unique tag names (and discusses draw object offsets): https://Paul-ninjaTrader.tinytake.co...A4M184NTkwOTg3

    Comment


      #3
      Paul,

      Thanks for taking the time to make the video mate, really great example. I had run into the issue with using Auto Scale without using a good Y value and all the prices went really flat in that section... I thought it was a bug and didn't work properly, so thanks for explaining that too!

      Really great support mate, much appreciated!!

      Regards,

      codeowl

      Comment


        #4
        Paul,

        Is it possible to collect timestamps When was a crossover before current position? How I can know timestamp when was crossover Above and Below? I need it for some analytics.

        Thanks a lot!

        Comment


          #5
          Hello sergey_z,

          Thanks for your post.

          One approach would be to create a private data series that contains the same number of bars as the data series of the chart. Each time a crossover occurs, as part of the action of the crossover you could write a value into the data series (such as +1 for crossabove and -1 for crossbelow (and perhaps 0 for no cross)). Then at any time, you can search that data series looking for the "events" of +/- 1 and when found the bars ago index can then provide the timestamp of the bar where the event occurred.

          Reference: https://ninjatrader.com/support/help.../?iseriest.htm

          Comment


            #6
            Ok, but for this idea my Strategy have to be online always for control crossovers.

            But I need to know timestamps Before strategy was started for example my Strategy was started now and crossover was yesterday or week ago. In this time my strategy was offline but now, when strategy online, I need to know all past crossovers. How I can do it?

            Comment


              #7
              Hello sergey_z,

              Thanks for your reply.

              You are missing an important understanding of how scripts work. Unless you have specifically programmed it not to, when you load the script, it will begin processing on the very first historical bar in the history of the chart and move in order to the current bar, processing all bars in between the first and current bar. The script will execute its code on each bar and in this example if a cross is determined it would write into the data series. When your strategy gets to the live data, it will have the full chart history to draw from.

              To further clarify, if your chart has 10 days of data and 73 crossovers have occurred historically in those 10 days, you would be able to access any of those times as they are within the history of the chart and upon loading your strategy that history has been accessed and processed. Obviously, if you only have 5 days of data you would not be able to access crossovers from 10 days ago and if that is your need then you would have to clarify.

              Comment


                #8
                Originally posted by NinjaTrader_PaulH View Post
                Hello sergey_z,

                Thanks for your post.

                One approach would be to create a private data series that contains the same number of bars as the data series of the chart. Each time a crossover occurs, as part of the action of the crossover you could write a value into the data series (such as +1 for crossabove and -1 for crossbelow (and perhaps 0 for no cross)). Then at any time, you can search that data series looking for the "events" of +/- 1 and when found the bars ago index can then provide the timestamp of the bar where the event occurred.

                Reference: https://ninjatrader.com/support/help.../?iseriest.htm
                Perfect, can you provide a simple example for this idea?

                Comment


                  #9
                  Hello sergey_z,

                  Thanks for your reply.

                  This educational reference will provide the concept: https://ninjatrader.com/support/help...taseries_o.htm of writing data to a private series.

                  Comment


                    #10
                    Thanks, I did it but in my private series I don`t have all moments of crossover.
                    My code is:
                    Code:
                    SMA_Cross_Series = new Series<int>(this, MaximumBarsLookBack.Infinite); // in Section =>  if (State == State.DataLoaded)
                    
                     OnBarUpdate():
                                if ( CrossAbove(SMA(Close,SMA1_period),SMA(Open,SMA2_period),1) ) 
                                    {
                                        int index = Bars.GetBar(Time[0]);                    
                                        SMA_Cross_Series[index] = 1; //to find later this crossover type
                                        DateTime Bar_time = Bars.GetTime(index);                   
                                    }
                    And later I will check SMA_Cross_Series in cycle - I see only zero values in each сell of Series.
                    Why? I need fill my private series with all moments of crossover on a chart for last 1000 bars like for picture below

                    Click image for larger version

Name:	108bd0d571.png
Views:	698
Size:	57.4 KB
ID:	1050516

                    Comment


                      #11
                      Hello sergey_z,

                      Thanks for your reply.

                      I would suggest doing this:

                      OnBarUpdate():

                      SMA_Cross_Series[0] = 0; // set everything to a zero value first

                      if ( CrossAbove(SMA(Close,SMA1_period),SMA(Open,SMA2_pe riod),1) )
                      {
                      SMA_Cross_Series[0] = 1; // only change when a cross is found.
                      }


                      Comment


                        #12
                        SMA_Cross_Series[0] its mean " Set value for index=0 in Series" ? its first (oldest) or last(newest) index in Series?

                        Comment


                          #13
                          Hello sergey_z,

                          Thanks for your reply.

                          As previously mentioned the code is processed a bar at a time starting from the historical (of the data series) beginning and the bar that is being processed would be identified as the current bar with a bars ago index of [0]. So when the cross occurs you would write +1 into the current bars ago storage location of the data series [0]. This educational link may help clarify that the indexes are a bars ago reference: https://ninjatrader.com/support/help...ice_series.htm

                          Comment


                            #14
                            I did it but I have zero in cells. How i can fix it?

                            Click image for larger version  Name:	7720785834.png Views:	1 Size:	86.0 KB ID:	1050531
                            Last edited by sergey_z; 03-06-2019, 06:15 PM.

                            Comment


                              #15
                              any ideas?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              50 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              126 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              69 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              42 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              46 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X