Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Price Line

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

    #16
    Hello all,

    Firstly, I am very grateful for all your time, efforts and assistance.

    @NinjaTrader_Bertrand, below is my code:

    Code:
    public class KayYLinePrice : Indicator
        {
            #region Variables
            // Wizard generated variables
             private double lossPerUnit6 = 0.100; // Default setting for LossPerUnit6
             private double lossPerTrade6 = 10.00; // Default setting for LossPerTrade6
             // User defined variables (add any user defined variables below)
             private double yvalue = 0;
             private Font    textFont    = new Font("Arial", 10, FontStyle.Regular);
             private Color   txtColor;
             private int barsBack = 0; //default. Make this a property, and you can change it from the GUI
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Overlay                = false;
            }
    
            protected override void OnStartUp()
            {
                    
              foreach (IDrawObject draw in DrawObjects)
                 {
                   if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn)
                    
                     {    
                     IHorizontalLine hLine = (IHorizontalLine) draw;
                      if (hLine.Tag == "0")
                       {
                       yvalue = Math.Round(hLine.Y, 2);    // This is Price value    
                       }
                     }
                    
                 }
                
                
                double StopLossP, StopLossPATR, StopLossP2, StopLossPATR2, SharesMxS, SharesMxS2, SharesATR, SharesATR2, SharesPC, SharesPC2;
                
                
                StopLossP = yvalue - LossPerUnit6;
                StopLossPATR = Math.Round(yvalue - ATR(14)[0],2);
                SharesATR = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossPATR)),2);
                SharesPC = Math.Round(Math.Abs(LossPerTrade6/(yvalue - Low[barsBack])),2);
                SharesMxS = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossP)),2);
                
                StopLossP2 = yvalue + LossPerUnit6;
                StopLossPATR2 = Math.Round(yvalue + ATR(14)[0],2);
                SharesATR2 = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossPATR2)),2);
                SharesPC2 = Math.Round(Math.Abs(LossPerTrade6/(yvalue - High[barsBack])),2);
                SharesMxS2 = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossP2)),2);
                
                DrawTextFixed("Stop Values","EP " + yvalue + "  ATR " + Math.Round(ATR(14)[0],2) + "  BUY(MS/AS/PS) " + StopLossP + " [" + SharesMxS + "] / " + StopLossPATR + " [" + SharesATR + "] / " + Low[barsBack].ToString("0.00") + " [" + SharesPC + "]  " + "  SELL(MS/AS/PS) " + StopLossP2 + " [" + SharesMxS2 + "] / " + StopLossPATR2 + " [" + SharesATR2 + "] / " + High[barsBack].ToString("0.00") + " [" + SharesPC2 + "]" , TextPosition.BottomLeft, Color.White, textFont, Color.Transparent, Color.Transparent, 0);
                
                
                Print(Low[barsBack]);
                Print(High[barsBack]);
                Print(SharesPC);
                Print(SharesPC2);
                Print(yvalue);
                
                
            }
            
                
            
            protected override void OnBarUpdate()
            {
                
                if (CurrentBar < barsBack) return;
                
            }
    
            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public double LossPerUnit6
            {
                get { return lossPerUnit6; }
                set { lossPerUnit6 = Math.Max(0.001, value); }
            }
    
            [Description("")]
            [GridCategory("Parameters")]
            public double LossPerTrade6
            {
                get { return lossPerTrade6; }
                set { lossPerTrade6 = Math.Max(0.001, value); }
            }
            
            
            [Description("")]
            [GridCategory("Parameters")]
            [Gui.Design.DisplayName("Bar to reference")]
            public int BarsBack
            {
                get { return barsBack; }
                set { barsBack = Math.Max(0, value); }
            }
            
            
    
            #endregion
        }
    }
    @koganam, the error I am getting (at least in the Output Window) is the one I have already mentioned below.

    Many thanks
    Dan

    Comment


      #17
      Hello rabcnesbit,
      Thanks for the code.

      I could run the code without any issue. However let me say, if I scroll back to the start of the bar and press F5 (with barsAgo set to say 100) I am also getting the error which you are also witnessing.

      Please read this post to understand further why the error occurs http://ninjatrader.com/support/forum...ead.php?t=3170

      Please let me know if I can assist you any further.
      JoydeepNinjaTrader Customer Service

      Comment


        #18
        Originally posted by rabcnesbit View Post
        Hello all,

        Firstly, I am very grateful for all your time, efforts and assistance.

        @NinjaTrader_Bertrand, below is my code:

        Code:
        public class KayYLinePrice : Indicator
            {
                #region Variables
                // Wizard generated variables
                 private double lossPerUnit6 = 0.100; // Default setting for LossPerUnit6
                 private double lossPerTrade6 = 10.00; // Default setting for LossPerTrade6
                 // User defined variables (add any user defined variables below)
                 private double yvalue = 0;
                 private Font    textFont    = new Font("Arial", 10, FontStyle.Regular);
                 private Color   txtColor;
                 private int barsBack = 0; //default. Make this a property, and you can change it from the GUI
                #endregion
        
                /// <summary>
                /// This method is used to configure the indicator and is called once before any bar data is loaded.
                /// </summary>
                protected override void Initialize()
                {
                    Overlay                = false;
                }
        
                protected override void OnStartUp()
                {
                        
                  foreach (IDrawObject draw in DrawObjects)
                     {
                       if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn)
                        
                         {    
                         IHorizontalLine hLine = (IHorizontalLine) draw;
                          if (hLine.Tag == "0")
                           {
                           yvalue = Math.Round(hLine.Y, 2);    // This is Price value    
                           }
                         }
                        
                     }
                    
                    
                    double StopLossP, StopLossPATR, StopLossP2, StopLossPATR2, SharesMxS, SharesMxS2, SharesATR, SharesATR2, SharesPC, SharesPC2;
                    
                    
                    StopLossP = yvalue - LossPerUnit6;
                    StopLossPATR = Math.Round(yvalue - ATR(14)[0],2);
                    SharesATR = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossPATR)),2);
                    SharesPC = Math.Round(Math.Abs(LossPerTrade6/(yvalue - Low[barsBack])),2);
                    SharesMxS = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossP)),2);
                    
                    StopLossP2 = yvalue + LossPerUnit6;
                    StopLossPATR2 = Math.Round(yvalue + ATR(14)[0],2);
                    SharesATR2 = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossPATR2)),2);
                    SharesPC2 = Math.Round(Math.Abs(LossPerTrade6/(yvalue - High[barsBack])),2);
                    SharesMxS2 = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossP2)),2);
                    
                    DrawTextFixed("Stop Values","EP " + yvalue + "  ATR " + Math.Round(ATR(14)[0],2) + "  BUY(MS/AS/PS) " + StopLossP + " [" + SharesMxS + "] / " + StopLossPATR + " [" + SharesATR + "] / " + Low[barsBack].ToString("0.00") + " [" + SharesPC + "]  " + "  SELL(MS/AS/PS) " + StopLossP2 + " [" + SharesMxS2 + "] / " + StopLossPATR2 + " [" + SharesATR2 + "] / " + High[barsBack].ToString("0.00") + " [" + SharesPC2 + "]" , TextPosition.BottomLeft, Color.White, textFont, Color.Transparent, Color.Transparent, 0);
                    
                    
                    Print(Low[barsBack]);
                    Print(High[barsBack]);
                    Print(SharesPC);
                    Print(SharesPC2);
                    Print(yvalue);
                    
                    
                }
                
                    
                
                protected override void OnBarUpdate()
                {
                    
                    if (CurrentBar < barsBack) return;
                    
                }
        
                #region Properties
                [Description("")]
                [GridCategory("Parameters")]
                public double LossPerUnit6
                {
                    get { return lossPerUnit6; }
                    set { lossPerUnit6 = Math.Max(0.001, value); }
                }
        
                [Description("")]
                [GridCategory("Parameters")]
                public double LossPerTrade6
                {
                    get { return lossPerTrade6; }
                    set { lossPerTrade6 = Math.Max(0.001, value); }
                }
                
                
                [Description("")]
                [GridCategory("Parameters")]
                [Gui.Design.DisplayName("Bar to reference")]
                public int BarsBack
                {
                    get { return barsBack; }
                    set { barsBack = Math.Max(0, value); }
                }
                
                
        
                #endregion
            }
        }
        @koganam, the error I am getting (at least in the Output Window) is the one I have already mentioned below.

        Many thanks
        Dan
        Your DrawTextFixed() statement is in OnStartUp(), so the only possible value for any barSeries index is "0", as there is no possible previous bar at that time.

        Comment


          #19
          Originally posted by NinjaTrader_Joydeep View Post
          Hello rabcnesbit,
          Thanks for the code.

          I could run the code without any issue. However let me say, if I scroll back to the start of the bar and press F5 (with barsAgo set to say 100) I am also getting the error which you are also witnessing.

          Please read this post to understand further why the error occurs http://ninjatrader.com/support/forum...ead.php?t=3170

          Please let me know if I can assist you any further.
          Thanks for your reply NT_Joydeep, but mine was not even working with barsAgo set to 1!
          Anyway it's working now after moving the code from OnStartUp() to OnBarUpdate().

          Comment


            #20
            Originally posted by koganam View Post
            Your DrawTextFixed() statement is in OnStartUp(), so the only possible value for any barSeries index is "0", as there is no possible previous bar at that time.
            Thanks for this tip koganam, it now works fine after moving the code from OnStartUp() to OnBarUpdate(). Many thanks for your assistance and time, most grateful.

            Comment


              #21
              Hello rabcnesbit,
              Glad you could make the code work.

              Thanks to koganam too for his valuable input.

              Please let me know if I can assist you any further.
              JoydeepNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              579 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
              554 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