Problem with aiHighestDispValue
Posted: Apr 26 2014
I wrote a simple indicator to test plotting a value in the upper left hand corner of the chart and opened a can of worms. It keeps driving a floating point error.
Here's the code:
When I comment out the line of the plot section that contains aiHighestDispValue and substitute the line immediately below, all is good. Then, when I comment out the substitute line and re-compile, it still works--with the plot now in the upper left corner as desired.
The problem occurs when I turn the indicator off and then on again. The error floating point error gets thrown for the indicator and an error also gets thrown for the (completely unrelated) signal as well. At that point the only way to continue is to close and re-open the workspace.
I have used the aiHighestDispValue function in a number of other code streams without encountering this problem. Thanks in advance for any help.
PDQ
Here's the code:
Code: Select all
{************************************************************************************************************************************************************
inputs and variable initialization section
************************************************************************************************************************************************************}
[RecoverDrawings = false];
inputs:
SignalBarStopBuffer (0.5), { an incremental buffer amount beyond the initial calculated stop }
PositionSize (2),
Text_Color (white),
Font_Size (14);
variables:
intrabarpersist Risk_Plot_Vert (0),
intrabarpersist Risk_Plot_Horz (0),
intrabarpersist Text_Risk (0),
Risk (0),
Text_Risk_str ("");
{*************************************************************************************************************************************************************
risk calculation
*************************************************************************************************************************************************************}
Risk = round(((absvalue(high - low) + SignalBarStopBuffer) * PositionSize * 100) + (PositionSize * 2 * (10 + 2.01)),0);
{*************************************************************************************************************************************************************
plot section
*************************************************************************************************************************************************************}
Risk_Plot_Vert = round(GetAppInfo(aiHighestDispValue), 1); { gets the top of the chart screen }
// Risk_Plot_Vert = high + 5;
Risk_Plot_Horz = CalcTime(DateTime2ELTime(GetAppInfo(aiLeftDispDateTime)), 5); { gets the leftmost bar on the chart }
Text_Risk_str = "Risk: $" + numtostr(Risk,0);
if LastBarOnChart then once begin { initialize text }
Text_Risk = Text_New(Date,Risk_Plot_Horz,Risk_Plot_Vert - 1.0,Text_Risk_str);
Text_SetColor(Text_Risk,Text_Color);
Text_SetSize(Text_Risk,Font_Size);
Text_SetAttribute(Text_Risk,1,true);
Text_SetStyle(Text_Risk,0,1);
end;
{ update text string value and location }
begin
Text_SetString(Text_Risk, "Risk: $" + numtostr(Risk,0));
Text_SetLocation(Text_Risk, date, Risk_Plot_Horz, Risk_Plot_Vert - 1.0);
end;
The problem occurs when I turn the indicator off and then on again. The error floating point error gets thrown for the indicator and an error also gets thrown for the (completely unrelated) signal as well. At that point the only way to continue is to close and re-open the workspace.
I have used the aiHighestDispValue function in a number of other code streams without encountering this problem. Thanks in advance for any help.
PDQ