IPlotObject do not hold data as I expected  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
kenadian
Posts: 9
Joined: 14 Jan 2014
Has thanked: 5 times
Been thanked: 1 time

IPlotObject do not hold data as I expected

Postby kenadian » 18 Jan 2014

Hello,
I have problems with plotting. It seems that CalcBar() is called randomly, not in the sequential order of the bars in chart. Please see the code and the result below(sorry for its length).
It is the Multicharts's Pivot_High indicator code to which I added output.

One can see that CalcBar() is called in an apparently random order and even several times for the same for bar #:
12, 6, 12, 21, 2, 11, 29, 13, 21, 41, 46, 15, 20, 28, 36, 42

The display on graph is partial, showing only a few pivots, at the end (the blue dots).

If I remove the Output instructions then the pivots are correctly detected and displayed less the first two ones, at bar #5 and #8, which are not detected:
17,23,32,50,58,78,83,91,99,105 --- these are the pivots

I don't understand why the Output instructions perturb the calculations.

Another thing that it is not clear to me is related to Plot1.Set(*,*):
When the code is debugged in Visual Studio (with Output instructions removed), the
bars (int N=Bars.CurrentBar) that generate a pivot are

12, 18, 27, 45, 53, 73, 78, 86, 94, 100

and the pivots on the chart are the correct ones, above.
Thus Plot1.Set(rightstrength,value) provides the bar(pivot) in the future, not in the past, although rightstrength>0.
Besides, while rightstrength=3, the difference between a current bar and its corresponding pivot is 5: pivot = bar -5.

Could somebody explain these two things to me please ? Thank you.

I attached the chart image and the data I worked with.


Code: Select all

protected override void CalcBar(){
if ((m_pivothighvsbar1[0] // = m_pivothighvsbar1.Value = rightstrength
!= -1)){
Plot1.Set(rightstrength, // bars back
Bars.High[rightstrength]); // value(price) bars back
Alerts.Alert();

int N = Bars.CurrentBar;
Output.WriteLine("------------- Current Bar # "+N+"; Pivot detected at bar #"+ (N-rightstrength));
for (int i = 0; i < N; i++)
Output.WriteLine("plot.Values["+(N-i)+"]=" +Plot1.Values[i]);
}
else{
Plot1.Reset();
} // if
} // CalcBar
In PLeditor's output window I get :

