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

trying to get a zero plot to store condition colors

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

    trying to get a zero plot to store condition colors

    i'm trying to get an indicator to plot it's zero line as a multicolor line based on conditions.
    but what keeps happening, i've tried several ways, i tried using Line/Lines terms, is that the whole line plots only one color instead of the line plotting a color dependent upon which condition is true for that bar, i.o.w. i want a line that plots the condition color at zero but stays that conditions color once another bar is begun...

    maybe i need to pass the conditions into a dataseries by storing a simple value for each condition then plot that condition?

    thanks for you time, i'm not a programmer by any means.... i haven't even finished the plots, i was going to continue with plot definitions and limits for 200-299.9999 and 300+, both for positive and negative....

    here's what i've done:

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line, "CCIcolor_Val")); //data holder for CCIcolor(Period)
    Add(new Plot(Color.FromKnownColor(KnownColor.Silver), PlotStyle.Line, "ZeroPlot")); //new ZeroPlot color changing line...
    Add(new Plot(Color.FromKnownColor(KnownColor.LimeGreen), PlotStyle.Line, "Positive"));
    Add(new Plot(Color.FromKnownColor(KnownColor.MediumTurquoi se), PlotStyle.Line, "MiddlePositive"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Negative"));
    Add(new Plot(Color.FromKnownColor(KnownColor.HotPink), PlotStyle.Line, "MiddleNegative"));


    Add(new Line(Color.FromKnownColor(KnownColor.Crimson), 200, "TwoHundredTop"));
    Add(new Line(Color.FromKnownColor(KnownColor.ForestGreen), -200, "TwoHundredBottom"));
    Add(new Line(Color.FromKnownColor(KnownColor.Green), Up, "Up"));
    Add(new Line(Color.FromKnownColor(KnownColor.Red), Down, "Down"));

    PaintPriceMarkers = true;

    Plots[0].Pen.Width = 1;
    Plots[2].Pen.Width = 4;
    Plots[4].Pen.Width = 4;
    Plots[3].Pen.Width = 2;
    Plots[5].Pen.Width = 2;
    Lines[0].Pen.Width = 1;
    Lines[1].Pen.Width = 4;

    Plots[2].Min = up; // set the plot threshold values
    Plots [2].Max = 199.9999;
    Plots[3].Max = up;
    Plots[3].Min = 0;
    Plots[4].Max = down;
    Plots[4].Min = -199.9999;
    Plots[5].Max = 0;
    Plots[5].Min = down;


    CalculateOnBarClose = false; // calculate on each tick data
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (CurrentBar < Period) return;

    double CCIcolor_Val = CCI(Period)[0];

    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.

    ZeroPlot.Set (0); // set ZeroPlot to 0 value ????
    Positive.Set(CCIcolor_Val); // or Positive.Set(CCI(Period)[0]);
    MiddlePositive.Set(CCIcolor_Val);
    Negative.Set(CCIcolor_Val);
    MiddleNegative.Set(CCIcolor_Val);


    if ( CCI(Period)[0] > CCI(Period)[1] && Close[0] >= Close[1] )
    {Plots[1].Pen = new Pen(Color.LimeGreen, 4);}
    else if ( CCI(Period)[0] < CCI(Period)[1] && Close[0] <= Close[1] )
    {Plots[1].Pen = new Pen(Color.Red, 4);}
    else if ( CCI(Period)[0] < CCI(Period)[1] && Close[0] > Close[1] )
    {Plots[1].Pen = new Pen(Color.Magenta, 4);}
    else if ( CCI(Period)[0] > CCI(Period)[1] && Close[0] < Close[1])
    {Plots[1].Pen = new Pen(Color.Yellow, 4);}
    else
    {Plots[1].Pen = new Pen(Color.Silver, 4);}



    }

    #region Properties

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries CCIcolor_Val
    {
    get { return Values[0]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries ZeroPlot
    {
    get { return Values[1]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Positive
    {
    get { return Values[2]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries MiddlePositive
    {
    get { return Values[3]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Negative
    {
    get { return Values[4]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries MiddleNegative
    {
    get { return Values[5]; }
    }

    [Description("CCIcolor period")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }
    [Description("setting for Up")]
    [GridCategory("Parameters")]
    public int Up
    {
    get { return up; }
    set { up = Math.Max(1, value); }
    }
    [Description("setting for Down")]
    [GridCategory("Parameters")]
    public int Down
    {
    get { return down; }
    set { down = Math.Max(1, value); }
    }
    #endregion

    #2
    actually, i think i just figured it out...
    i should have been using PlotColors instead and it works fine...

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by XXtrader, Today, 11:30 PM
    0 responses
    1 view
    0 likes
    Last Post XXtrader  
    Started by MarianApalaghiei, Today, 10:49 PM
    2 responses
    8 views
    0 likes
    Last Post MarianApalaghiei  
    Started by love2code2trade, Yesterday, 01:45 PM
    4 responses
    28 views
    0 likes
    Last Post love2code2trade  
    Started by funk10101, Today, 09:43 PM
    0 responses
    8 views
    0 likes
    Last Post funk10101  
    Started by pkefal, 04-11-2024, 07:39 AM
    11 responses
    37 views
    0 likes
    Last Post jeronymite  
    Working...
    X