Indicator Value Continuation

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #141606 quote
    Bi
    Participant
    New

    Hi all

    I am new to PRT as well as coding, I am trying to create an indicator with the below logic but the value seems to be not continuous. I feel like I am missing an obvious point, appreciate your help.

    The logic behind the indicator is

    Positive signal  – when EMA9 crossover EMA20 while both the line being under VWMA50

    Negative signal – when EMA9 crossover EMA20 while both the line being under VWMA50

    The above signals are getting created accurately but I want the value to continue even when EMA9 and EMA20 crosses above VWMA50. So essentially what I am trying to do is if a positive signal occurred then show me the signal until a negative signal appears. At the moment the signal disappears when EMA9 and EMA20 crosses above VWMA50 I want the system to ignore that event and lookback the value what it was previously.

    Values would look like 0000011111111111-1-1-1-1-1-1

    I am not sure whether I should be using “for loop ” to get this which I’ve tried and failed.

    I would very much appreciate your expert help

    ma9 = ExponentialAverage[9](close)
    ma20= ExponentialAverage[20](close)
    ma50 = Average[50](close*volume)/Average[50](volume)
    
    value1  = ma9-ma20
    value2 = ma9-ma50
    value3 = ma20-ma50
    
    if value1 crosses over 0 and value2 <0 and value3< 0then
    direction = 1
    elsif value1 crosses under 0 and value2>0 and value3>0 then
    direction = -1
    else
    direction = 0
    endif
    
    
    if direction[1] = 1 and value1>0 then
    value = 1
    elsif direction[1] =-1 and value1<0 then
    value = -1
    else
    value = 0 
    endif
    
    
    return value
    #141613 quote
    robertogozzi
    Moderator
    Master

    I think you only have to remove, or comment out, line 23.

    Bi thanked this post
    #141647 quote
    Bi
    Participant
    New

    Legend! thank you it worked

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

Indicator Value Continuation


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Bi @mpscomail Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Bi
5 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/14/2020
Status: Active
Attachments: No files
Logo Logo
Loading...