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

Short horizontal line (~5 bars ago)

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

    Short horizontal line (~5 bars ago)

    HI,
    Firstly I have to apologize for my bad english.

    I have a problem with rewrite script from NT7 to NT8. I need a short horizontal line like that on a picture.

    error code: CS0103



    Code:
     protected override void OnBarUpdate()
            {
                
                
                                barsBack                    = 5;       //  THERE IS PROBLEM
                                Color smaLineColor            = Color.Orange;
                
                if (BarsArray[0].BarsType.IsRemoveLastBarSupported)
                {
                    if (CurrentBar == 0)
                        Value[0] = Input[0];
                    else
                    {
                        double last = Value[1] * Math.Min(CurrentBar, Period);
    
                        if (CurrentBar >= Period)
                            Value[0] = (last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period);
                        else
                            Value[0] = ((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
                    }
                    
                        if(CurrentBar > barsBack)
                            Draw.Line("HorizontalSMA", 0, Value[0], barsBack ,Value[0], smaLineColor);
                }
                else
                {
                    if (IsFirstTickOfBar)
                        priorSum = sum;
    
                    sum = priorSum + Input[0] - (CurrentBar >= Period ? Input[Period] : 0);
                    Value[0] = sum / (CurrentBar < Period ? CurrentBar + 1 : Period);
                }
            }

    If you have any ideas, I would be grateful for help.

    #2
    Hello kamix265,

    Thank you for the post, and welcome to the NinjaTrader support forum.

    First, make sure that you have barsBack set up at the class level as a public property.

    At the class level:
    Code:
    [Range(1, int.MaxValue), NinjaScriptProperty]
    		[Display(ResourceType = typeof(Custom.Resource), Name = "barsBack", GroupName = "NinjaScriptParameters", Order = 0)]
    		public int barsBack
    		{ get; set; }
    The other thing you will need to change is the Color smaLineColor property. The Draw.Line method takes a Brush object in NinjaTrader 8 instead of a Color. Also, make sure to pass the NinjaScript owner.

    Code:
    Brush smaLineColor            = Brushes.Orange;
    
    ...
    
    Draw.Line(this, "HorizontalSMA", 0, Value[0], barsBack ,Value[0], smaLineColor);
    The constructor for NT8's Draw.Line() can be found below:


    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello kamix265,

      Thank you for the post, and welcome to the NinjaTrader support forum.

      First, make sure that you have barsBack set up at the class level as a public property.

      At the class level:
      Code:
      [Range(1, int.MaxValue), NinjaScriptProperty]
      [Display(ResourceType = typeof(Custom.Resource), Name = "barsBack", GroupName = "NinjaScriptParameters", Order = 0)]
      public int barsBack
      { get; set; }
      The other thing you will need to change is the Color smaLineColor property. The Draw.Line method takes a Brush object in NinjaTrader 8 instead of a Color. Also, make sure to pass the NinjaScript owner.

      Code:
      Brush smaLineColor = Brushes.Orange;
      
      ...
      
      Draw.Line(this, "HorizontalSMA", 0, Value[0], barsBack ,Value[0], smaLineColor);
      The constructor for NT8's Draw.Line() can be found below:


      Please let me know if I can assist further.
      Hi, when I use this code, I am not able to "drag and drop" the short HorizontalSMA line to another panel.... I have it as a HorizontalSMA (15-min) in panel 3, and want to move it to my (1-min) chart in Panel 1... The line shows as "locked"... when I unlock it, it still doesn't move to panel 1, and also when I change it in properties it doesn't move to any other panel.

      Dragging to another panel (with different time frame) works with the "regular" SMA indicator, but I can't get it to work with this modified version.

      **** If you could show me how to modify the HorizontalSMA so that it calculates on the 15-min time frame (inside the 1-min chart) that would be ideal!!! *****

      Please help! Thank you
      Attached Files
      Last edited by ldanenberg; 04-09-2024, 11:32 PM.

      Comment


        #4
        Hello ldanenberg,

        To show the drawing object in a different panel, you would need to use DrawOnPricePanel false, and assign the indicator Panel to the panel you would like the drawn object in.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea, this will not work since I have 2 price panels.... a 1-min chart, and a 15-min chart. I would like to draw the 15-min indicator, on the 1-min chart.

          Comment


            #6
            Since you don't seem to know how to solve this issue, could you please forward this question to another customer service rep who can help! Thanks

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Johnny Santiago, 10-11-2019, 09:21 AM
            95 responses
            6,193 views
            0 likes
            Last Post xiinteractive  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            2 responses
            11 views
            0 likes
            Last Post xiinteractive  
            Started by Irukandji, Today, 09:34 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by RubenCazorla, Today, 09:07 AM
            1 response
            5 views
            0 likes
            Last Post RubenCazorla  
            Started by TraderBCL, Today, 04:38 AM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X