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

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.
    Emily C.NinjaTrader Customer Service

    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.
          Emily C.NinjaTrader Customer Service

          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 PaulMohn, Today, 05:00 AM
            0 responses
            5 views
            0 likes
            Last Post PaulMohn  
            Started by ZenCortexAuCost, Today, 04:24 AM
            0 responses
            5 views
            0 likes
            Last Post ZenCortexAuCost  
            Started by ZenCortexAuCost, Today, 04:22 AM
            0 responses
            2 views
            0 likes
            Last Post ZenCortexAuCost  
            Started by SantoshXX, Today, 03:09 AM
            0 responses
            16 views
            0 likes
            Last Post SantoshXX  
            Started by DanielTynera, Today, 01:14 AM
            0 responses
            3 views
            0 likes
            Last Post DanielTynera  
            Working...
            X