I’m trying to write a screener that can catch three possible states.
They are:
- Time signal only
- Price signal only
- Price & time signal together
I want to be able to return one result which identifies which one it is but can only get two states.
Is it possible, if so how? Could I capture six if need be?
Thanks again
Rob
IF TimeAlertLong = 1 THEN
SignalAlert = 10
ENDIF
IF PriceAlertLong = 1 THEN
SignalAlert = SignalAlert + 10
ENDIF
IF PriceAlertLong = 1 AND TimeAlertLong = 1 THEN
SignalAlert = SignalAlert + 20
ENDIF
There you go, each 1 (true) will have its own position as well as each 9 (false). “99” means ALL conditions are false:
IF TimeAlertLong = 1 THEN
SignalAlert = 1
else
SignalAlert = 9
ENDIF
IF PriceAlertLong = 1 THEN
SignalAlert = SignalAlert + 10
else
SignalAlert = SignalAlert + 90
ENDIF
IF SignalAlert = 99 THEN
SignalAlert = 0
Endif
SCREENER[SignalAlert](SignalAlert AS "11")
the third signal is not needed, it is when the returned criterion is “11”, while the other two values can be “91” or “19”.
Thanks Roberto.
If I wanted to do the same but incorporate SHORT signals within the same screener (same principle applies, three possible states) is that possible?
Hope you’re staying out of the way of this damn virus!
You can use 2 and 20 for short signals, leaving 9 and 99 to have these combinations:
- 99 = 0 = NO signal
- 19
- 91
- 11
- 29
- 92
- 22
If both opposite signals can occur you might also have:
I am fine, just staying longer in front of my PC, so I have more time to reply 🙂
Thanks again Roberto
I think I’m with you. I will work on this in the morning and share the alert code back just in case it’s helpful for anyone else in the future.
Glad you’re staying out of the way of things. We aren’t quite in lock down here in the UK but the supermarket shelves were very bare earlier when we went out 🙁
Hi Roberto
I seem to have something wrong in my logic as I cannot get the short signals to activate at all. Can you help pelase?
Thnaks agian, Rob
I have converted the code to an indicator to help debug it…
// Hardcoded variables
// Can be either 0 or 2
TimeAlertShort = 2
PriceAlertShort = 0
// Can be either 0 or 1
TimeAlertLong = 0
PriceAlertLong = 0
// Short signals
// 29 = Price
// 92 = Time
// 22 = Price & Time
// 9 = no signal
IF TimeAlertShort = 2 THEN
SignalAlert = 2
ELSE
SignalAlert = 9
ENDIF
IF PriceAlertShort = 2 THEN
SignalAlert = SignalAlert + 20
ELSE
SignalAlert = SignalAlert + 90
ENDIF
// Long signals
// 19 = Price
// 91 = Time
// 11 = Price & Time
// 99 = no signal
IF TimeAlertLong = 1 THEN
SignalAlert = 1
ELSE
SignalAlert = 9
ENDIF
IF PriceAlertLong = 1 THEN
SignalAlert = SignalAlert + 10
ELSE
SignalAlert = SignalAlert + 90
ENDIF
IF SignalAlert = 99 THEN
SignalAlert = 0
ENDIF
RETURN SignalAlert as "Signal Alert"
Your line 53 ahould read (you coded it as if it were an indicator):
SCREENER[SignalAlert](SignalAlert as "99")
Moreover when SHORT conditions are true, lines 40 and 46 will reset signal to 99.
This is the correct code:
// Hardcoded variables
// Can be either 0 or 2
TimeAlertShort = 2
PriceAlertShort = 0
// Can be either 0 or 1
TimeAlertLong = 0
PriceAlertLong = 0
// Short signals
// 29 = Price
// 92 = Time
// 22 = Price & Time
// 9 = no signal
// Long signals
// 19 = Price
// 91 = Time
// 11 = Price & Time
// 99 = no signal
IF TimeAlertShort = 2 THEN
SignalAlert = 2
ELSIF TimeAlertLong = 1 THEN
SignalAlert = 1
ELSE
SignalAlert = 9
ENDIF
IF PriceAlertShort = 2 THEN
SignalAlert = SignalAlert + 20
ELSIF PriceAlertLong = 1 THEN
SignalAlert = SignalAlert + 10
ELSE
SignalAlert = SignalAlert + 90
ENDIF
IF SignalAlert = 99 THEN
SignalAlert = 0
ENDIF
SCREENER[SignalAlert](SignalAlert as "99")
Perfect, thanks again Roberto.