Announcement

Collapse
No announcement yet.

MACD Histogram question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MACD Histogram question

    Hello everybody

    I was wondering how I can colour every n'th bar of the histogram after it become possitive or negative a different colour.

    Say I want to colour every 5th bar after it crosses from negative to positive black and the same if it crosses from possitive to negative.

    Any ideas or help will be appreciated.

    I include my code for the histogram.
    Attached Files

  • #2
    Hello Kobus,

    This could be accomplished using two global variables. Declare them outside of main() and set their initial values to 0. Then add a BARSTATE_NEWBAR condition inside each of your onAction functions. Inside those conditions, increment the variable by one and reset the apposing counter variable to 0 so that when the histogram crosses back through the 0 line the count will start at 0 for the opposite side. Then add another condition in each onAction function that looks for the value of 5 before coloring the histogram.

    PHP Code:
    var nUp 0;
    var 
    nDn 0;

    function 
    onAction1() {
        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    nDn 0;
            
    nUp++;
        }
        if (
    nUp == 5setBarFgColor(Color.RGB(255,0,0));
    }
     
       
    function 
    onAction2() {
        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    nDn++;
            
    nUp 0;
        }
        if (
    nDn == 5setBarFgColor(Color.green);

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Jason

      Thank you very much for the help, I appreciate it very much.

      I include the updated code.
      Attached Files

      Comment


      • #4
        You're most welcome.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment

        Working...
        X