Throwing error message for invalid input

jackie540

Junior member
Messages
13
Likes
1
I don't understand how I can show an error message if the inputs entered are not valid (outside a particular range of numbers, e.g.). Has anyone thrown an error message to tell the user he needs to re-enter an input?
 
I don't understand how I can show an error message if the inputs entered are not valid (outside a particular range of numbers, e.g.). Has anyone thrown an error message to tell the user he needs to re-enter an input?

Hello Jackie540
Afaik there are no Input validation checks other than for correct format of Numeric, True/False or Text format.

Is this for an Indicator ?
For an Indicator you could write your code so that if the Input value is outside a range, then the indicator simply doesn't plot. That should draw attention to it !
Or you could include an extra Plot statement which displays something like "Input out of Range" on the chart or in a Radar column.

Glenn
 
I did some more work and found the #BEGINALERT #END; code. I'm going to try to throw an alert when invalid input is entered. True, I like the idea too that the chart won't display.

Thanks, Glenn.
 
Paul, I have a screen shot but how do I get that out to you? Attach a Word file?

The code I used is below:

{ Validate ShortPeriodForecaset is not > 25% of ShortStudyPeriod }
#BEGINALERT
if ShortPeriodForecast > (.25 * ShortStudyPeriod) then begin
Alert("Short Period Forecast input can't be > 25% of Short Study Period input.");
end;
#END;

ShortPeriodForecast and ShortStudyPeriod are two inputs. It works nicely.
 
You can throw error messages using EL. Look into RaiseRunTimeError. It will prevent the code from being ran. Being as it is runtime then it will only happen when they try to load. Alerts do not work in strategies.
 
Thanks, StratOpt, as always. I tried it out. I think, although you may differ, that the Alert notification is easier to understand and correct. For the RaiseRunTimeError, the Details button needed to be clicked to read the error message, and then the Format button needed to be re-enabled by clicking the Status button. Lastly, I do have my Alert in an indicator.
 
Yes, I disagree that it is harder. It is the same difficulty. One line of code in exactly the same syntax. They serve different purposes. The Alert serves to warn you, but not prevent you from making a mistake, as the alert will not happen until you are actually runing it on live data. The RunTimeError will both alert you and prevent you from running the program at all until you correct it. It just depends on how critical your application is. I prefer to not have to wait until I am running on live data to get an alert that I goofed up. I prefer to learn of my mistakes immediately if at all possible.

if << wrong thing one here >> then RaiseRunTimeError( "Failure to enter numerical value") ;

This will create a pop up window with the details within it, and then prevent somebody from further using the program until the error is fixed. This is also the sort of thing that you would do if you are building a program for use by others who may not be intimately familiar with your program or for a commercial usage of the program which may actually be in a black boxed format.
 
Top