Multiple data streams question

Questions about MultiCharts and user contributed studies.
PD Quig
Posts: 186
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 65 times
Been thanked: 10 times

Multiple data streams question

Postby PD Quig » 24 Dec 2018

I have a two data stream chart with a test indicator that I have applied twice--one is based on data1 (3 point) and one is based on data2 (8 point). The indicator explicitly defines each variable as data1 or data2 and performs two calculations: 1) a simple EMA calc and 2) a paintbar calc that marks the data2 bars.

The EMA is correctly calculated by both instances, but the instance based on data1 does not produce correct paintbar bar marking results. This becomes an issue because in the ultimate application for this concept there are nearly 1500 lines of calculations all but 8 of which--the paintbar calcs--are based on data1. I'd like to avoid having to modify tons of code if there is a way to get the tiny piece that references data2 to work as I had expected it would.

Here's the test code:
Name : $Test_1
Description : Indicator that plots an ma and marks cons bars
Last Modified Date : 12/24/2018 --


MA_Length (89),
MA_Color (yellow),
Cons_Bar_Color (cyan);


MA (0, data1),
intrabarpersist Bar_Range (0.8, data2),
intrabarpersist Bar_Tail (0, data2),
intrabarpersist Body_Size (0, data2),
intrabarpersist Bar_Close ("", data2),
intrabarpersist Bar_Type ("", data2);

perform ma calculation and plot

MA = XAverage(close, MA_Length) data1;
Plot3(MA, "MA", MA_Color);

paintbar calculations done at the close of the 8 point bar

if barstatus(2) = 2 then begin

if close data2 < open data2 then Bar_Close = "Bear"
else Bar_Close = "Bull";

Bar_Tail = Bar_Range - absvalue(open - close) data2;

if close data2 = open data2 then begin

if close data2 > low data2 then Bar_Close = "Bull"
else Bar_Close = "Bear";

Body_Size = absvalue(open - close) data2;

if (Bar_Tail >= 0.5) or ((Bar_Tail = 0.4) and (Bar_Close <> Bar_Close[1]))
then Bar_Type = "Cons_Bar" else Bar_Type = "";

if Bar_Type = "Cons_Bar" then
PlotPaintBar(open data2, close data2, "Cons", Cons_Bar_Color);
Correct_results.png (62.49 KiB) Viewed 249 times
Incorrect_results.png (67.75 KiB) Viewed 249 times
I've attached the simple workspace. If anybody has any ideas I'd appreciate hearing them!

Thanks (and Merry Christmas / Happy Holidays)!

Test Multi datastreams.wsp
(153.63 KiB) Downloaded 97 times

User avatar
Anna MultiCharts
Posts: 405
Joined: 14 Jul 2017
Has thanked: 28 times
Been thanked: 102 times

Re: Multiple data streams question

Postby Anna MultiCharts » 01 Feb 2019

Hello, PD Quig!

This will require introducing debugging logic to your code. Please try outputting the calculation results for the conditions that are related to bar painting to be able to see why the code paints different number of bars in each case.

Return to “MultiCharts”