Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Newbie need help with own indicator

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

    Newbie need help with own indicator

    hello, I am a complete novice in programming and would like to create my own indicator. I have already tried different things, but I get no further and would be very happy if you could help me.

    The indicator should be able to do the following: It should mark me candles with at least 5 points in the chart with a different color. If a green or red candle appears in the chart or if the last candle (green or red) is at least 3 points long, this candle should be marked in the chart with another color like black. In addition, I can change the value of the candle in the indicator settings, which should then be displayed in the chart when the candle size appears.

    thanks in advance for the help

    #2
    Hi IntyRocket, thanks for posting. This can be done by doing some math on the PriceSeries arrays and using the BarBrush array. First, the condition "mark candles with at least 5 points" would look like this:

    if(High[0] - Low[0] >= 5)
    {
    BarBrush = Brushes.Black;
    }

    See the documentation on BarBrush and all the PriceSeries arrays here:




    Kind regards,
    -ChrisL

    Comment


      #3
      hello, thank you very much, I have managed it. I still have a question.

      I have put the HeikenAshi8 indicator and my own indicator over the chart. The 5 points candles are shown to me with my own indicator, but only the ones from the regular chart and not the ones the HeikenAshi8 indicator shows me. For example, in the regular chart the candle has 2 points and in HeikenAshi8 the candle has 5 points. Can I program my own indicator to show me the 5 points candles in the HeikenAshi8 indicator and not in the regular chart?

      Thanks

      Comment


        #4
        Hello IntyRocket,

        You can read the Heiken Ashi indicator values in your own indicator, or your can apply the indicator to a Heiken Ashi data series using the Heiken Ashi BarsType.

        Syntax for adding the indicator in NinjaScript and reading the Heiken Ashi values from it can be set up in the Strategy Builder and viewed with the View Code button.

        Comment


          #5
          Thank you again for your help. I have made it. Slowly i understand how this works . I still have two things in mind that I would like to optimize my indicator. I have tried many things, but still do not fully understand the programming connections. The marked candles are now displayed in HeikenAshi. I would like to program that now in such a way that if a candle was marked by the indicator that with the High of the candle automatically a line is to be drawn for example with 10 points higher. And when the next marked candle comes, then the line and the marked candle should be deleted at the last one and drawn in at the new one. Will this be too difficult for a beginner to program? I would be happy if you could give me some tips.

          thanks a lot

          Comment


            #6
            Hello IntyRocket,

            Thanks for your note.

            When a candle is 'marked' you could use the Draw.Line() method in the same condition set with the start price (startY) and end price (endY) values set to High[0] + 5 * TickSize to draw a line 5 ticks above the High of that 'marked' candle.

            Draw.Line(NinjaScriptBase owner, string tag, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush)

            If you want to move a drawing object to another value, you would re-use the Tag name of the drawing object.

            See this help guide page for more information about Draw.Line() and sample code: https://ninjatrader.com/support/help.../draw_line.htm

            Let us know if we may assist further.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              Hello, thanks for the tip. i got it working. In my indicator, the line is now drawn at a marked candle. In the long candle, the programming is ok. But on the short candle, the line is shown to me above the candle and not below. Where do I have there the thinking error? And if the line is drawn and the price runs for example 100 points in one direction then the chart is contracted until the next candle is marked. This is because of the horizontal line. How can I avoid that the chart is displayed normally?

              Many Thanks
              Last edited by IntyRocket; 04-27-2022, 07:50 AM.

              Comment


                #8
                Hello IntyRocket,

                Thanks for your note.

                I see that you are adding an offset (+ TakeProfit) to the price value when calling Draw.HorizontalLine().

                By calling '+ TakeProfit', you are adding an offset of TakeProfit to the value passed into Draw.HorizontalLine(). If you would like the line to be placed below the candle instead of above the candle, you would need to subtract the offset (- TakeProfit) from the candle's Low price. For example, Low[0] - 5 * TickSize.

                If you would like the horizontal line to be included in the Y-axis scale (price scale) on a chart, you would need to use the Draw.HorizontalLine() syntax that allows you to set isAutoScale to true.

                Draw.HorizontalLine(NinjaScriptBase owner, string tag, bool isAutoScale, double y, Brush brush, DashStyleHelper dashStyle, int width)

                See this help guide page for more information about Draw.HorizontalLine() and sample code: https://ninjatrader.com/support/help...zontalline.htm

                Let us know if we may assist further.
                Last edited by NinjaTrader_BrandonH; 04-27-2022, 08:14 AM.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  Hello, I have managed that my indicator now works and would now like to program a strategy with it. The strategy automatically sets an order when a candle is marked, but when the first order is set I get an error message and the strategy is automatically stopped. Unfortunately I do not know where the error lies and would need your help
                  Attached Files

                  Comment


                    #10
                    Hello intyRocket,

                    Thanks for your note.

                    The error message in the screenshot you shared indicates that the strategy tried to submit an order but there was not enough excess margin to submit the orders.

                    You would need to ensure that you have enough margin in the trading account for the strategy to place orders.

                    If trading a live account you will need to contact your broker in regard to this error message.

                    If trading the Sim101 account you could reset the balance of the Sim101 account using the steps below.

                    Please follow the instructions below to reset a simulation account in NinjaTrader 8.
                    • From the NinjaTrader Control Center window select the Accounts tab
                    • Right click on your simulation account and select 'Edit Account'
                    • Press the "Reset" button
                    Let us know if we may assist further.
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment


                      #11
                      okay thanks. if the strategy opens a long position for example at 15000 and then at 15010 the take profit is automatically set or executed and the stop loss would be at 14990. So TP 10 points and SL 10 points. To make this work I need all these commands for one side:
                      EnterLong()
                      ExitLong()
                      SetProfitTarget()
                      SetStopLoss

                      thank you.

                      Comment


                        #12
                        Hello IntyRocket,

                        Thanks for your note.

                        To clarify, are you asking if all four methods could be used in the same NinjaScript strategy without violating any internal order handling rules?

                        If so, yes you could use those methods in a NinjaScript strategy without violating any internal order handling rules since these rules do not apply to market orders, such as ExitLong() or ExitShort().

                        See this help guide page for more information about Managed Approach internal order handling rules: https://ninjatrader.com/support/help...antedPositions

                        Note in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services in our support. This is so that we can maintain a high level of service for all of our clients as well as our partners.

                        Let us know if we may assist further.
                        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                        Comment


                          #13
                          Thanks for the feedback.
                          Unfortunately I am not getting anywhere with my code and I have a thinking error somewhere. For example, if a candle has 7 points, the low of the candle should be the reference line. If the price rises by 10 points, then a short order should be executed with target back to the reference line.
                          With my code the order is not triggered, but I am sure that I have done this correctly. Would you please check the code? And how do I make it so that the order is only executed 2 times, for example?
                          I have included an image to show how I mean it. I would be grateful for some tips.

                          Last edited by IntyRocket; 05-18-2022, 11:23 AM.

                          Comment


                            #14
                            Hello IntyRocket,

                            Thanks for your note.

                            That said, I see in the code you shared that you are wanting to submit, for example, a "Take profit" order and are calling ExitLong(); which is a market order. To place a resting profit target order using Exit methods, you would need to use ExitLongLimit(). The same would need to be done for the Exit methods for your Short orders.

                            See this help guide page about ExitLongLimit(): https://ninjatrader.com/support/help...rlonglimit.htm
                            See this help guide page for more information about Managed Approach order methods: https://ninjatrader.com/support/help...d_approach.htm

                            You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. If you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request, please contact vendorsupport[AT]ninjatrader.com.

                            Let us know if we may assist further.
                            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            637 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            366 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            107 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            569 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            571 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X