Reply To: Scan For 50 sma higher than 150 sma but result are wrong

Optuma Forums Optuma Scripting Scan For 50 sma higher than 150 sma but result are wrong Reply To: Scan For 50 sma higher than 150 sma but result are wrong

AvatarTrevor R
  • Topics: 79
  • Replies: 252
  • Posts: 331

Hi Deepak,

I’ve been trying to post this response for some time but the Forum keeps rejecting it for some reason the Optuma Guru’s have not identified, so here I go trying again at their request.

I must admit that I really cannot work out what you are trying to do. You say you want to find stocks when the 50 sma is greater than the 150 sma, but then I find your script has ema20, ema40, sma50, sma150, ma50 and ma100. You do not describe what all the other moving averages are supposed to be doing.

Your script has numerous “AND”, “OR”, “>” and “<” operators, in many cases it being unclear in which sequence they should be evaluated. As written they will be evaluated sequentially.

What I mean is Var1 > Var2 Or Var3 < Var4 And Var5 > Var6 can result in a confused and unexpected result as the script will attempt to evaluate itself in a simple left to right sequence. To mark sure the sequence is evaluated correctly it needs to be written as  (Var1 > Var2) Or (Var3 < Var4) And (Var5 > Var6).  This clear definition of the groups of comparison and evaluations becomes even more critical as the scripts become more complex.

I’ve taken your script and split it into individual variables and shown some different bracketing arrangement that will produce very different results. As  I can’t work out what you are trying to achieve with your complete script this will most probably not give you the results you are seeking.

A few other comments:

·         It is well worth splitting your script into multiple simple evaluations as I’ve done above, and then combine the variables. Doing this allows you to easily comment out (// at the start of the line) to test the script step by step. It also makes bracketing the various sub-scripts easier and clearer.

·         I find it advisable to define all the properties of functions so you can be sure you have them the way you desire. (Many of your MA functions are relying in the default setting, whatever that may be.)

·         Function like CLOSE() and LOW() require the round brackets.

·         It’s simpler to put the bar offset for OPEN(), HIGH(), LOW() and CLOSE() between the round brackets, rather than appending the square bracketed offset, eg CLOSE(-1) is the same as CLOSE()[-1].

·         I must admit I don’t like the use of variable names like var1, var2 etc. I prefer meaningful, even though longer, variable names that have some meaning, eg the ema50 and ema150 which immediately can be understood as exponential moving average 50 or 150. It makes working out what you were trying to do when you go back to your script after a break of a few days or more. Have a shot at guessing at ClGtMA50 and LoLtMA50 – they’d be typical variable names I’d use in the above script.

Happy scripting



The Auld Tyma at

Auld Tyma Data Logo with URL 1 cm

Pin It on Pinterest

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.