Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

We want to paint on the chart a candle that has achieved at least 5% from the previou

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

    We want to paint on the chart a candle that has achieved at least 5% from the previou

    Thank you for your reply.

    You can use a cell filter to change the color of cells that have a value greater than .05.
    https://ninjatrader.com/support/help...CellConditions



    To confirm, this Market analyzer column is what you are looking for?

    Yes it is.
    Thank you very much. It seems to have worked out well for that one.


    What are you trying to paint on the chart?
    This would require custom coding a new indicator to achieve.
    Are you interested in programming a new indicator in C#?
    If so, we can create a new thread in the Indicator Development section the forums.

    We want to paint on the chart a candle that has achieved at least 5% from the previous day's close or high.

    The attached screenshot will be from the TradeStation chart, but I think the attached screenshot is painted in light blue on the ones that have achieved 5% or more at the close, and I would like to do the same on the NinjaTreder platform.

    Yes, I am interested, but I am not very knowledgeable about programming and would appreciate your support.

    Thank you.
    Please create a thread.
    Attached Files

    #2
    Hello ラリー,

    Below I am providing a link to a forum post with helpful resources on getting started with programming C# and NinjaScript.


    To set the bar color assign brush to BarBrush.

    Below is a link to the help guide with sample code.


    For the previous session close, you could either use the PriorDayOHLC().PriorClose[0] in OnBarUpdate() or assign the marketDataUpdate.Price to a variable when the marketDataUpdate.MarketDataType is MarketDataType.LastClose in OnMarketData().





    Multiply the previous close by 1.05 to add 5%. Multiple the the previous close by .95 to subtract 5%.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry for the delay in replying to your message.

      I wrote PriorClose[0] in OnBarUpdate(), but as you can see in the attached image, I get an "Only assign, call, increment, decrement, wait, and new object expressions are allowed as statements" error.


      Multiply the previous close by 1.05 to add 5%. Multiple the the previous close by .95 to subtract 5%.
      In which line of code should they be written? Also, I don't know how to describe them in the code.
      Attached Files

      Comment


        #4
        Hello ラリー ,

        Line 54 does not have any assignment or method called..

        What are you trying to do with this line of code?

        Are you trying to print the value?

        Print(PriorDayOHLC().PriorClose[0]);

        The above is a method call. This is calling the method Print().

        Are you trying to assign the value of this to a variable and multiply this by 1.05?

        private double myPriceVariable;

        myPriceVariable = PriorDayOHLC().PriorClose[0] * 1.05;

        The above is a variable assignment. We are assigning a calculated value of the prior close multiplied by 1.05.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your reply.

          What are you trying to do with this line of code?

          Are you trying to print the value?​
          In post 2, you mentioned "You can also use PriorDayOHLC() at the end of the previous session, either by specifying PriorClose[0] in OnBarUpdate()," so I was thinking that on line 54, you would write PriorDayOHLC() .PriorClose[0 ]; I thought you were going to make the statement.

          Are you trying to assign the value of this to a variable and multiply this by 1.05?
          I think I am that way.
          So, I wrote the following code on line 54
          The name 'myPrice Variable' does not exist in the current context. I get an error message saying

          myPriceVariable = PriorDayOHLC().PriorClose[0] * 1.05;​

          Attached Files

          Comment


            #6
            Hello ラリー,

            A variable has to be declared to exist. Please watch the 'NinjaScript Editor 401' training video from the forum post I have linked you which covers this.

            private double myPriceVariable;
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you for your reply.

              The error is resolved, but when applied to a chart, the candlesticks are not colored.​
              Attached Files

              Comment


                #8
                Hello ラリー,

                To set the bar color assign brush to BarBrush.

                Below is a link to the help guide with sample code.
                https://ninjatrader.com/support/help...8/barbrush.htm

                The condition would be if the Close[0] is greater than the prior close multiplied by 1.05, and the action block would be setting the BarBrush to the brush of your choice.

                If you are not familiar with if statements and you have not read the information from the link I provided you, below is a direct link to dot net perls on if statements.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you for your reply.

                  I tried the sample example (SMA) in the link you sent and it was colored.
                  Then, I added the if statement code to line 64 to add color when the close of the day is 5% higher than the close of the previous day, but I could not add color.​
                  Attached Files

                  Comment


                    #10
                    Hello ラリー,

                    The condition you have is if the Close[0] of the current bar is greater than the Close[1] of the previous bar, then set the bar color to yellow.

                    I would expect this to color bars yellow where the close is greater than the previous bar. The name of the script appears to be Mychartbrush.

                    Add Mychartbrush to a chart and a new screenshot of a chart that has the indicator you are building on it.

                    Where you have mentioned:
                    Code:
                    added the if statement code to line 64 to add color when the close of the day is 5% higher than the close of the previous day
                    I am not seeing this in the code.

                    I am seeing myPriceVariable is assigned a value of the prior close multiplied by 1.05, but this is not compared in any conditions.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you for your reply.

                      I removed the if statement on line 64 and was able to paint yellow on all legs except the last leg of the day, but I only want to color the legs of the day that closed above 5%.
                      How can I do this?​
                      Attached Files

                      Comment


                        #12
                        Hello ラリー,

                        So I understand correctly, you want to see if the bar's Close price is greater than your variable for "1.05 times the previous close?"

                        You would then use the variable in the if statement:

                        if (Close[0] > myPriceVariable)
                        {
                        // Action here
                        }

                        Comment


                          #13
                          Thank you for your reply.

                          So I understand correctly, you want to see if the bar's Close price is greater than your variable for "1.05 times the previous close?"
                          Yes, it is.

                          You would then use the variable in the if statement:
                          I added the code as shown in the image from line 70 to line 73 and ran it, but there seems to be no change on the chart.
                          Is my addition of the code from line 70 to 73 incorrect?​
                          Attached Files

                          Comment


                            #14
                            Hello ラリー,

                            OnBarUpdate will be processed once we are updating a bar (either on each tick, on price change, or on bar closures.)

                            Your code is then processed line by line and each programmed action is taken in that order.

                            To understand why you are getting the result you are getting, you will need to understand the code written, and I would suggest reading reach line inside OnBarUpdate to understand each line's function, and the sequence in which each action is taken.

                            Reading each line aloud can also help to understand the flow of code execution, and exactly why your code produces that result.

                            Comment


                              #15
                              Thank you for your reply.

                              To understand why you are getting the result you are getting, you will need to understand the code written, and I would suggest reading reach line inside OnBarUpdate to understand each line's function, and the sequence in which each action is taken.

                              Reading each line aloud can also help to understand the flow of code execution, and exactly why your code produces that result.
                              Thank you for your advice.

                              I read the code aloud to understand it, and in the latest image, line 60 specifies that the next day's close ended 5% or more above the previous day's close, line 62 assigns BraBrushes.Yellow; to the BraBrush= variable, and for lines 70 through 73, if I am aware that if the closing price of the day ends 5% or more higher than the closing price of the previous day, then the yellow color is applied, is that correct?

                              Also, I don't understand why the codes on lines 64 and 68 need to be written.


                              I also found this post very similar to what I wanted to do, so I modified the code to be closer to what I wanted to achieve, using this code and Jim's instructions as a reference.
                              However, I was not able to add color to the last end date. How can I make the last end date also be included in the calculation?

                              http://ninjatrader.com/support/forum...24#post1215824
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              574 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              333 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X