Announcement

Collapse
No announcement yet.

Price Bars

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

  • Price Bars

    Is it possible to set my price bars on Esignal with Green for Up bars and Red for down bars with 4 specific rules.

    Price Bars are Green when the current close of a price bar is above the Previous Close.

    Price Bars are Red when the Current Close of a price bar is Below the Previous Close.

    If The Previous Price Bar is Green, when the Current Price bar's close is equal to the previous price bar close I want the current price bar to be green.


    If the Previous Price Bar is Red when the Current Price Bar's close is equal to the previous price bar close I want the current price bar to be red.

    Here is a link with a perfect example only the bars that I want Green are black on this site and the other bars are red which is fine but the concept it what Im looking for.

    The Dow Jones or S&P on the homepage below.



    I do not want the current price bar's color changing referencing the current close to the current open of the same price bar I always want the current close referenced and to turn color accordingly to the previous price bar close in any time frame.
    Last edited by vintageus1; 08-12-2006, 08:28 PM.

  • #2
    vintageus1
    The enclosed script - which includes step by step explanations of the logic used - should do what you asked.
    As you can see in the image the bars which have a Close equal to the prior Close maintain the prior bar's color.
    Alex

    PHP Code:
    function preMain(){
        
    setPriceStudy(true);
        
    setStudyTitle("Color PriceBars");
        
    setShowCursorLabel(false);
        
    setColorPriceBars(true);
        
    setDefaultPriceBarColor(Color.black);
    }

    var 
    Color0 Color.black;//variable to store current color and assign intial color
    var Color1 Color.black;//variable to store prior bar color and assign intial color

    function main(){

        if(
    getBarState()==BARSTATE_NEWBAR){//at every new bar
            
    Color1 Color0;//assign to the variable Color1 the last calculated value of Color0
        
    }
        
        if(
    close(0) > close(-1)){//if Close greater than prior Close
            
    Color0 Color.green;//assign to the variable Color0 the color green
        
    }
        if(
    close(0) < close(-1)){//if Close is lesser than prior Close
            
    Color0 Color.red;//assign to the variable Color0 the color red
        
    }
        if(
    close(0) == close(-1)){//if Close is equal to prior Close
            
    if(Color1 == Color.green){//if color at prior bar was green 
                
    Color0 Color.green;//assign to the variable Color0 the color green
            
    }
            if(
    Color1 == Color.red){//if color at prior bar was red 
                
    Color0 Color.red;//assign to the variable Color0 the color red
            
    }
        }
        
    setPriceBarColor(Color0);//paint bar using the variable Color0
        
        
    return;

    Comment

    Working...
    X