Scan For 50 sma higher than 150 sma but result are wrong

Hiii,

 

I have written below code for finding stock which has 50 sma higher than 150 sma but results are wrong. Also some filter i have added which are not working.

 

MA(BARS=20, STYLE=Exponential,CALC=Close)>MA(BARS=40, STYLE=Exponential,CALC=Close) AND

MA(BARS=50, STYLE=Simple, CALC=Close)>MA(BARS=150, STYLE=Simple, CALC=Close) )

AND

( close()>MA(BARS=50,CALC=Close) AND ( low()<MA(BARS=50, CALC=Close) OR low()[-1]<MA(BARS=50, CALC=Close)[-1] OR low()[-2]<MA(BARS=50, CALC=Close)[-2] OR low()[-3]<MA(BARS=50, CALC=Close)[-3])) or

( close()>MA(BARS=100,CALC=Close) AND ( low()<MA(BARS=100, CALC=Close) OR low()[-1]<MA(BARS=100, CALC=Close)[-1] OR low()[-2]<MA(BARS=100, CALC=Close)[-2] OR low()[-3]<MA(BARS=100, CALC=Close)[-3]))

 

 

Hi Deepak,

I’ve been trying to post a response to your request for assistance but the Forum keeps rejecting my detailed postfrown I reported to problem to Optuma Support, but because of the Christmas/New Year holidays we are unlikely to see a resolution before mid-January.

Send your email address to me at [email protected] and I’ll send my response directly to you.

Cheers

Trevor

The Auld Tyma at

Auld Tyma Data Logo with URL 1 cm

 

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.

ema20 = MA(BARS=20, STYLE=Exponential,CALC=Close);

// >

ema40 = MA(BARS=40, STYLE=Exponential,CALC=Close);

//AND

ema50 = MA(BARS=50, STYLE=Simple, CALC=Close);

//>

ema150 = MA(BARS=150, STYLE=Simple, CALC=Close) );

//AND

var1 = ( close() > MA(BARS=50,CALC=Close);

// AND

var2 = ( low() < MA(BARS=50, CALC=Close);

// OR

var3 = low()[-1] < MA(BARS=50, CALC=Close)[-1];

//OR

var4 = low()[-2] < MA(BARS=50, CALC=Close)[-2];

// OR

var5 = low()[-3] < MA(BARS=50, CALC=Close)[-3]));
// or
var6 = ( close() > MA(BARS=100,CALC=Close);

// AND

var7 = ( low() < MA(BARS=100, CALC=Close);

//OR

var8 = low()[-1] < MA(BARS=100, CALC=Close)[-1];

// OR

var9 = low()[-2] < MA(BARS=100, CALC=Close)[-2];

// OR

var10 = low()[-3] < MA(BARS=100, CALC=Close)[-3]));
//
// Original evaluation sequence
Result1 = (ema20 > ema40) and (ema50 > ema150) and var11 and var2 or var3 or var4 or var5 or var6 and var7 or var8 or var9 or var10;

//
// Alternative evaluation sequence 1 - same operators but bracketing changes evaluation sequence, hence result

Result2 = (ema20 > ema40) and (ema50 > ema150) and var11 and (var2 or var3 or var4 or var5 or var6) and (var7 or var8 or var9 or var10);

//
//Alternative evaluation sequence 2 - again same operators but bracketing changes evaluation sequence, hence result

Result3 = (ema20 > ema40) and (ema50 > ema150) and (var11 and (var2 or var3)) or var4 or (var5 or (var6 and var7)) or (var8 or var9 or var10);

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

Cheers

Trevor

The Auld Tyma at

Auld Tyma Data Logo with URL 1 cm

Sir i have put simple formula as below but results are still not matching

 

(MA(BARS=20, STYLE=Exponential,CALC=Close)>MA(BARS=40, STYLE=Exponential,CALC=Close)) and (MA(BARS=50, STYLE=Simple, CALC=Close)>MA(BARS=150, STYLE=Simple, CALC=Close))

 

The above criteria in my understanding is 20 EMA > 40 EMA

and

50 SMA > 150 SMA

so the result shall be on those which satisfy both of the above conditions.

 

However i am getting result which is wrong.

 

Below attached figure yellow average is 150 SMA & Blue is 50 SMA.

 

whereas 20 EMA & 40 EMA are in order which are dotted respectively.

 

PS: Also is i am putting semicolon at end optuma is restarting again & again.

 

Hi Deepak,

Your script:

(MA(BARS=20, STYLE=Exponential,CALC=Close)>MA(BARS=40, STYLE=Exponential,CALC=Close)) and (MA(BARS=50, STYLE=Simple, CALC=Close)>MA(BARS=150, STYLE=Simple, CALC=Close))

is working perfectly as can be seen on the following chart of the NDY:

20200121 Deepak's Script

I do not subscribe to the Indian market so cannot show you IIFL, so I’ve used NDY (NASDAQ100 Index) and as you can see your script has highlighted using SHOWBARs (the arrows) and SHOWPLOT (yellow shading using an unlinked layer) where your script conditions are met.

Cheers

Trevor

The Auld Tyma at

Auld Tyma Data Logo with URL 1 cm