Adding Filter: SPY above 40 SMA
Author: 01439
Creation Date: 8/15/2019 6:47 PM
profile picture

01439

#1
I am new to WealthLab coding and am trying to add a simple piece of code to below. Have looked through the forum and found some help but cannot get it to work?

All I want to do is say that SPY must be greater than 40 SMA.

CODE:
Please log in to see this code.
profile picture

Eugene

#2
This question has been raised numerous times on the forum, for example:

Buy/sell signal using external symbol SPY or .SPX
SPY criteria

QUOTE:
All I want to do is say that SPY must be greater than 40 SMA.

You're now authorized to use Community.Rules with conditions like:

* External Symbol Price is above (below) its Moving Average

This is the simplest option which requires no programming. Anyway, here's code sample as requested:

CODE:
Please log in to see this code.
profile picture

01439

#3
Thank You Eugene
profile picture

Eugene

#4
At your service.
profile picture

LenMoz

#5
Eugene, why did you express the SPY variables as "var" in stead of DataSeries? I wrote the code as I would have written it and see no difference.
CODE:
Please log in to see this code.
profile picture

Eugene

#6
Len, it's just syntactic sugar (and less room for error for new users).
profile picture

superticker

#7
QUOTE:
why did you express the SPY variables as "var" in stead of DataSeries?

QUOTE:
less room for error for new users

As us computer professionals on the forum know, strongly typed languages (like C#) were specifically created to reduce errors. The intent is to discover the errors (and spelling typos) at compile time, not at run time. I think that's the subtle point being made in Post# 5.

There are situations where the returned type is "unknown" like in a Linq query or data read from an Excel XML file when "var" may be necessary; otherwise, we want to use the power of a strongly typed language to catch errors early (compile time).
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).