Announcement

Collapse
No announcement yet.

How to color MAs on a study?!?

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

  • How to color MAs on a study?!?

    Hi. Im new to efs. Im making everything with note pad (as to say hacking up other code). Im using this basic 8/21 crossover ema for backtesting right now. How do I make the 8 ema white and the 21 blue? They are both white right now. Thanks!

    PHP Code:
    var fast = new MAStudy(80"Close"MAStudy.EXPONENTIAL);
    var 
    slow = new MAStudy(210"Close"MAStudy.EXPONENTIAL);

    function 
    preMain() {

        
    setPriceStudy(true);
        
    setColorPriceBars(true);
        
    setDefaultPriceBarColor(Color.white);
    }

    function 
    main() {

        var 
    fast.getValue(MAStudy.MA);
        var 
    slow.getValue(MAStudy.MA);
        
        if(
    == null || == null)
        return;

        if(
    >= && !Strategy.isLong()) 
            
    Strategy.doLong("Crossing Up"Strategy.MARKETStrategy.THISBAR);

        if(
    && !Strategy.isShort())
            
    Strategy.doShort("Crossing Down"Strategy.MARKETStrategy.THISBAR);

        if(
    Strategy.isLong())
            
    setPriceBarColor(Color.blue);
        else if(
    Strategy.isShort())
            
    setPriceBarColor(Color.red);

        return new Array(
    f,s);


  • #2
    Geoff
    You do it by adding a setDefaultBarFgColor() statement for each element of the returned array and assigning it to the appropriate element through the index parameter (see the link for the syntax)
    The enclosed revision of your script shows you how you would implement it.
    Alex

    PHP Code:
    var fast = new MAStudy(80"Close"MAStudy.EXPONENTIAL);
    var 
    slow = new MAStudy(210"Close"MAStudy.EXPONENTIAL);

    function 
    preMain() {

        
    setPriceStudy(true);
        
    setColorPriceBars(true);
        
    setDefaultPriceBarColor(Color.white);
        
    setDefaultBarFgColor(Color.white,0);//colors the first element of the return array
        
    setDefaultBarFgColor(Color.blue,1);//colors the second element of the return array
    }

    function 
    main() {

        var 
    fast.getValue(MAStudy.MA);
        var 
    slow.getValue(MAStudy.MA);
        
        if(
    == null || == null)
        return;

        if(
    >= && !Strategy.isLong()) 
            
    Strategy.doLong("Crossing Up"Strategy.MARKETStrategy.THISBAR);

        if(
    && !Strategy.isShort())
            
    Strategy.doShort("Crossing Down"Strategy.MARKETStrategy.THISBAR);

        if(
    Strategy.isLong())
            
    setPriceBarColor(Color.blue);
        else if(
    Strategy.isShort())
            
    setPriceBarColor(Color.red);

        return new Array(
    f,s);

    Comment


    • #3
      Thx! Worked like a champ

      Comment


      • #4
        Geoff
        You are most welcome and thank you for the feedback
        Alex

        Comment

        Working...
        X