Draw a rectangle within an indicator  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
pdemontferrier
Posts: 20
Joined: 22 Jun 2017
Has thanked: 8 times
Been thanked: 2 times

Draw a rectangle within an indicator

Postby pdemontferrier » 04 Feb 2019

Hello,

I wish to draw a rectangle within an indicator.
I successfully draw rectangles within a price chart using the following lines :

private IRectangleObject PE_07_08,
PE_07_08 = DrwRectangle.Create(new ChartPoint(PE_07_08_START,PE_OPENING), new ChartPoint(PE_07_08_END,PE_CLOSING), false);

But when I try to draw a rectangle within an indicator, it appears in the price chart and not in the indicator chart.
Can someone let me know if it's possible, and if yes could you let me know what I'm doing wrong.

The indicator is set with these lines:

[SameAsSymbol(true)]
[RecoverDrawings(false)]

Thank you in advance for your contributions.

User avatar
ABC
Posts: 629
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 355 times
Contact:

Re: Draw a rectangle within an indicator

Postby ABC » 04 Feb 2019

Hi pdemontferrier,

your code sets the onSameSubchart flag to false i.e. the rectangle will be placed on the price chart. Setting it to true should display it on the indicator subchart.

Regards,

ABC

pdemontferrier
Posts: 20
Joined: 22 Jun 2017
Has thanked: 8 times
Been thanked: 2 times

Re: Draw a rectangle within an indicator

Postby pdemontferrier » 04 Feb 2019

Hi ABC,

Thank you very much for your contribution but it didn't fix my problem.
Even if I set:

[SameAsSymbol(false)]

The rectangle is still on the price chart.

Regards

User avatar
ABC
Posts: 629
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 355 times
Contact:

Re: Draw a rectangle within an indicator

Postby ABC » 04 Feb 2019

Hi pdemontferrier,

you would have to post your code, as the SameAsSymbol attribute is not related to your problem. The onSameSubchart flag is part of DrwRectangle.Create and in the snippet you posted you have set it to false.

Regards,

ABC
Hi ABC,

Thank you very much for your contribution but it didn't fix my problem.
Even if I set:

[SameAsSymbol(false)]

The rectangle is still on the price chart.

Regards

pdemontferrier
Posts: 20
Joined: 22 Jun 2017
Has thanked: 8 times
Been thanked: 2 times

Re: Draw a rectangle within an indicator

Postby pdemontferrier » 04 Feb 2019

Hi ABC,

Find here under the complete code :

using System;
using System.IO;
using System.Linq;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Collections.Generic;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
[UpdateOnEveryTickAttribute(true)]
[RecoverDrawings(false)]
[SameAsSymbol(false)]

public class RSI_BK_COLOR : IndicatorObject
{
public RSI_BK_COLOR(object ctx) : base(ctx)
{
BK_COLOR = true;
}

[Input]
public bool BK_COLOR { get; set; }

#region Private Variables, Functions, Orders & Flags
//RSI
private PowerLanguage.Function.RSI RSI_FUNC;
private VariableSeries<Double> RSI;
private int RSI_LEN_INP;

//Drawings
private IPlotObject Plot_RSI, Plot_RS1, Plot_RS2, Plot_RS3, Plot_RS4;
private double RSI_RS1, RSI_RS2, RSI_RS3, RSI_RS4;

private IRectangleObject BK_L1, BK_L2, BK_L3, BK_L4, BK_L5, BK_L6;
private DateTime BK_START, BK_FINISH;
private double BK_L1_BEGIN, BK_L2_BEGIN, BK_L3_BEGIN, BK_L4_BEGIN, BK_L5_BEGIN, BK_L6_BEGIN;
private double BK_L1_END, BK_L2_END, BK_L3_END, BK_L4_END, BK_L5_END, BK_L6_END;

#endregion

protected override void Create()
{
RSI_FUNC = new PowerLanguage.Function.RSI(this, 1);
RSI = new VariableSeries<Double>(this, 0, 1, true);

Plot_RSI = AddPlot(new PlotAttributes("RSI", 0, Color.DarkOrange, Color.Empty, 2, EPlotStyle.Solid, true));
Plot_RS1 = AddPlot(new PlotAttributes("RSI_RS1", 0, Color.Silver, Color.Empty, 0, EPlotStyle.Dash, true));
Plot_RS2 = AddPlot(new PlotAttributes("RSI_RS2", 0, Color.Silver, Color.Empty, 0, EPlotStyle.Dash, true));
Plot_RS3 = AddPlot(new PlotAttributes("RSI_RS3", 0, Color.Silver, Color.Empty, 0, EPlotStyle.Dash, true));
Plot_RS4 = AddPlot(new PlotAttributes("RSI_RS4", 0, Color.Silver, Color.Empty, 0, EPlotStyle.Dash, true));
}

protected override void StartCalc()
{
RSI_LEN_INP = 12;
RSI_FUNC.price = BarsOfData(1).Close;
RSI_FUNC.length = RSI_LEN_INP;
RSI_RS1 = 80;
RSI_RS2 = 60;
RSI_RS3 = 40;
RSI_RS4 = 20;
}

protected override void CalcBar()
{
RSI.Value = RSI_FUNC[0];
Plot_RSI.Set(0, RSI.Value);
Plot_RS1.Set(0, RSI_RS1);
Plot_RS2.Set(0, RSI_RS2);
Plot_RS3.Set(0, RSI_RS3);
Plot_RS4.Set(0, RSI_RS4);

BK_START = BarsOfData(1).Time[1];
BK_FINISH = BarsOfData(1).Time[0];


if (BarsOfData(1).Status == EBarState.Close)
{
//BK_L1 0-20
BK_L1 = DrwRectangle.Create(new ChartPoint(BK_START,0), new ChartPoint(BK_FINISH,20), false);
BK_L1.AnchorToBars = false;
BK_L1.FillColor = Color.DarkRed; //Color.DarkRed Color.FromArgb(0,225,0,0)
BK_L1.BorderStyle = ETLStyle.ToolSolid;
BK_L1.Color = Color.DarkRed;
BK_L1.Size = 0;
BK_L1.Locked = true;

}
}
}
}

Again thank you for your collaboration.

User avatar
ABC
Posts: 629
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 355 times
Contact:

Re: Draw a rectangle within an indicator  [SOLVED]

Postby ABC » 04 Feb 2019

Hi pdemontferrier,

check your usage of DrwRectangle.Create. The onSameSubchart flag is still set to false:

BK_L1 = DrwRectangle.Create(new ChartPoint(BK_START,0), new ChartPoint(BK_FINISH,20), false);

Regards,

ABC

pdemontferrier
Posts: 20
Joined: 22 Jun 2017
Has thanked: 8 times
Been thanked: 2 times

Re: Draw a rectangle within an indicator

Postby pdemontferrier » 05 Feb 2019

Hi ABC,
Thank you very much, you answer did fix all as I wanted.
Have a nice day.
Regards.

pdemontferrier
Posts: 20
Joined: 22 Jun 2017
Has thanked: 8 times
Been thanked: 2 times

Re: Draw a rectangle within an indicator

Postby pdemontferrier » 05 Feb 2019

Here attached the result.
Attachments
20190205144757.PNG
20190205144757.PNG (8.47 KiB) Viewed 418 times


Return to “MultiCharts .NET”