Get MA indicator line color

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #186780 quote
    krogen
    Participant
    New

    Hi there,

    I’m trying to write script where it checks if the MA line color changes from one bar to the next. Is there a property or method to get the color of the MA line e.g. green for bullish and red for bearish?

    Thanks for any help!

    k

    #186797 quote
    robertogozzi
    Moderator
    Master

    There you go:

    MA = average[20,0](close)
    BullMA = MA > MA[1]
    BearMA = MA < MA[1]
    MAchange = (BullMA and BearMA[1]) or (BullMA[1] and BearMA)

    lines 2 and 3 retain the trend of the MA, while line 4 returns any change in direction (colour).

    #186801 quote
    krogen
    Participant
    New

    Thank you @robertogozzi!

    Something I don’t understand as I am new to this scriping language (though I have experience with JavaScript and C#)

    BearMA[1]

    Shouldn’t the above contain only a true or false value? How can you use it like an array?

    #186807 quote
    JS
    Participant
    Senior
    MySma   = average[20,0](close)
    Rising  = MySma > MySma[1] AND MySma[1] < MySma[2]
    Falling = MySma < MySma[1] AND MySma[1] > MySma[2]
     
    if rising then 
     r = 0
     g = 255
    elsif falling then 
     r = 255
     g = 0
    endif 
     
    return mysma coloured(r,g,0)
    
    robertogozzi thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Get MA indicator line color


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
krogen @krogen Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by JS
4 years ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/28/2022
Status: Active
Attachments: No files
Logo Logo
Loading...