Plot Paint Bar Issue  [SOLVED]

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

Plot Paint Bar Issue

Postby PD Quig » 03 Mar 2013

I am trying to create a simple paint bar study for a moving average filter. When the three EMAs (13, 34, 255) are stacked in the proper order for a long entry (shorter EMAs above longer EMAs), I want the bar to be painted BLUE. For some reason not obvious to me all the bars get painted blue whether all the criteria are met or not.

I have messed with this for more than an hour now, printing out the bar-by-bar data points, trying various different approaches, but I must be doing something fundamentally wrong. I would appreciate another set of eyes looking at this:


//*****************************************************************************
// inputs and variables
//*****************************************************************************

inputs:
MA_1_Length (13),
MA_2_Length (34),
MA_3_Length (255),
Color_Up (blue);

variables:
MA_1 (0),
MA_2 (0),
MA_3 (0),
MA_Config_Long (false),
MA_3_Rising (false);


//*****************************************************************************
// perform calculations
//*****************************************************************************

// calculate MAs

MA_1 = XAverage(Close, MA_1_Length);
MA_2 = XAverage(Close, MA_2_Length);
MA_3 = XAverage(Close, MA_3_Length);


// filter for long setups

if MA_1 > MA_2 and MA_2 > MA_3 then MA_Config_Long = true; // shorter moving averages are stacked above longer moving averages

if MA_3 > MA_3[5] and MA_3 > MA_3[10] then MA_3_Rising = true; // longest MA is rising over both five and ten periods ago

if MA_Config_Long and MA_3_Rising then
PlotPaintBar(High,Low,Open,Close, "SULong", Color_Up); // both criteria are met so plot paint bars
Attachments
2013-03-03_1807.png
(50.68 KiB) Downloaded 489 times
2013-03-03_1753.png
(31.14 KiB) Downloaded 480 times

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

Re: Plot Paint Bar Issue  [SOLVED]

Postby TJ » 03 Mar 2013

I am trying to create a simple paint bar study for a moving average filter. When the three EMAs (13, 34, 255) are stacked in the proper order for a long entry (shorter EMAs above longer EMAs), I want the bar to be painted BLUE. For some reason not obvious to me all the bars get painted blue whether all the criteria are met or not.

I have messed with this for more than an hour now, printing out the bar-by-bar data points, trying various different approaches, but I must be doing something fundamentally wrong. I would appreciate another set of eyes looking at this:


//*****************************************************************************
// inputs and variables
//*****************************************************************************

inputs:
MA_1_Length (13),
MA_2_Length (34),
MA_3_Length (255),
Color_Up (blue);

variables:
MA_1 (0),
MA_2 (0),
MA_3 (0),
MA_Config_Long (false),
MA_3_Rising (false);


//*****************************************************************************
// perform calculations
//*****************************************************************************

// calculate MAs

MA_1 = XAverage(Close, MA_1_Length);
MA_2 = XAverage(Close, MA_2_Length);
MA_3 = XAverage(Close, MA_3_Length);


// filter for long setups

if MA_1 > MA_2 and MA_2 > MA_3 then MA_Config_Long = true; // shorter moving averages are stacked above longer moving averages

if MA_3 > MA_3[5] and MA_3 > MA_3[10] then MA_3_Rising = true; // longest MA is rising over both five and ten periods ago

if MA_Config_Long and MA_3_Rising then
PlotPaintBar(High,Low,Open,Close, "SULong", Color_Up); // both criteria are met so plot paint bars

see this thread:
viewtopic.php?f=1&t=12482&p=59543&hilit ... lse#p59543



ps: how to post codes:
viewtopic.php?f=16&t=11713

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Plot Paint Bar Issue

Postby PD Quig » 03 Mar 2013

Thanks TJ! (I tried to use the "thumbs up" on your reply but got a fatal error, so I'm thanking you the old-fashioned way).

Here's where my code ended up after viewing your suggested link. Clean and works.

Code: Select all

//********************************************************************************
// inputs and variables
//********************************************************************************

inputs:
MA_1_Length (13),
MA_2_Length (34),
MA_3_Length (275),
Color_Up (blue),
Color_Down (red),
Color_NoTrend (yellow);

variables:
MA_1 (0),
MA_2 (0),
MA_3 (0),
MA_Config_Long (false),
MA_Config_Short (false),
MA_3_Rising (false),
MA_3_Falling (false),
SetupLong (false),
SetupShort (false);


//********************************************************************************
// perform calculations
//********************************************************************************

// calculate MAs

MA_1 = XAverage(Close, MA_1_Length);
MA_2 = XAverage(Close, MA_2_Length);
MA_3 = XAverage(Close, MA_3_Length);


// filter for long setups

MA_Config_Long = MA_1 > MA_2 and MA_2 > MA_3; // shorter moving averages are stacked above longer moving averages
MA_3_Rising = MA_3 > MA_3[5] and MA_3 > MA_3[10]; // longest MA is rising over both five and ten periods ago

SetupLong = MA_Config_Long and MA_3_Rising; // both criteria are met for long


// filter for short setups

MA_Config_Short = MA_1 < MA_2 and MA_2 < MA_3; // shorter moving averages are stacked below longer moving averages
MA_3_Falling = MA_3 < MA_3[5] and MA_3 < MA_3[10]; // longest MA is fallin over both five and ten periods ago

SetupShort = MA_Config_Short and MA_3_Falling; // both criteria are met for short


if SetupLong then // plot long paint bars

PlotPaintBar(High,Low,Open,Close, "A", Color_Up)

else if SetupShort then // plot short paint bars

PlotPaintBar(High,Low,Open,Close, "A", Color_Down)

else // plot no trend bars

PlotPaintBar(High,Low,Open,Close, "A", Color_NoTrend);
Attachments
2013-03-03_2055.png
(27.64 KiB) Downloaded 494 times

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

Re: Plot Paint Bar Issue

Postby TJ » 03 Mar 2013

Thanks TJ! (I tried to use the "thumbs up" on your reply but got a fatal error, so I'm thanking you the old-fashioned way).

Here's where my code ended up after viewing your suggested link. Clean and works.
Nice work! Thanks for sharing.


Return to “MultiCharts”