Hi, I’m new to coding but have been through the introductory videos in detail. I’d like some help with the following simple programme I’ve created, which I’d like to return as a histogram on a separate panel below a price chart.
Although I have specified three different results [1, -1, 0], the resulting indicator only shows one horizontal line across the panel at the zero level with the area below shaded purple. The variable for the Exponential Average [short] I have included in the variables section [wrench indicated alongside above the code lines] as 9. Here is my programme code thus far:
//Variables
a = ExponentialAverage[short](close)
b = MACD[12,26,9](close)
IF a > a[1] AND b > b[1] THEN
Result = 1
IF a < a[1] AND b < b[1] THEN
Result = -1
ELSE
Result = 0
ENDIF
ENDIF
RETURN Result
Basically, if the current value for the EMA is higher than its value for the period/bar/candle immediately preceding [1], and if the MACD-H value [Line-Signal] is higher than that of its immediately preceding value [1], then I’d like the histogram to show +1. The rest should be clear…
Also, I need reminding how to return the indicator as a histogram.
Apologies for the basic nature of the request to all you pros, but any help would be appreciated. Many thanks, Steve
JSParticipant
Senior
Hi Steve,
Try:
ElsIf a<a[1] and b<b[1] then
Result=-1
Hi JS,
Thanks for the reply.
I had previously tried ‘ELSEIF’ as you suggested for line 2 of the code. For some reason, the variable ‘a’ in that line has a red mark indicating an error and when I click ‘apply’, I get the message ‘ unauthorised character: “a variable name” ‘. When the code replaces ELSEIF with a plain ELSE, that difficulty disappears and the indicator displays but with the issues mentioned in my first post. So, I’m still at square one! See attached screenshots of the code (modified as you suggest) and the error message.
SA
Apologies, I should have said that if I replace ELSEIF with a simple IF (not ELSE, as I stated in my reply) for line 2 of the code, then the ‘error’ issue disappears.
JSParticipant
Senior
Hi Steve,
The problem is in the spelling of “ELSEIF”, the correct spelling is “ElsIf”…
JSParticipant
Senior
//Variables
a = ExponentialAverage[9](close)
b = MACD[12,26,9](close)
IF a > a[1] AND b > b[1] THEN
Result = 1
ElsIf a < a[1] AND b < b[1] THEN
Result = -1
ELSE
Result = 0
ENDIF
RETURN Result
Hi JS,
Brilliant! That spelling issue now resolved and it came out great!
Many thanks!
Steve