indicator width depending on code

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #211951 quote
    Swisspatrick
    Participant
    New

    I’m trying to code an indicator where the width depends on a condition. As a simply example use a pair of moving averages, e.g. MA20 and MA200.
    – if MA20 >MA200, I want the width of MA20 to be 2,
    – if MA20 < MA200, I want the width of MA20 to be 1.

    Problems:
    – RETURN MA20 COLOURED (255,0,0) style(line, 2) only accepts numbers, not code variables (e.g. style(line, x))

    I thought of a workaround of plotting an indicator 2x, once with width 1 and once with width 2 (if a condition is met with width 2, otherwise invisible),
    – but the transparency alpha in “colored by (r,g,b,alpha)” does not allow two different values.

    Any idea how this could be fixed?

    Thank you.

    #211975 quote
    JC_Bywan
    Moderator
    Master

    Hello,

    ma20a=Average[20](close)// ma20 for width=1
    ma20b=Average[20](close)// ma20 for width=2
    ma200=Average[200](close)
    
    if ma20b>ma200 then // make visible case width=2
    alpha=255
    else // make invisible case width=1
    alpha=0
    endif
    
    return ma20a, ma20b coloured(0,0,0,alpha) style(line,2), ma200
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

indicator width depending on code


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by JC_Bywan
2 years, 10 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/22/2023
Status: Active
Attachments: No files
Logo Logo
Loading...