Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I have a difficulty to make Price channel. Who can help me?

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

    I have a difficulty to make Price channel. Who can help me?

    Click image for larger version

Name:	image.png
Views:	126
Size:	21.6 KB
ID:	1281496​Black line is 50period Price Channel, Blue line is 20 Price channel in Thinksworm. I want to make this indicator. I am trying to create an indicator that connects the highest and lowest prices for each candle with lines, either 20 or 50 of them. It's called Price Channel in Thinkorswim. I don't have much coding experience, and I tried to create it, but I keep encountering errors. Is there anyone who can help me? ------------------------------------------------------------

    It is my code. But it does not work .
    region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    // This namespace holds indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class PriceChannel : Indicator
    {
    private double[] priorHigh20;
    private double[] priorLow20;
    private double[] priorHigh50;
    private double[] priorLow50;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Price Channel based on each bar's High and Low (20, 50)";
    Name = "PriceChannel";
    IsOverlay = true;
    IsSuspendedWhileInactive = true;

    AddPlot(Brushes.Orange, "Upper20");
    AddPlot(Brushes.Orange, "Lower20");
    AddPlot(Brushes.Blue, "Upper50");
    AddPlot(Brushes.Blue, "Lower50");
    }
    else if (State == State.DataLoaded)
    {
    priorHigh20 = new double[20];
    priorLow20 = new double[20];
    priorHigh50 = new double[50];
    priorLow50 = new double[50];
    }
    }

    protected override void OnBarUpdate()
    {
    UpdatePriorValues(High, Low, ref priorHigh20, ref priorLow20, 20);
    UpdatePriorValues(High, Low, ref priorHigh50, ref priorLow50, 50);

    Upper20[0] = priorHigh20[0];
    Lower20[0] = priorLow20[0];
    Upper50[0] = priorHigh50[0];
    Lower50[0] = priorLow50[0];
    }

    private void UpdatePriorValues(Series<double> highs, Series<double> lows, ref double[] priorHigh, ref double[] priorLow, int period)
    {
    double currentHigh = highs[0];
    double currentLow = lows[0];

    for (int i = 0; i < period - 1; i++)
    {
    priorHigh[i] = priorHigh[i + 1];
    priorLow[i] = priorLow[i + 1];
    }

    priorHigh[period - 1] = currentHigh;
    priorLow[period - 1] = currentLow;
    }

    region Properties
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Upper20
    {
    get { return Values[0]; }
    }

    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Lower20
    {
    get { return Values[1]; }
    }

    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Upper50
    {
    get { return Values[2]; }
    }

    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Lower50
    {
    get { return Values[3]; }
    }
    #endregion
    }
    }

    #2
    Hello Sarihwa,

    Thanks for your note.

    This seems to be a duplicate of another thread that I addressed at the following link:
    &quot;I am trying to create an indicator that connects the highest and lowest prices for each candle with lines, either 20 or 50 of them. It's called Price Channel in Thinkorswim. I don't have much coding experience, and I tried to create it, but I keep encountering errors. Is there anyone who can help me?&quot;&#8203; -------


    Please continue to respond via that thread with additional questions or concerns.

    Thank you for using NinjaTrader.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    560 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    325 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
    547 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X