Bug working with data1 and data2

Questions about MultiCharts and user contributed studies.
User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Bug working with data1 and data2

Postby CrazyNasdaq » 20 Jul 2010

I'd like to create a simple paintbar based on MACD.
I've inserted 2 data:
- data1 (300 contract bar)
- data2 - Hidden (3000 contract bar)

I'd like that MC plots the bars of data1 based on the study of data2.
The study is a simple macd.
Here is the code:

Code: Select all

inputs: FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ), UpTrend(cyan), DownTrend(magenta) ;
variables: var0( 0 ), var1( 0 ), var2( 0 ), color(0) ;

value1 = close of data2;
var0 = MACD( value1, FastLength, SlowLength ) ;
var1 = XAverage( var0, MACDLength ) ;
var2 = var0 - var1 ;

If var2 > 0 then color = UpTrend;
If var2 < 0 then color = DownTRend;

if Var2 > 0 then begin
PlotPaintbar(H,L,O,C, "Uptrend", color);
end else begin
PlotPaintbar(H,L,O,C, "DownTrend", color);
END;
but when I applied it, it plots and paints the bars of data1 but in a wrong way.
It paints bars as the study is based on a simple macd of data1.
If I change the properties and apply the study on data2, it plots correctly, but not each bar of data1 (second image)
Attachments
MACD data2 _second.png
(53.31 KiB) Downloaded 451 times
MACD data2.png
(50 KiB) Downloaded 442 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 20 Jul 2010

...try adding data2 behind everything

e.g.

var0 = MACD( value1, FastLength, SlowLength ) data2 ;

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Postby sptrader » 20 Jul 2010

I was told by a programmer that you should also initialize multi data streams like the following-
Vars: Var2(0,data2), var3(0,data3) etc., (not needed for data1)

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Postby CrazyNasdaq » 21 Jul 2010

Thanks for the suggestions, now the code and the paintbar looks better and works correctly.
Thanks

Code: Select all

inputs: FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ), UpTrend(cyan), DownTrend(magenta) ;
variables: var0( 0, data2 ), var1( 0, data2 ), var2( 0, data2 ), color(0) ;

value1 = close of data2;
var0 = MACD( value1, FastLength, SlowLength )data2 ;
var1 = XAverage( var0, MACDLength )data2 ;
var2 = var0 - var1 ;

If var2 of data2 > 0 then color = UpTrend;
If var2 of data2 < 0 then color = DownTRend;

if var2 of data2 > 0 then begin
PlotPaintbar(H,L,O,C, "Uptrend", color);
end else begin
PlotPaintbar(H,L,O,C, "DownTrend", color);
END;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 21 Jul 2010

good to hear it is working,
and thanks for sharing the code.

TJ

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Postby CrazyNasdaq » 22 Jul 2010

good to hear it is working,
and thanks for sharing the code.

TJ
You are Welcome !!!
and Thanks to you.

CrazyNasdaq


Return to “MultiCharts”