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

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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    92 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    6 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    158 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    7 views
    0 likes
    Last Post Belfortbucks  
    Started by zstheorist, Yesterday, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Working...
    X