------------- Current Bar # 12; Pivot detected at bar #9
plot.Values[12]=0
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=3694.19
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
------------- Current Bar # 6; Pivot detected at bar #3
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=3694.19
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 12; Pivot detected at bar #9
plot.Values[12]=0
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=3691.06
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=3694.19
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 21; Pivot detected at bar #18
plot.Values[21]=0
plot.Values[20]=0
plot.Values[19]=0
plot.Values[18]=3684.22
plot.Values[17]=0
plot.Values[16]=0
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=0
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=3691.06
plot.Values[8]=0
plot.Values[7]=0
------------- Current Bar # 2; Pivot detected at bar #-1
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 11; Pivot detected at bar #8
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=0
plot.Values[8]=3684.22
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=0
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 29; Pivot detected at bar #26
plot.Values[29]=0
plot.Values[28]=0
plot.Values[27]=0
plot.Values[26]=3798.76
plot.Values[25]=0
plot.Values[24]=0
plot.Values[23]=0
plot.Values[22]=0
plot.Values[21]=0
plot.Values[20]=0
plot.Values[19]=0
plot.Values[18]=0
plot.Values[17]=0
plot.Values[16]=0
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=0
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=0
plot.Values[8]=3684.22
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
------------- Current Bar # 13; Pivot detected at bar #10
plot.Values[13]=0
plot.Values[12]=0
plot.Values[11]=0
plot.Values[10]=3798.76
plot.Values[9]=0
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=0
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 21; Pivot detected at bar #18
plot.Values[21]=0
plot.Values[20]=0
plot.Values[19]=0
plot.Values[18]=3819.28
plot.Values[17]=0
plot.Values[16]=0
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=0
plot.Values[11]=0
plot.Values[10]=3798.76
plot.Values[9]=0
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=0
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 41; Pivot detected at bar #38
plot.Values[41]=0
plot.Values[40]=0
plot.Values[39]=0
plot.Values[38]=3966.71
plot.Values[37]=0
plot.Values[36]=0
plot.Values[35]=0
plot.Values[34]=0
plot.Values[33]=0
plot.Values[32]=0
plot.Values[31]=0
plot.Values[30]=0
plot.Values[29]=0
plot.Values[28]=0
plot.Values[27]=0
plot.Values[26]=0
plot.Values[25]=0
plot.Values[24]=0
plot.Values[23]=0
plot.Values[22]=0
plot.Values[21]=0
plot.Values[20]=0
plot.Values[19]=0
plot.Values[18]=3819.28
plot.Values[17]=0
plot.Values[16]=0
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=0
plot.Values[11]=0
plot.Values[10]=3798.76
plot.Values[9]=0
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=0
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 46; Pivot detected at bar #43
plot.Values[46]=0
plot.Values[45]=0
plot.Values[44]=0
plot.Values[43]=3955.97
plot.Values[42]=0
plot.Values[41]=0
plot.Values[40]=0
plot.Values[39]=0
plot.Values[38]=3966.71
plot.Values[37]=0
plot.Values[36]=0
plot.Values[35]=0
plot.Values[34]=0
plot.Values[33]=0
plot.Values[32]=0
plot.Values[31]=0
plot.Values[30]=0
plot.Values[29]=0
plot.Values[28]=0
plot.Values[27]=0
plot.Values[26]=0
plot.Values[25]=0
plot.Values[24]=0
plot.Values[23]=0
plot.Values[22]=0
plot.Values[21]=0
plot.Values[20]=0
plot.Values[19]=0
plot.Values[18]=3819.28
plot.Values[17]=0
plot.Values[16]=0
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=0
plot.Values[11]=0
plot.Values[10]=3798.76
plot.Values[9]=0
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
------------- Current Bar # 15; Pivot detected at bar #12
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=3966.71
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=0
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=0
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 20; Pivot detected at bar #17
plot.Values[20]=0
plot.Values[19]=0
plot.Values[18]=0
plot.Values[17]=3955.97
plot.Values[16]=0
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=3966.71
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=0
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=0
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 28; Pivot detected at bar #25
plot.Values[28]=0
plot.Values[27]=0
plot.Values[26]=0
plot.Values[25]=3994.97
plot.Values[24]=0
plot.Values[23]=0
plot.Values[22]=0
plot.Values[21]=0
plot.Values[20]=0
plot.Values[19]=0
plot.Values[18]=0
plot.Values[17]=3955.97
plot.Values[16]=0
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=3966.71
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=0
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=0
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 36; Pivot detected at bar #33
plot.Values[36]=0
plot.Values[35]=0
plot.Values[34]=0
plot.Values[33]=4069.7
plot.Values[32]=0
plot.Values[31]=0
plot.Values[30]=0
plot.Values[29]=0
plot.Values[28]=0
plot.Values[27]=0
plot.Values[26]=0
plot.Values[25]=3994.97
plot.Values[24]=0
plot.Values[23]=0
plot.Values[22]=0
plot.Values[21]=0
plot.Values[20]=0
plot.Values[19]=0
plot.Values[18]=0
plot.Values[17]=3955.97
plot.Values[16]=0
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=3966.71
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=0
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=0
plot.Values[2]=0
plot.Values[1]=0
------------- Current Bar # 42; Pivot detected at bar #39
plot.Values[42]=0
plot.Values[41]=0
plot.Values[40]=0
plot.Values[39]=4081.78
plot.Values[38]=0
plot.Values[37]=0
plot.Values[36]=0
plot.Values[35]=0
plot.Values[34]=0
plot.Values[33]=4069.7
plot.Values[32]=0
plot.Values[31]=0
plot.Values[30]=0
plot.Values[29]=0
plot.Values[28]=0
plot.Values[27]=0
plot.Values[26]=0
plot.Values[25]=3994.97
plot.Values[24]=0
plot.Values[23]=0
plot.Values[22]=0
plot.Values[21]=0
plot.Values[20]=0
plot.Values[19]=0
plot.Values[18]=0
plot.Values[17]=3955.97
plot.Values[16]=0
plot.Values[15]=0
plot.Values[14]=0
plot.Values[13]=0
plot.Values[12]=3966.71
plot.Values[11]=0
plot.Values[10]=0
plot.Values[9]=0
plot.Values[8]=0
plot.Values[7]=0
plot.Values[6]=0
plot.Values[5]=0
plot.Values[4]=0
plot.Values[3]=0
plot.Values[2]=0
plot.Values[1]=0
Attachments
yahoo.daily.120.csv.txt
(7.84 KiB) Downloaded 396 times
Partial.display.Pivot_High.PNG
(29.01 KiB) Downloaded 545 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: IPlotObject do not hold data as I expected  [SOLVED]

Postby Henry MultiСharts » 24 Jan 2014

Hello kenadian,

Please change the cycle code from

Code: Select all

for (int i = 0; i < N; i++)
to

Code: Select all

for (int i = 0; i < ExecInfo.MaxBarsBack; i++)

kenadian
Posts: 9
Joined: 14 Jan 2014
Has thanked: 5 times
Been thanked: 1 time

Re: IPlotObject do not hold data as I expected

Postby kenadian » 25 Jan 2014

Thank you, the use of ExecInfo.MaxBarsBack solved my problem.

For the beginners(I am one of them) that are interested in drawing text on chart, I would like to mention that ExecInfo.MaxBarsBack is also required for ITextObject.
The small enhancement, below, plots the bar # above the pivot. Please observe the use of MaxBarsBack at the x-coordinate of ChartPoint.

Code: Select all

protected override void CalcBar(){
if ((m_pivothighvsbar1[0]
!= -1)){
Plot1.Set(rightstrength, Bars.High[rightstrength]);

int xPivot = Bars.FullSymbolData.Current-rightstrength;
ChartPoint top = new ChartPoint(xPivot-ExecInfo.MaxBarsBack, Bars.High[rightstrength]);
/***** ITextObject textObj = DrwText.Create(top, Convert.ToString(xPivot-ExecInfo.MaxBarsBack), true); // incorrect *****/
ITextObject textObj = DrwText.Create(top, xPivot.ToString(), true); // correct
textObj.VStyle = ETextStyleV.Above;

Alerts.Alert();

int N = ExecInfo.MaxBarsBack;
Output.WriteLine("------------- Current Bar # "+(Bars.CurrentBarAbsolute()+1)+"; Pivot detected at bar #"+ ((Bars.CurrentBarAbsolute()+1)-rightstrength));
for (int i = 0; i < N; i++)
Output.WriteLine("plot.Values["+(N-i)+"]=" +Plot1.Values[i]);

}
else{
Plot1.Reset();
} // if
} // CalcBar()
Attachments
pivot_bar_num.PNG
(11.71 KiB) Downloaded 547 times


Return to “MultiCharts .NET”