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

BackBrushAll using On Price Change

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

    BackBrushAll using On Price Change

    I noticed a couple of similar posts, but they seem to be using calculate On Bar Close.

    In my indicator using calculate On Price Change, I want to see the BackBrush colour change as a signal bar is developing such that should the bar and indicator combination hesitate and maybe eventually fail instead of maturing into a steady state, the BackBrush would flash then disappear, reverting to the chart background. This way I would be able to see a "warning" signal before the trigger point is reached.

    Right now, when a signal bar is forming and the BackBrush paints, once triggered it simply stays set regardless of whether the signal bar completes or reverses.

    Just started on indicators, so hope there is a simple answer!

    #2
    Hello CaptHindsight,

    Welcome to the forums!

    BackBrush will have to be set back to null to revert it to the original color. If you would like it to trigger on a developing bar and then revert back to the original color without waiting for another price change, you could use a timer. (BackBrushes can also be used to set Back Brushes historically.)

    We have an example that demonstrates using a timer in our help guide and I'll also link a utility indicator that can be used to reference more uses of timers.

    SampleCustomEvent - https://ninjatrader.com/support/help...to_output_.htm

    Utility indicator that uses timers - https://ninjatrader.com/support/foru...hp?linkid=1099

    I'll include a link to BackBrush and BackBrushes in our help guide for the thread's reference as well.

    BackBrush - https://ninjatrader.com/support/help...?backbrush.htm

    BackBrushes - https://ninjatrader.com/support/help...ackbrushes.htm

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

    Comment


      #3
      BackBrushAll using On Price Change

      Thanks Jim for the info. I can see how using a timer function could help, but as I am using range bars tried another approach. Using If, Then, Else with BackBrush.Null allows the developing signal to set and reset according to changing conditions.

      As my indicator has four different signal combinations I used the Or || function too, however so far have to create a separate indicator for the short signals otherwise only the last condition displays, so once I define this issue clearly will make another post.

      Right now I am happy, as the pair of indicators provides exactly the outcome I was seeking.

      Comment


        #4
        BackBrushAll using On Price Change

        I now have an indicator for long signals, and another for shorts. They do exactly what I wanted, but I am trying to combine them into a single indicator and the result is that the short conditions only display.

        How do I combine the Longs and Shorts results so that they both display, keeping in mind my requirement the signals to display as they develop and reset should the setup fail.

        This code below is a simple example demonstrating my problem:

        protected override void OnBarUpdate()
        {
        //Add your custom indicator logic here.
        if (BarsInProgress != 0)
        return;
        if (CurrentBars[0] < 2)
        return;

        // Longs
        if (((IsRising(HMA1) == true)
        && (Close[1] < Open[1])
        && (Close[0] > Open[0]))
        || ((IsRising(HMA1) == true)
        && (Close[1] == Low[1])
        && (Close[0] > Open[0])))
        {
        BackBrushAll = Brushes.ForestGreen;
        }
        else
        {
        BackBrushAll = Brushes.Transparent;
        }

        // Shorts
        if (((IsFalling(HMA1) == true)
        && (Close[1] > Open[1])
        && (Close[0] < Open[0]))
        || ((IsFalling(HMA1) == true)
        && (Close[1] == High[1])
        && (Close[0] < Open[0])))
        {
        BackBrushAll = Brushes.Maroon;
        }
        else
        {
        BackBrushAll = Brushes.Transparent;
        }
        }

        Comment


          #5
          Hello CaptHindsight,

          If I understand your inquiry, you are trying to visualize the color changes for both long and short conditions should they overlap. I may suggest creating logic to use a different brush when both of these conditions are true.

          Using Calculate.OnPriceChange will allow the indicator to update as the bar is developing. I'll include a link to our documentation on the IsFirstTickOfBar bool which will be true when the first tick of a new bar comes in and signals the close of the previous bar. The bar that has just closed could be referenced as follows:

          Code:
          protected override void OnBarUpdate()
          {
          	if(IsFirstTickOfBar)
          	{
          		double BarThatJustClosed = Close[1]; // Same value as referencing Close[0] outside of IsFirstTickOfBar with Calculate set to OnBarClose.
          	}
          }
          IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

          Should you need to reset this color historically, you could use BackBrushesAll.

          BackBrushesAll - https://ninjatrader.com/support/help...brushesall.htm

          If there is anything else we can do to assist, please let us know.
          JimNinjaTrader Customer Service

          Comment


            #6
            BackBrushAll using On Price Change

            Hi Jim,

            Thanks for the post, but I am not trying to see any overlap as the conditions should prevent this.

            What I am trying to do, is to combine the 2 indicators I made into one. However, my attempts result in only the last set of conditions (Shorts in this case) being visible. The little example I gave shows a set for Longs and a set for Shorts, both providing dynamic BackBrushAll as each signal builds.

            The 2 separate indicators both work fine, I just want to now combine them into one indicator as all the parameter settings are the same for each.

            I feel there must be a way to use an OR statement somewhere (?) as the resulting signals will be either one or the other.

            Comment


              #7
              Hello CaptHindsight,

              Thanks for clarifying.

              Since the issue is a logical matter where you are seeing only the behavior for Shorts, the best way to approach the matter is by taking debugging steps and to add prints to better understand what is going on with the code as it is executing.

              It sounds like while the first block of code is becoming true, the conditions for the second block of code interfere with the behavior from the first block of code and you will not see effects from the first block.

              Some questions to ask yourself while debugging may be:
              • Are the conditions that control my first block of code becoming true?
              • Are the conditions that control my second block of code becoming true?
              • Is the second block of code becoming true after the first block of code?
              • Is my logic reaching else statements that are hiding the behavior from the previous block of code?

              Prints for the values that drive your conditions can be added outside of conditions so their value can be observed before the condition is evaluated. I may also suggest placing prints for Time[0] and CurrentBar so you can also observe which bar the logic is iterating on. Another tip would be to print an empty line with Print(""); so you may better visualize the prints in the output window.

              More tips on debugging can be found below.

              Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

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

              Comment


                #8
                All sorted out now.
                Here is the solution for the example indicator (for a Range Bar chart) where reversal signal bars in sympathy with an HMA slope trigger a BackBrushAll stripe only while the signal is valid. Should the bar not complete in that direction, then the signal resets:


                USING THE If / Else-If / Else STATEMENT

                protected override void OnBarUpdate()
                {
                //Add your custom indicator logic here.
                if (BarsInProgress != 0)
                return;
                if (CurrentBars[0] < 2)
                return;

                // Longs
                if (((IsRising(HMA1) == true)
                && (Close[1] < Open[1])
                && (Close[0] > Open[0]))
                || ((IsRising(HMA1) == true)
                && (Close[1] == Low[1])
                && (Close[0] > Open[0])))
                {
                BackBrushAll = Brushes.ForestGreen;
                }

                // Shorts
                else if (((IsFalling(HMA1) == true)
                && (Close[1] > Open[1])
                && (Close[0] < Open[0]))
                || ((IsFalling(HMA1) == true)
                && (Close[1] == High[1])
                && (Close[0] < Open[0])))
                {
                BackBrushAll = Brushes.Maroon;
                }
                else
                {
                BackBrushAll = Brushes.Transparent;
                }
                }

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by CortexZenUSA, Today, 12:53 AM
                0 responses
                1 view
                0 likes
                Last Post CortexZenUSA  
                Started by CortexZenUSA, Today, 12:46 AM
                0 responses
                1 view
                0 likes
                Last Post CortexZenUSA  
                Started by usazencortex, Today, 12:43 AM
                0 responses
                5 views
                0 likes
                Last Post usazencortex  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                168 responses
                2,266 views
                0 likes
                Last Post sidlercom80  
                Started by Barry Milan, Yesterday, 10:35 PM
                3 responses
                13 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X