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

Inserting Arrow on Price Panel

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

    Inserting Arrow on Price Panel

    Hi,

    I have an indicator that paints/brushes candles/OHLC either one of three different colors (green[1], red[2], blue[3]) upon close of the candle and based upon three specific conditions. I would like the indicator to draw an arrow upon the close of the current bar if the bar was brushed green [1] and the previous bar was red [2], and vice versa (red [2], green [1]). I don't want anything to happen if ([1],[3])([3],[1]), ([2],[3]), ([3],[2]).

    Any help would be greatly appreciated.

    Thank you!

    #2
    Hello TopGun13,

    Thanks for your post.

    You could add a custom data series to your script. A custom data series will provide a "slot" to store values in that would be sync'd to your charts bars and would allow you to use [n] bars ago references.

    So in your code when you paint the candle a specific color you would assign a value to the data series. For example:

    if (conditions to paint green)
    {
    BarBrush = Brushes.Green;
    myCustomSeries[0] = 1;
    }
    else if (conditions to paint red)
    BarBrush = Brushes.red;
    myCustomSeries[0] = 2;
    }
    else if (conditions to paint Blue)
    {
    BarBrush = Brushes.Blue;
    myCustomSeries[0] = 3;
    else
    {
    // no bar painted
    myCustomSeries[0] = 0; // or any other value you wish to help you know it was not painted
    }

    Then you can create your arrow drawing logic:

    if (myCustomseries[0] == 1 && myCustomSeries[1] == 2) // Current bar green, previous bar red.
    {
    // Draw arrow...
    }
    etc.etc.

    Please see the help guide here on creating a custom series: https://ninjatrader.com/support/help...8/?seriest.htm


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul! This helped a lot.

      I am also wondering if you could help me connect-the-dots (i.e. backbrush) between indicator signals. For example I am using the following to paint the background:

      if (Value[0] == 1 && Value[1] == 1 && Value[2] == 1 || (Value[0] == 4 && Value[1] == 1 && Value[2] == 1) || (Value[0] == 4 && Value[1] == 4))
      {
      BackBrushesAll[0] = Bullish;
      }

      if (Value[0] == -1 && Value[1] == -1 && Value[2] == -1 || (Value[0] == -4 && Value[1] == -1 && Value[2] == -1) || (Value[0] == -4 && Value[1] == -4))
      {
      BackBrushesAll[0] = Bearish;

      }

      As you can see I used your logic to create plots. Bullish and bearish plots have three different rules separated by "or". Although it is possible to generate all three bullish signals before a bearish signal is generated, I was wondering if I can paint the background bullish (or bearish) for the candles in-between a bull and then bear signal (or a bear and then bull signal).

      Any guidance would be greatly appreciated.

      Thank you!

      Comment


        #4
        I have attached a picture for further clarification.

        Thank you once again!

        Comment


          #5
          Hello TopGun13,

          Thanks for your replies.

          " I was wondering if I can paint the background bullish (or bearish) for the candles in-between a bull and then bear signal (or a bear and then bull signal)". If I understand correctly, once you have a signal you want to continue plotting the background that color until the opposite signal is generated? To accomplish that, remove the assigning colors from your code block and instead create/use a new bool variable that is set true or false by those conditions and then use the bool to paint the background.

          if (Value[0] == 1 && Value[1] == 1 && Value[2] == 1 || (Value[0] == 4 && Value[1] == 1 && Value[2] == 1) || (Value[0] == 4 && Value[1] == 4))
          {
          myBool = true;
          }
          else if (Value[0] == -1 && Value[1] == -1 && Value[2] == -1 || (Value[0] == -4 && Value[1] == -1 && Value[2] == -1) || (Value[0] == -4 && Value[1] == -4))
          {
          myBool = false;
          }

          //Paints the back ground on every bar and only changes when above conditions change the bool state.

          if (myBool)
          {
          BackBrushesAll[0] = Bullish;
          }
          else
          {
          BackBrushesAll[0] = Bearish;
          }
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Excellent! Worked perfectly.

            Thank you Paul!

            Best.

            Comment


              #7
              Hi Paul,

              Could you help me with the following logic:

              // Plotting Logic for within 5 candles

              // Bullish arrow
              if ((Value[0] == 5 && Value[1] == -5 && Value[2] == -5 && Value[3] == -5) || // 1 back
              (Value[0] == 5 && Value[1] < 5 && Value[1] > -5 && Value[2] == -5 && Value[3] == -5 && Value[4] == -5) || // 2 back
              (Value[0] == 5 && Value[1] < 5 && Value[1] > -5 && Value[2] < 5 && Value[2] > -5 && Value[3] == -5 && Value[4] == -5 && Value[5] == -5) || // 3 back
              (Value[0] == 5 && Value[1] < 5 && Value[1] > -5 && Value[2] < 5 && Value[2] > -5 && Value[3] < 5 && Value[3] > -5 && Value[4] == -5 && Value[5] == -5 && Value[6] == -5) || // 4 back
              (Value[0] == 5 && Value[1] < 5 && Value[1] > -5 && Value[2] < 5 && Value[2] > -5 && Value[3] < 5 && Value[3] > -5 && Value[4] < 5 && Value[4] > -5 && Value[5] == -5 && Value[6] == -5 && Value[7] == -5)) // 5 back
              {
              Draw.ArrowUp(this, @"GreenArrowUp"+CurrentBar, false, 0, (Low[0] + (-1 * TickSize)) , Brushes.Lime);
              }

              // Bearish arrow
              if ((Value[0] == -5 && Value[1] == 5 && Value[2] == 5 && Value[3] == 5) || // 1 back
              (Value[0] == -5 && Value[1] < 5 && Value[1] > -5 && Value[2] == 5 && Value[3] == 5 && Value[4] == 5) || // 2 back
              (Value[0] == -5 && Value[1] < 5 && Value[1] > -5 && Value[2] < 5 && Value[2] > -5 && Value[3] == 5 && Value[4] == 5 && Value[5] == 5) || // 3 back
              (Value[0] == -5 && Value[1] < 5 && Value[1] > -5 && Value[2] < 5 && Value[2] > -5 && Value[3] < 5 && Value[3] > -5 && Value[4] == 5 && Value[5] == 5 && Value[6] == 5) || // 4 back
              (Value[0] == -5 && Value[1] < 5 && Value[1] > -5 && Value[2] < 5 && Value[2] > -5 && Value[3] < 5 && Value[3] > -5 && Value[4] < 5 && Value[4] > -5 && Value[5] == 5 && Value[6] == 5 && Value[7] == 5)) // 5 back
              {
              Draw.ArrowDown(this, @"RedArrowDn"+CurrentBar, false, 0, (High[0] + (+1 * TickSize)) , Brushes.Red);
              }

              As we've previously discussed, there are values on candles ranging from +5 to -5 and I'd have to write code for every different kind of candle combination in between a -5 candle entry and a previous +5 candle trend. I've tried jumping from a (Value[0] == -5 && Value[5] == 5) to draw an up arrow but it will not work.

              Any help would be greatly appreciated.

              Thank you!

              Comment


                #8
                Hello TopGun13,

                Thanks for your reply.

                What I recommend would be print out the values you have on each bar along with the time of the bar, in that way you can scan the chart for where you expect the combinations to exist and then check the print statements (using the bar close time) to see why or why not you are or are not getting the arrows.

                You may need to then print the combinations out to swee why or why not they are true or false, examples:

                Print (Time[0]+" V0: "+Value[1]+" V1: "+Value[1]+" V2: "+Value[2] .... " V7: "+Value[7]); // print all the values

                Print (Time[0] +" 1st condition: "+(Value[0] == 5 && Value[1] == -5 && Value[2] == -5 && Value[3] == -5)); // Prints true or false
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Paul,

                  I've moved on from the above code and was able to determine an alternative. Thank you for your quick reply.

                  However, in using the OF Cumulative Delta indicator (Session), I have succeeded in plotting an EMA. Now I wish to paint the bars within the CD indicator and I can't seem to get it to work. This is using the same OnBarUpdate() as my original (basic) logic used above.

                  I have the following:

                  #region Variable
                  private OrderFlowCumulativeDelta OrderFlowCumulativeDelta1;
                  private EMA _ema;
                  private MACD _macd;
                  #endregion

                  protected override void OnStateChange()
                  {
                  if (State == State.SetDefaults)
                  {
                  Description = @"**";
                  Name = "CD";
                  Calculate = Calculate.OnBarClose;
                  IsOverlay = true;
                  DisplayInDataBox = true;
                  DrawOnPricePanel = true;
                  DrawHorizontalGridLines = true;
                  DrawVerticalGridLines = true;
                  PaintPriceMarkers = true;
                  ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Overlay;
                  IsSuspendedWhileInactive = true;
                  Bullish = Brushes.Lime;
                  Bearish = Brushes.Red;
                  Neutral = Brushes.DodgerBlue;
                  }
                  else if (State == State.Configure)
                  {
                  AddDataSeries(BarsPeriodType.Tick, 1);
                  }
                  else if (State == State.DataLoaded)
                  {
                  OrderFlowCumulativeDelta1= OrderFlowCumulativeDelta(Close, NinjaTrader.NinjaScript.Indicators.CumulativeDelta Type.BidAsk, NinjaTrader.NinjaScript.Indicators.CumulativeDelta Period.Session, 0);
                  _ema = EMA(OrderFlowCumulativeDelta1.DeltaClose, 13);
                  _macd = MACD(OrderFlowCumulativeDelta1.DeltaClose, 12, 26, 9);
                  }
                  }


                  Is there anything in particular I am missing? Is there additional code within OnBarUpdate() that I must also input to my original plotting(bar brushing) logic?

                  Thank you kindly in advance!

                  Comment


                    #10
                    Hello TopGun13,

                    Thanks for your reply.

                    Are you wanting your "CD" indicator to display the Cumulative Delta indicator?

                    Regardless, yes there is additional code needed to support the cumulative delta, please see the examples here: https://ninjatrader.com/support/help...ive_delta2.htm You would use the 2nd example and the part that would be needed is the part starting with If(BarsInProgress ==1) and using the name of your local indicator "OrderFlowCumulativeDelta1"
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Paul,

                      Again thank you for the quick reply. I was hoping to have my CD indicator paint the bars within the Cumulative Delta indicator in a session format.

                      I used this:

                      if (BarsInProgress == 0) within OnBarUpdate() and it worked, but painting the bars within the price panel.

                      However, using the BarsInProgress == 1 example under State==State.DataLoaded:

                      else if (BarsInProgress == 1)
                      {
                      OrderFlowCumulativeDelta1.Update(OrderFlowCumulati veDelta1.BarsArray[1].Count - 1, 1);
                      }


                      and nothing happens. Just a chart with CD showing but not my indicator.

                      Apologies for being less clear. Hoping this helps!

                      Kindest Regards,

                      Comment


                        #12
                        Hello TopGun13,

                        Thanks for your reply.

                        Regarding the help guide example, it looks like we need to improve that. The example I was referring to should show this code as being in OnBarUpdate() and not in State.DataLoaded.

                        Specifically:

                        if (BarsInProgress == 0)
                        {
                        // Print the close of the cumulative delta bar with a delta type of Bid Ask and with a Session period
                        Print("Delta Close: " + cumulativeDelta.DeltaClose[0]);
                        }
                        else if (BarsInProgress == 1)
                        {
                        // We have to update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync
                        cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
                        }


                        I'll ask our documentation team to make that more obvious.

                        Paul H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Barry Milan, Yesterday, 10:35 PM
                        5 responses
                        16 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by DanielSanMartin, Yesterday, 02:37 PM
                        2 responses
                        13 views
                        0 likes
                        Last Post DanielSanMartin  
                        Started by DJ888, 04-16-2024, 06:09 PM
                        4 responses
                        12 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by terofs, Today, 04:18 PM
                        0 responses
                        11 views
                        0 likes
                        Last Post terofs
                        by terofs
                         
                        Started by nandhumca, Today, 03:41 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post nandhumca  
                        Working...
                        X