is it possible to plot backwards?  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Ram
Posts: 90
Joined: 25 Nov 2014
Has thanked: 17 times
Been thanked: 5 times

is it possible to plot backwards?

Postby Ram » 30 Nov 2014

Hi All,

my goal is to have some calculation every 10 bars and based on the result to plot on those last 10 bars..

for example (if only it was that easy :))

Code: Select all

x = MyFunction()

for i = 0 to 9
me.plot1.set(MyBase.Bars.CurrentBar - i, x)
next i
is there any way to achieve something like that?

Thanks much in advance!
Best,
Ram

======================================
MultiCharts .NET64 for TWS Version 8.9 Release (Build 10291)
Using VB.Net

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: is it possible to plot backwards?

Postby JoshM » 30 Nov 2014

my goal is to have some calculation every 10 bars and based on the result to plot on those last 10 bars..

for example (if only it was that easy :))

Code: Select all

x = MyFunction()

for i = 0 to 9
me.plot1.set(MyBase.Bars.CurrentBar - i, x)
next i
is there any way to achieve something like that?
I don't think you need to correct for the current bar number (`Bars.CurrentBar`) when using the `barsAgo` argument from the plot's `Set()` method.

But I don't use VB .NET, so I cannot be sure. But to give you an idea, here's how it's done in C#:

Code: Select all

[SameAsSymbol(true)]
public class Snippet_Indicator : IndicatorObject
{
public Snippet_Indicator(object _ctx) : base(_ctx) { }

private IPlotObject myPlot;

protected override void Create()
{
myPlot = AddPlot(new PlotAttributes());
}

protected override void CalcBar()
{
if (Bars.LastBarOnChart)
{
for (int i = 0; i < 30; i++)
{
myPlot.Set(i, Bars.CloseValue);
}
}
}
}
Image
Attachments
scr.30-11-2014 17.42.13.png
(2.86 KiB) Downloaded 635 times

Ram
Posts: 90
Joined: 25 Nov 2014
Has thanked: 17 times
Been thanked: 5 times

Re: is it possible to plot backwards?

Postby Ram » 30 Nov 2014

@JoshM

many thanks for your reply!

by using "Bars.LastBarOnChart" i get to plot only last calculation:

Image

what I'm trying to achieve is for every n bars I do some calculation and then to plot back, should look something like this:
Image

once again, I appreciate your help very much!

BTW - i can convert your C# code successfully so any snippet can help :)

Ram
Posts: 90
Joined: 25 Nov 2014
Has thanked: 17 times
Been thanked: 5 times

Re: is it possible to plot backwards?  [SOLVED]

Postby Ram » 30 Nov 2014

got it! :) :)

Code: Select all


BarsCount = BarsCount + 1

if BarsCount = 15 Then
BarsCount = 0
' Get the highest high for the last 15 bars
highestHigh = Bars.High.Highest(15)

For i As Integer = 0 To 15
myPlot.Set(i, highestHigh)
Next

End If
MANY THANKS!!!!


Return to “MultiCharts .NET”