Unexpected behavior in plotting arrows on a Renko chart

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

Unexpected behavior in plotting arrows on a Renko chart

Postby PD Quig » 28 Oct 2014

Version 9.0 Release (Build 10014)

The test code below is supposed to initialize two arrows above price on the last bar of a Renko chart. Ultimately the objective is to be able to move either arrow and have the code pick up data from the bars that they point to and perform other calculations.

Instead, after a random number of bars (it probably isn't random but I haven't been able to figure out a pattern) the two arrows are replotted on the latest bar. The previous arrows are still visible on the chart until I click on the chart (see file attached below).

Also, I am using a "once begin" to clear the print log, and this block of code is being entered more than once. When I comment out the ClearPrintLog block, it appears that instead of bar number incrementing by one, the bar number jumps backward and then resumes incrementing (see output file attached). Also, the LastBarOnChart_s value keeps jumping between FALSE and TRUE.

As a final bizarre clue, if I comment out the "Up_Bar_Low" variable assignment line, the code works as I expected--the arrows plot once and only once and I can move them around and retrieve the bar number they point to.

I must be missing something obvious.

Code: Select all

{****************************************************************************
Name : $Test_Arrow_Plotter_s
Description :
Last Modified Date : 10/28/2014 -- test placing arrows above or below bars to get data from bars
*****************************************************************************}

{ system parameter section }

[RecoverDrawings = false];

[LegacyColorValue = false];


{*****************************************************************************
variable initialization section
*****************************************************************************}

variables:
Up_Arrow_Color (blue),
Down_Arrow_Color (red),
Up_Arrow (0),
Down_Arrow (0),
intrabarpersist Down_Bar_High (0),
intrabarpersist Up_Bar_Low (0),
intrabarpersist Up_Arrow_Bar (0),
intrabarpersist Down_Arrow_Bar (0),
intrabarpersist ID_Arw_Up (0),
intrabarpersist ID_Arw_Down (0),
ID (0);


{******************************************************************************
plot initial arrows
******************************************************************************}

if LastBarOnChart_s then once begin

{ initialize arrows above the last bar on the chart }

Up_Arrow = Arw_New_s(date, time_s, close + 2, false);
Arw_SetSize(Up_Arrow, 7);
Arw_SetColor(Up_Arrow, Up_Arrow_Color);
Arw_SetStyle(Up_Arrow, 10);

Down_Arrow = Arw_New_s(date, time_s, close + 3, true);
Arw_SetSize(Down_Arrow, 7);
Arw_SetColor(Down_Arrow, Down_Arrow_Color);
Arw_SetStyle(Down_Arrow, 10);
end;


{*****************************************************************************
find location of arrows
*****************************************************************************}

begin

ID = Arw_GetFirst(1); { study-drawn arrows only }

while ID > 0 begin

if Arw_GetColor(ID) = Up_Arrow_Color then begin { up arrow }

ID_Arw_Up = ID;
Up_Arrow_Bar = Arw_GetBarNumber(ID);
end;

if Arw_GetColor(ID) = Down_Arrow_Color then begin { down arrow }

ID_Arw_Down = ID;
Down_Arrow_Bar = Arw_GetBarNumber(ID);
end;

ID = Arw_GetNext(ID, 1); { study-drawn arrows only }
end;
end;


Up_Bar_Low = low[(BarNumber - Up_Arrow_Bar)]; { assign low of up bar to variable }


{*************************************************************************
diagnostic print section
*************************************************************************}

once begin

ClearPrintLog;
end;


Print(
"Bar Number= ", (BarNumber + MaxBarsBack),
" time_s= ", time_s,
" Up_Arrow_Bar= ", Up_Arrow_Bar + MaxBarsBack,
" Down_Arrow_Bar= ", Down_Arrow_Bar + MaxBarsBack,
" LastBarOnChart_s= ", LastBarOnChart_s
);
Attachments
arrow output file.txt
messed up output data
(32.13 KiB) Downloaded 462 times
Multiple_arrow_initializations.png
Shows multiple arrows plotted
(32.79 KiB) Downloaded 327 times

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

Re: Unexpected behavior in plotting arrows on a Renko chart

Postby Henry MultiСharts » 29 Oct 2014

Hello PD Quig,

Please send me the workspace you are using for replicating this behavior to support@multihcarts.com
Please also attach a screenshot of MultiCharts->File->Preferences->Charting.


Return to “MultiCharts”