Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

error Value of property

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

    error Value of property

    Hello, I have an indicator that does not give me problems in the compilation but it gives me an error when I uncheck the "Compra" variable, then it does nothing and throws me an error that I send you as a screenshot. It is related to the conditional (if else). If I just want it to make me
    "Draw.Line (this, @" Sup ", true, BarrAtras, Superior, BarrDel, Superior, Brushes.Red, DashStyleHelper.Dash, 2);" no problem but if I put the conditioner then it does nothing and throws me the error. I am sure it is something simple but due to my lack of programming knowledge I cannot make the indicator work correctly.

    Please if you can help me, thank you very much in advance.




    public class LinesMines : Indicator
    {
    private double Inferior;
    private double Superior;
    private double Cierre;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "LinesMines";
    Calculate = Calculate.OnEachTick;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    DisTick_A = 5;
    DisTick_B = 10;
    BarrAtras = -5;
    BarrDel = -30;
    Inferior = 1;
    Superior = 1;
    Cierre = 1;
    Compra = true;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    if (Compra)
    {
    RemoveDrawObjects();
    Superior = Close[0] + DisTick_A*TickSize;
    Inferior = Close[0] - DisTick_B*TickSize;
    Cierre = Close[0];
    Compra = true;

    Draw.Line(this, @"Inf", true, BarrAtras, Inferior, BarrDel, Inferior, Brushes.Red, DashStyleHelper.Dash, 2);

    else
    {
    RemoveDrawObjects();
    Superior = Close[0] + DisTick_B*TickSize;
    Inferior = Close[0] - DisTick_A*TickSize;
    Cierre = Close[0];
    Compra = false;


    Draw.Line(this, @"Sup", true, BarrAtras, Superior, BarrDel, Superior, Brushes.Red, DashStyleHelper.Dash, 2);

    }

    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, double.MaxValue)]
    [Display(Name="Compra", Description="Compra o Venta", Order=1, GroupName="Parameters")]
    public bool Compra
    { get; set; }
    Attached Files

    #2
    Hello punkiy2111,

    Thanks for your post.

    Even though you are declaring Compra as a public bool you have also specified the input to check for a range of [Range(1, double.MaxValue)] where the minimum is 1. When the bool is true it will have a value of 1, when false it will be 0 and thus outside the acceptable range.
    Reference: https://ninjatrader.com/support/help...eattribute.htm

    Please removed [Range(1, double.MaxValue)] as it is not needed for a bool type and then recompile and test for the issue.

    Comment


      #3
      Ohhh great !!! It works like a charm. One last question, how can I add a number to a line that is below the price at 10 ticks for example, how could it be placed in the middle of the line. I am sending you a capture. Thanks a lot.
      Attached Files

      Comment


        #4
        Hello punkiy2111,

        Thanks for your reply.

        How is the line drawn? In Ninjascript or manually?

        Is that how it would be as shown in your picture, ahead of the price action?


        Comment


          #5
          It is plotted like this in ninjascipt by the command + ticksize where is = 20. This line below the price marks it like this, but I would like to include the number 20 that corresponds to the distance of the price.

          Comment


            #6
            Hello punkiy2111,

            Thanks for your reply.

            You can use the Draw.Text() method to place the text where you wish.

            Reference: https://ninjatrader.com/support/help...?draw_text.htm

            Comment


              #7
              Ok, in protected override void I have a variable called "distanceticks" where "distanceticks" is a number that I can write for example 20. Then I want the line to appear and also the number 20 as in the capture I sent you ...
              How would the "drawtext" command be in this case ... thank you very much.

              Comment


                #8
                Hello punkiy2111,

                Thanks for your reply.

                Draw.Text() offers a number of method overloads.

                using the simplest one, you could use something like:

                // Draws text
                Draw.Text(this, "tag1", distanceticks.ToString(), 0, Low[0] - 20 * TickSize, Brushes.Magenta);

                This would draw 20 at 20 ticks below the low of the current bar.

                Comment


                  #9
                  Thank you, what I want is the same as in the capture that I sent you. This price line moves every tick above the price, this line is always moving. So what I want is that in this case the number 20 appears, two ticks below the price line and this number 20 also moves each tick like the line. What would the command be like? Thanks a lot.

                  Comment


                    #10
                    Hello punkiy2111,

                    Thanks for your reply.

                    I will assume that you know the value of the price line.
                    // Draws text
                    Draw.Text(this, "tag1", distanceticks.ToString(), 0, (your prie line value here) - 2 * TickSize, Brushes.Magenta);

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    650 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    370 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    109 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    574 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    577 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X