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

create a simple indicator

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

    create a simple indicator

    Dear support

    I am trying to create a simple indicator but I do not get a part.
    How could I make the indicator draw a line from, for example,the High of the candle when two SMA cross and draw the line until the price returns to that price,where it stops drawing.

    Many thanks.

    #2
    Welcome to the forums antoniogalaserra!

    You could use CrossAbove and CrossBelow to detect when your two SMA's cross and start counting how many bars ago that cross has happened. You can then use DrawLine() to draw from that High[BarsAgo] (Y coordinate) and BarsAgo (X coordinate) to the current bar and the same Y coordinate to draw your line. You will want to use the same drawing tag until you see a new cross which would indicate you want to draw a new line. (Unique drawing tags will create unique drawing objects, while reusing a tag will update that drawing object.)

    You would then need to check when the the price recurses back to High[BarsAgo]. I may suggest checking if the current bar's High and Low contain this price to determine when to use that bar as the lines endpoint.

    If you are new to NinjaScript and using Drawing Tools, I may suggest to start with the example within the Strategy Wizard documentation. I have also included documentation reference for using Draw.Line and for working with Price Series like Open High Low and Close.

    Strategy Wizard Action examples (See How to draw on a chart) - https://ninjatrader.com/support/help...gy_actions.htm

    DrawLine - https://ninjatrader.com/support/help...7/drawline.htm

    Working with Price Series - https://ninjatrader.com/support/help...rice_data2.htm

    Please let me know if i can be of further assistance.
    Last edited by NinjaTrader_Jim; 04-09-2019, 08:39 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello again

      Thank you very much for the information it has been very useful. However, I can not fix the part of endBarsAgo. In this example I put -10 bars but I do not know how to write to stop drawing when the price recurses back to High[BarsAgo].regardless of the number of bars that late

      example:

      if(CrossBellow(SMA(14), SMA (35),1))
      {
      DrawLine("My line" + CurrentBar,0, High[0] + 1* TickSize, -10, High[0] + 1 * TickSize, Color. Red);
      }

      Many thanks.

      Comment


        #4
        Hello antoniogalaserra,

        You will not know when the line recurses at the same moment the cross occurs. When you detect a cross, you know that the line is developing and you know the start points. At this point the line should be updated on each bar so that it continues the line from the start point to the current bar.

        I would consider an approach to set a bool when you detect a cross to begin developing your line. When the bool is true, the line should be drawn from the start point to the current bar. Also save the index so you know what to supply the Draw method on subsequent calls.

        When you notice that High[BarsAgo] is in between High[0] and Low[0], the current price has recursed, and you then know your endpoint. When this happens, you can update your line with the line start point and the last points needed for the endpoint, and set the bool to false so the logic does not update/draw the line again.

        Demo - https://drive.google.com/file/d/1Qx0...w?usp=drivesdk

        Please note that the logic provided is general context to model the behavior. The demonstration would not account for an instance where multiple crosses occur before the price is recursed. A List could be used to keep track of multiple crosses and to draw a line until an associated recursion is seen instead of only working with 1 line at a time.

        Our role in the support department is to outline some context for how something can be accomplished. These examples are intended to be educational and informative, but are not intended to provide a copy and paste solution for you.

        If you are interested in services to have this code written for you, we can have a representative of our EcoSystem reach out with more information on NinjaScript Consultants who would be happy to build this at you request.

        If you have any additional questions, please don't hesitate to ask.
        JimNinjaTrader Customer Service

        Comment


          #5
          Dear support

          Thank you very much for all the information you have given me, I am studying and practicing to improve my indicators.

          There is only one problem that I can not understand. The indicator must stop drawing when High [BarsAgo] (being barsAgo = 0) is in between High [0] and Low [0], however it does so in BarsAgo = -1 and not in 0.
          Thank you very much for the help. Great job.

          Comment


            #6
            Hello antoniogalaserra,

            High[BarsAgo] would be a reference to that specific bar's High value when we saw that the cross had occurred. The example condition in the demonstration shows a comparison with this historical bar to the current processing bar's High and Low. The counted BarsAgo index is from an integer that is reset to 0 when a cross occurs and accumulates after that cross occurs, it would not be -1.

            NinjaScripts by default will use CalculateOnBarClose = true, so we will only see OnBarUpdate iterate whenever a bar is closed. If you are looking to have the line drawn and updated for the developing bar, you can set CalculateOnBarClose to false. This may be what you are trying to accomplish if you are referring to the developing bar when you mention a BarsAgo index of -1.

            I look forward to being of any further assistance.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hello again
              I apologize because I did not have to explain well. I wanted to say that even if I put BarAgo=0 to stop painting the indicator, the indicator is doing it in barago -1. I attach a screen print to explain it better.

              thanks for your help

              Comment


                #8
                Hello antoniogalaserra,

                The CrossAbove/CrossBelow condition will become true after the cross is seen. If you would like to adjust when your BarsAgo indexing starts, you can adjust the script to start counting from a BarsAgo of 1, for example.

                Please note, that if you must have enough bars available for each data series you are referencing. It isn't as important in this case as we must see a bar below and then a bar above to create a cross over, but there are other cases that should be noted where you need to make sure that there are enough bars on the chart before referencing a data series. Please see the help guide page below for more information.



                Please let us know if we can be of further assistance.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Dear support

                  Thank you very much for all the information

                  Great job.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by agclub, Yesterday, 08:57 PM
                  2 responses
                  16 views
                  0 likes
                  Last Post agclub
                  by agclub
                   
                  Started by cre8able, 04-17-2024, 04:16 PM
                  6 responses
                  56 views
                  0 likes
                  Last Post cre8able  
                  Started by Mindset, 05-06-2023, 09:03 PM
                  13 responses
                  293 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by kaywai, 09-01-2023, 08:44 PM
                  4 responses
                  600 views
                  0 likes
                  Last Post joselube001  
                  Started by dpolyakov, 03-29-2024, 11:30 AM
                  3 responses
                  135 views
                  2 likes
                  Last Post sonia0101  
                  Working...
                  X