How to ignore error 99 while using error functions in code

I want to run certain afl only in daily timeframe. So I have written below demo code. Here I got the error 99.
How to ignore that and continue ?
@Tomasz

if( Interval()!=inDaily ) 
 { 
   Error("Timeframe Must be Daily"); 
 } 

SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle);
SetBarFillColor( IIf( C > O, colorBrightGreen, colorRed ) );
Plot( C, "Price", IIf( C > O,  colorBrightGreen,colorRed ), styleCandle|styleNoTitle|styleNoLabel );
Plot( C, "Price",  colorWhite,styleNoLine|styleNoTitle);
Title = StrFormat("{{NAME}} - {{INTERVAL}}  - {{DATE}}" +
EncodeColor(colorAqua)+
"\n OPEN = "+Open+"     HIGH = "+High+"     LOW = "+Low+"     CLOSE = "+Close+ "     CHANGE  = "+Prec( ROC( C, 1 ), 2) +"%%");

Hello

To Receive Error Notification like an Alert from your chart you can use the Title , GfxTextOut , Say, SetChartBkColor , Sound, or some other function instead of Error function.

// Receive Error Notification if the chart is NOT daily timeframe. (like a text alert)

SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );

if( Interval() != inDaily )
{
    // if is NOT daily chart do something
    // display User-specified error message As a Title on the chart
    Title = " >>>>  Timeframe Must be Daily <<<<<";
    GfxTextOut ( " Wrong Timeframe " , 50 ,100);

}
else  
{
    //  if chart is Daily do something
    Title = StrFormat( "{{NAME}} - {{INTERVAL}}  - {{DATE}}" + EncodeColor( colorAqua ) +
                       "\n OPEN = " + Open + "     HIGH = " + High + "     LOW = " + Low + "     CLOSE = " + Close + "     CHANGE  = " + Prec( ROC( C, 1 ), 2 ) + "%%" );
	Plot( C, "Price", colorDefault, styleCandle );

}
1 Like

Thanks for the reply. But what if I want to use error function.
I have a solution for that but that is manual.
Step 1
First we have to comment out the error function and apply the formula

Step 2
Remove comment from error function and saved it.
It will work as expected.

But any modification in formula need these two step to repeat . So I want to ignore that error.
Is it possible ?

Hi
Maybe you can use other coding technique to achieve this. My mind is not working at this moment.
As it is very late time now, lets wait for @Tomasz to reply.

But what the Error() function says is

Error("text")

The function stops the formula execution in the place of the call and displays user-specified error message.

Thanks. you always reply my post. Thanks a lot once again
:sweat_smile:

1 Like

From what I think, there is no problem with the code you posted.

The Error message is displayed correctly, only it is visually similar to other Native AB Errors and it shows Error Caret after the Error() function so you feel there is a problem with the code.

But the custom error message is displayed correctly.

image
since code execution is halted, there will be nothing else drawn on the pane except the text that you see.

Unless it is a critical error, better to use an Option like @PanoS suggested as it appears more user friendly or appealing better.

Error 99 maybe a generic Code for user-invoked Error() Calls.

1 Like

Thanks for reply. But you did not get my point. I want the error which you have posted. I do not want to run the code if timeframe is not daily. What i want is to overcome the error message in afl editor.
Here is the screen shot.
error99
I want the error to go so that i can apply the formula.

You did not make this point earlier, so the question of me not getting it doesn't arise.
You should specify the Error Highlight occurring in the AFL Editor. otherwise it is assumed in the Pane.
This error will disappear by clicking the close button on the message bar in yellow.

Now coming to the Error, looking at the whole scenario, I think that's an improper use of Error().

Just throwing errors isn't ok when you can handle them, and this applies to any software.
In your case, I'd just put a message, change TF to Daily.

Also, the Error() function implies an Error in AFL to be corrected, where as the problem has nothing to do with AFL but requires a specific Chart Timeframe which reinforces the fact that it is improper use of a function.

Infact, if you want to auto-change the Interval to daily, there is COM/OLE code here in the forum that can change the Interval of active chart..

okay fine. But you can not apply this formula from AFL Editor.
First you have to comment out the error code then apply.
After that you can comment it out and save the formula.

My Question is not tricky. I want to know simply that
Is there any build in AFL function to suppress this error ?

I'm able to click the close button on yellow Message bar and it goes.

Maybe you aren't able to apply because the Charts TF isn't still daily or chart doc not active doc or something like that.

Only TJ knows for sure, but I don't think it can be done because its doing what it is supposed to do.

I think the Error() is more suited for those calling it from DLLs. Anyway, now you know the optimal code usage.

Thanks for prompt reply.
Error function is very useful in afl because it stopped me from doing any error in analysis on chart .
You know some afl for self is written to use in daily time frame only or some written for intraday timeframe.

/// Don't execute in Formula Editor, Code Verification, Apply
if ( Status( "actionex" ) != actionExEditVerifyFormula ) {
	if ( Interval() != inDaily ) 
		Error( "TimeFrame Must be Daily" );
}
8 Likes

Thanks. Your reply solved my current problem also learn one of the excellent formula.
:smile:

1 Like