Announcement

Collapse
No announcement yet.

setBarFgColor issue

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

  • setBarFgColor issue

    I suspect this must be some logic error on my part, but I really can't figure it out. Any help appreciated.

    I have a section of code that should turn the line green if a condition is true ( nRSI_Sig == 1) or red ( nRSI_Sig == -1 ). If neither condition is true, the default line color of blue will be used.

    PHP Code:
       if ( nBarState == BARSTATE_NEWBAR ) {
            
    debugPrintln("Index: " nBarIndex " nRSI_Sig: " nRSI_Sig " nLastRSI: " nLastRSI " nCurrentRSI: " nCurrentRSI);
            if ( 
    nRSI_Sig == ) {
                
    setBarFgColor(Color.RGB(0,2550), 0);
                
    debugPrintln("Index: " nBarIndex " Green ");
            }
            if ( 
    nRSI_Sig == -) {
                
    setBarFgColor(Color.RGB(255,00), 0);
                
    debugPrintln("Index: " nBarIndex " Red ");
            }
       } 
    nRSI_Sig is set prior to this in a section of code that is restricted by a check for NEWBAR ( if ( nBarState == BARSTATE_NEWBAR ) ).

    The issue is that in RT the line is always Blue (the default color), even though nRSI_Sig is 1 or -1 most of the time, and I get the correct color printed on the Formula Output screen:

    PHP Code:
    Index: -3 nRSI_Sig: -1 nLastRSI66.38295566980304 nCurrentRSI68.40682690587413
    Index
    : -3 Red 
    Index
    : -2 nRSI_Sig1 nLastRSI68.40682690587413 nCurrentRSI71.8209949644798
    Index
    : -2 Green 
    Index
    : -1 nRSI_Sig1 nLastRSI71.8209949644798 nCurrentRSI72.76165327122916
    Index
    : -1 Green 
    Index
    0 nRSI_Sig1 nLastRSI72.76165327122916 nCurrentRSI71.6848261373386
    Index
    0 Green 
    All historical data is displayed as I would expect (red or green line) and the value of the line is always correct in either mode. A refresh of the chart will display the line color correctly.

    If I remove the NEWBAR check in the section of code above, it all displays correctly, even in RT.

    What am I missing?

    Thanks!
    Garth

  • #2
    Re: setBarFgColor issue

    Garth
    Assuming I understood the problem correctly that happens because you are using setBarFgColor() inside the BARSTATE_NEWBAR condition which will apply that color only on the first tick of each bar after which the color reverts to whatever default you have set. On historical bars the script executes only once per bar hence the color set on that execution remains
    You should use setDefaultBarFgColor() instead of setBarFgColor()
    Alex


    Originally posted by gspiker
    I suspect this must be some logic error on my part, but I really can't figure it out. Any help appreciated.

    I have a section of code that should turn the line green if a condition is true ( nRSI_Sig == 1) or red ( nRSI_Sig == -1 ). If neither condition is true, the default line color of blue will be used.

    PHP Code:
       if ( nBarState == BARSTATE_NEWBAR ) {
            
    debugPrintln("Index: " nBarIndex " nRSI_Sig: " nRSI_Sig " nLastRSI: " nLastRSI " nCurrentRSI: " nCurrentRSI);
            if ( 
    nRSI_Sig == ) {
                
    setBarFgColor(Color.RGB(0,2550), 0);
                
    debugPrintln("Index: " nBarIndex " Green ");
            }
            if ( 
    nRSI_Sig == -) {
                
    setBarFgColor(Color.RGB(255,00), 0);
                
    debugPrintln("Index: " nBarIndex " Red ");
            }
       } 
    nRSI_Sig is set prior to this in a section of code that is restricted by a check for NEWBAR ( if ( nBarState == BARSTATE_NEWBAR ) ).

    The issue is that in RT the line is always Blue (the default color), even though nRSI_Sig is 1 or -1 most of the time, and I get the correct color printed on the Formula Output screen:

    PHP Code:
    Index: -3 nRSI_Sig: -1 nLastRSI66.38295566980304 nCurrentRSI68.40682690587413
    Index
    : -3 Red 
    Index
    : -2 nRSI_Sig1 nLastRSI68.40682690587413 nCurrentRSI71.8209949644798
    Index
    : -2 Green 
    Index
    : -1 nRSI_Sig1 nLastRSI71.8209949644798 nCurrentRSI72.76165327122916
    Index
    : -1 Green 
    Index
    0 nRSI_Sig1 nLastRSI72.76165327122916 nCurrentRSI71.6848261373386
    Index
    0 Green 
    All historical data is displayed as I would expect (red or green line) and the value of the line is always correct in either mode. A refresh of the chart will display the line color correctly.

    If I remove the NEWBAR check in the section of code above, it all displays correctly, even in RT.

    What am I missing?

    Thanks!

    Comment


    • #3
      Thanks Alex...your solution would work, and your comments allowed me to realize where my logic went wrong... I forgot that I was returning the lines value for each tick. Shows what happens to my brain after coding all day.
      Garth

      Comment


      • #4
        Garth
        You are most welcome
        Alex


        Originally posted by gspiker
        Thanks Alex...your solution would work, and your comments allowed me to realize where my logic went wrong... I forgot that I was returning the lines value for each tick. Shows what happens to my brain after coding all day.

        Comment

        Working...
        X