ProRealTime: histogram with MACD and EMA returns only zero

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #257625 quote
    SavvySteve
    Participant
    New

    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

    #257626 quote
    JS
    Participant
    Senior

    Hi Steve,

    Try:

    ElsIf a<a[1] and b<b[1] then

    Result=-1

    #257640 quote
    SavvySteve
    Participant
    New

    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

    Screenshot-2026-02-07-at-15.42.34.png Screenshot-2026-02-07-at-15.42.34.png Screenshot-2026-02-07-at-15.42.47.png Screenshot-2026-02-07-at-15.42.47.png
    #257642 quote
    SavvySteve
    Participant
    New

    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.

    #257643 quote
    JS
    Participant
    Senior

    Hi Steve,

    The problem is in the spelling of “ELSEIF”, the correct spelling is “ElsIf”…

    #257644 quote
    JS
    Participant
    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
    
    #257645 quote
    SavvySteve
    Participant
    New

    Hi JS,

    Brilliant! That spelling issue now resolved and it came out great!

    Many thanks!

    Steve

    JS thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

ProRealTime: histogram with MACD and EMA returns only zero


Community Welcome & Introductions

New Reply
Author
author-avatar
SavvySteve @savvysteve Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by SavvySteve
2 weeks, 6 days ago.

Topic Details
Forum: Community Welcome & Introductions
Language: English
Started: 02/06/2026
Status: Active
Attachments: 2 files
Logo Logo
Loading...