Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AnchorPrice Horizontal Line

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

    AnchorPrice Horizontal Line

    Hello, I have a strategy that draws by scripts 2 horizontal lines that I move manually. The problem I have is that if I enter the properties of the line and enter a number for example 4078.25 when taking the value with HorizontalLevel.Anchors.First().Price returns me 4078.24646739211 .
    Am I missing something? Is it a bug?
    Thanks in Advance!

    #2
    Hello PabloTrader,

    Thank you for your post.

    Are you using the Draw.HorizontalLine() method in your script? How are you checking the value of HorizontalLevel.Anchors.First().Price - is this via a Print() statement? What if you access the StartAnchor or EndAnchor properties for the horizontal line?



    I look forward to your reply.

    Comment


      #3
      Thanks for your answer, I paste part of the code here

      protected override void OnBarUpdate()
      {​


      if(Time[0].DayOfYear != DiaProcesado){
      DiaProcesado=Time[0].DayOfYear;
      Print("Dia Procesando: " + Time[0].Date);
      TradeActivado=false;
      Creado=false;
      }​

      if (!Creado
      && State == State.Realtime

      ){

      HorizontalStop = Draw.HorizontalLine(this, "Stop", Close[0] + 2, Brushes.Black);
      HorizontalStop.Stroke = new Stroke(Brushes.Red, DashStyleHelper.Dash, 1);
      HorizontalStop.IsLocked = false;

      HorizontalNivel = Draw.HorizontalLine(this, "Nivel", Close[0] + 4, Brushes.Black);
      HorizontalNivel.Stroke = new Stroke(Brushes.Yellow, DashStyleHelper.Dash, 1);
      HorizontalNivel.IsLocked = false;

      Creado=true;
      }

      //TRATAMIENTO DE VELAS 1 Minuto
      if (BarsInProgress == 0 && Creado) {

      PrecioNivel=HorizontalNivel.StartAnchor.Price;
      PrecioStop=HorizontalStop.StartAnchor.Price;

      Print("Nivel: " + PrecioNivel);
      Print("Stop: " + PrecioStop);

      }
      }

      After i run the script i move the horizontal lines via propertys to 4082,75 and 4080,75



      The result of this is

      Nivel: 4082,77028108802
      Stop: 4080,7524434747​

      Comment


        #4

        Another detail that I just noticed is that when moving the lines through the properties panel, the price is never updated again even if I move the lines manually. They remain in the last value they were before modifying them via the properties panel.​

        Comment


          #5
          Hello Pablo,

          Thank you for your reply.

          Since you are creating the object programmatically in your script and then adjusting it manually in the properties panel on the UI, the script will not automatically detect the changes you've made to the anchor(s). What you could do is loop through the DrawObjects collection to locate the object in question and access its properties that way after it has been manually adjusted. There is a snippet "Looping through the collection to find specific draw objects" on the help guide page here:


          Please let us know if we may be of further assistance.

          Comment


            #6
            Thanks for your help Emily. I paste the code here in case it helps someone else

            Code:
            foreach (Gui.NinjaScript.IChartObject thisObject in ChartPanel.ChartObjects){
                                if(thisObject is NinjaTrader.NinjaScript.DrawingTools.HorizontalLine){
                                    HL = thisObject as NinjaTrader.NinjaScript.DrawingTools.HorizontalLine;
                                    if (HL.Tag=="Nivel"){
                                        PrecioNivel=HL.StartAnchor.Price;
                                        Print("Nivel: " + PrecioNivel);
                                    }
                                    if (HL.Tag=="Stop"){
                                        PrecioStop=HL.StartAnchor.Price;
                                        Print("Stop: " + PrecioStop);
                                    }
                                }
            
                            }​

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X