bobptz
January 7, 2018, 11:04am
1
In line 5 I ger warning 505, Division by zero:
yValuesRange = Status( “axismaxy” ) - Status( “axisminy” );
Why? As long as I have a chart (which I do) yValuesRange will never become zero.
printf("Status( axismaxy )= %g\n",Status( "axismaxy" ));
printf("Status( axisminy )= %g\n",Status( "axisminy" ));
yValuesRange = Status( "axismaxy" ) - Status( "axisminy" );
PixPerUnitY = Status( "pxchartheight" ) / yValuesRange;
// price chart
SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
bobptz:
printf("Status( axismaxy )= %g\n",Status( "axismaxy" ));
printf("Status( axisminy )= %g\n",Status( "axisminy" ));
yValuesRange = Status( "axismaxy" ) - Status( "axisminy" );
PixPerUnitY = Status( "pxchartheight" ) / yValuesRange;
// price chart
SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
Why don't you simply trace your variables? Is it so difficult? I don't think it is (see code below).
If you apply your code from Editor via apply button there or if you click code check & profile there in editor then your code is not applied in Chart. Editor != Chart pane. Since you code is not applied in chart there are not any other axis minimum and maximum values other than zero . Same applies if you run your code in analysis. Analysis does not have axes. Does it? So there those status values are zero too.
_TRACEF output:
Instead of assuming "...never become zero" simply correct what the program is showing you in order to get your code running without warnings or errors.
So what to do?
Simply add a very low number to yValuesRange.
printf("Status( axismaxy )= %g\n",Status( "axismaxy" ));
printf("Status( axisminy )= %g\n",Status( "axisminy" ));
minY = Status( "axisminy" );
maxY = Status( "axismaxy" );
_TRACEF( "miny: %g, maxy: %g", minY, maxY );
yValuesRange = maxY - minY + 1e-9;
PixPerUnitY = Status( "pxchartheight" ) / yValuesRange;
// price chart
SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
1 Like
bobptz
January 7, 2018, 1:17pm
3
You are right fxshrat. Yes, I assumed it always runs on a chart.
Thank you very much for the tip.