Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

A boolean in OnBarUpdate() can not be called in OnRender()

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

    #16
    Originally posted by Stanfillirenfro View Post
    NinjaTrader_Emily, thanks for your reply.

    No, all bars should be colored:
    1. When the fast EMA crosses above the slow EMA, the bars should be colored, let's say in blue.
    2. When the fast EMA crosses below the slow EMA, the bars should have another color, let's say in red.


    1. Without boolean called in OnRender(), I have the rectangles drawn and on all bars. I am sure that the function OnRender() is not the problem itself, since it draws rectangles.
    2. But when the boolean is called in OnRender(), there is no rectagnles more drawn.

    No, I am expecting all bars to have rectangles drawn on them, and their colors change when the fast EMA crosses above/below the slow EMA.

    Thanks!
    If you only have conditions set to draw the rectangles when the bool is true, then that is the only time they will be drawn. If you want them to be a different color when the bool is false, you could use a different color. For example:
    Code:
     if(flagUp == true)
    {
    RenderTarget.FillRectangle(rec, flagUpColor);
    }
    else
    RenderTarget.FillRectangle(rec, flagFalseColor);​
    If you are still not getting the desired behavior, please describe how the script is behaving with a snippet of your current logic vs. how you would like the script to behave.

    Thanks again for your time and patience.

    Comment


      #17
      NinjaTrader_Emily, thanks for your reply.

      If you only have conditions set to draw the rectangles when the bool is true, then that is the only time they will be drawn. If you want them to be a different color when the bool is false, you could use a different color. For example:
      HTML Code:
      if(flagUp == true)
      {
        RenderTarget.FillRectangle(rec, flagUpColor);
      }
      else
      RenderTarget.FillRectangle(rec, flagFalseColor);​​
      I have this piece of code. In this case, all bars are flagFalseColor colored.

      Comment


        #18
        Hello Stanfillirenfro,

        Thanks for your reply.

        What are the results if you add a line at the end of OnBarUpdate() to force the bool to be true as follows:
        Code:
        flagUpColor = true;
        Then, compile the script and Reload NinjaScript on your chart (or remove then re-apply the indicator).

        I look forward to your reply.

        Comment


          #19
          Hello NinjaTrader_Emily!

          Thanks for your reply.

          When I add the condition of your post #18 at the end of OnBarUpdate(), all bars have the color flagUpColor.

          On my side, I haven't improved the script unfortunately. I am still failing to find a proper solution.
          Last edited by Stanfillirenfro; 01-09-2024, 09:44 AM.

          Comment


            #20
            Originally posted by Stanfillirenfro View Post
            Hello NinjaTrader_Emily!

            Thanks for your reply.

            When I add the condition of your post #18 and the end of OnBarUpdate(), all bars have the color flagUpColor.

            On my side, I haven't improved the script unfortunately. I am still failing to find a proper solution.
            It appears that OnRender() is calculating properly based on whether the bool is true or false. You may remove that line at the end of OnBarUpdate() that sets the bool to true, and now I suggest adding a Print() to determine whether the bool is true or false by the end of OnBarUpdate():
            Code:
            Print("flagUp is: " + flagUp);
            If you are only seeing that the bool flagUp is false each time at the end of OnBarUpdate(), then it would be expected that you see the flagFalseColor being rendered. Then you would need to debug why the bool is false each time, even if you expect it to be true. This may be done by adding additional prints or commenting out different lines of code to see which lines are changing the value of the bool unexpectedly. Additional debugging tips may be found at the following links:
            Please let us know if we may be of further assistance.

            Comment


              #21
              NinjaTrader_Emily,
              thanks for your help.

              After adding the line
              Code:
              Print("flagUp is: " + flagUp);
              at the end of OnBarUpdate(), I have false as well as true as shown on the attached file.
              Attached Files

              Comment


                #22
                If you scroll down to the very end of the output to the latest value, is it true or false? What color is rendered on the chart, and does that match the last value printed for the bool? If you wait and let the script run until the bool evaluates to the opposite value, do you see the color change? These are the kinds of questions you need to ask and test out to understand if your script is behaving as expected or not.

                Please let me know if I may be of further assistance.

                Comment


                  #23
                  NinjaTrader_Emily,

                  the lastest value printed is false and corresponds to the opposite. Also, the color rendered on the chart matches the last value printed for bool.

                  If you wait and let the script run until the bool evaluates to the opposite value, do you see the color change?
                  I am NOT seeing the color change unfortunately.

                  Comment


                    #24
                    "I am NOT seeing the color change unfortunately."

                    Did you see the bool change in the last printed value from true to false or from false to true? If not, you will need to wait for the bool to change in order to test and see if the color is changing when expected or not.

                    Comment


                      #25
                      NinjaTrader_Emily,

                      yes, I am seeing the changes.

                      When the bool changes in the last printed value from true to false or from false to true, the color of the rectangles on the chart flips too. But with this behaviour, I am still failing to point out what I am mistaking.

                      Any help, please?

                      Comment


                        #26
                        Originally posted by Stanfillirenfro View Post
                        NinjaTrader_Emily,

                        yes, I am seeing the changes.

                        When the bool changes in the last printed value from true to false or from false to true, the color of the rectangles on the chart flips too. But with this behaviour, I am still failing to point out what I am mistaking.

                        Any help, please?
                        What is your expected behavior? Based on your previous descriptions, my understanding is that you wanted all rectangles to be one color when one condition is met, or another color when the other condition is met. Whichever condition is met is what toggles the bool, and OnRender() is responding to the value of the bool in OnBarUpdate() and the colors are updating accordingly.

                        You previously mentioned the following:
                        No, all bars should be colored:
                        1. When the fast EMA crosses above the slow EMA, the bars should be colored, let's say in blue.
                        2. When the fast EMA crosses below the slow EMA, the bars should have another color, let's say in red.
                        Based on what you have stated, all bars are being colored either blue or red. If this is not what you expect, please describe what the discrepancy in desired behavior vs. exhibited behavior is.

                        1. Without boolean called in OnRender(), I have the rectangles drawn and on all bars. I am sure that the function OnRender() is not the problem itself, since it draws rectangles.
                        2. But when the boolean is called in OnRender(), there is no rectagnles more drawn.

                        No, I am expecting all bars to have rectangles drawn on them, and their colors change when the fast EMA crosses above/below the slow EMA.
                        Currently, all bars have rectangles drawn on them, no? If not, please describe what is happening that is not how you desire it to be happening. I may not understand what your question is at this point.

                        Thanks for your time and patience.

                        Comment


                          #27
                          What is your expected behavior? Based on your previous descriptions, my understanding is that you wanted all rectangles to be one color when one condition is met, or another color when the other condition is met.
                          Yes NinjaTrader_Emily, it is was I am expecting. let's imagine that the fast EMA crosses above the slower EMA over 10 bars. In this case, I want all these 10 bars to be colored. If the fast EMA crosses below the slower EMA from the bars 11 and over 20 bars, I want these bars to be colored in another color. The idea is to track the trend with this change of colors.

                          Based on what you have stated, all bars are being colored either blue or red. If this is not what you expect, please describe what the discrepancy in desired behavior vs. exhibited behavior is.
                          The discrepancy is huge! All the bars on the chart have the same color. Either when the trend is up or when the trend is down. This is not expected. The expectation is described above.

                          Currently, all bars have rectangles drawn on them, no?
                          Yes. This is a prouf for me that the problem is not within OnRender().

                          Comment


                            #28
                            Originally posted by Stanfillirenfro View Post

                            Yes NinjaTrader_Emily, it is was I am expecting. let's imagine that the fast EMA crosses above the slower EMA over 10 bars. In this case, I want all these 10 bars to be colored. If the fast EMA crosses below the slower EMA from the bars 11 and over 20 bars, I want these bars to be colored in another color. The idea is to track the trend with this change of colors.


                            The discrepancy is huge! All the bars on the chart have the same color. Either when the trend is up or when the trend is down. This is not expected. The expectation is described above.


                            Yes. This is a prouf for me that the problem is not within OnRender().
                            You will need to set up conditions that render certain rectangles with the up color and other rectangles with the down color. There are examples of indicators that render different colors for different bars based on certain conditions, such as the Heiken Ashi 8 indicator. This indicator is publicly available on our NinjaTrader Ecosystem website:
                            Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

                            Note — To import NinjaScripts you will need the original .zip file.

                            To Import:
                            1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
                            2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
                            3. Select the downloaded .zip file
                            4. NinjaTrader will then confirm if the import has been successful.

                            Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

                            Once installed, you may add the indicator to a chart by:
                            • Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK

                            Here is a short video demonstration of the import process:
                            Please let me know if I can be of further assistance.

                            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

                            Comment


                              #29
                              Hello NinjaTrader_Emily!

                              Many thanks for your help again. I have improved with the script thanks to the example you sent me in your last post, but I am still a step behind the goal (see picture please!).
                              I will update you when I will fix the last step. I just have to fit the rectangles on the bars. Since it is too late here, I will continue tomorrow.
                              I will let you know.

                              Thanks again
                              Attached Files

                              Comment


                                #30
                                Hello NinjaTrader_Emily!

                                I am still failing to complete this topic.
                                Let consider the bar with the arrows.

                                (1) Represents the Close. float val1 = chartScale.GetYByValue(Close.GetValueAt(index));
                                (2) Represents the Open. Float val2 = chartScale.GetYByValue(Open.GetValueAt(index));
                                (3) Represents the plotted indicator, beneath is the rectangle drawn in OnRender().
                                float yRec;
                                This rectangle should overlay the bar.
                                To draw a rectangle, we need the following function:
                                HTML Code:
                                SharpDX.RectangleF rect = new SharpDX.RectangleF(xStart, yStart, rectWidth, rectHeight);
                                My goal here is to find yStart.
                                This is what I have done with the unexpexted result (See picture).
                                HTML Code:
                                float space1 = val2 - yRec;
                                float space2 = val1 - val2;
                                yStart = val1- space1-space2;
                                ​
                                I am failing to have the rectangle overlayed on the bar.
                                I would appreciate it if you could point out where I am mistaking.

                                Best regards,


                                Attached Files
                                Last edited by Stanfillirenfro; 01-12-2024, 08:29 AM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                577 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                334 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