Announcement

Collapse
No announcement yet.

Help with Painting Price bars

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

  • Help with Painting Price bars

    I have an efs study that paints price bars purely based on price action (no indicators). When the current bar makes a higher high than the previous bar, it should paint green, if it makes a lower low, it should paint red. If not (like an inside bar), paint it grey.

    The thing is: it doesn't load properly. I changed it because it used to color based on every tick. I added a condition to paint it only on every new bar, but now it doesn't really change the color until I reload the efs.

    Can anyboyd help?

    Here it is:
    function preMain() {
    setPriceStudy(true);
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.lightgrey);

    setStudyTitle("3BR c");

    }


    function main() {

    if (getBarState() == BARSTATE_NEWBAR) {

    if(low(-1) < low(-2) && high(-2) > high(-1) && low() > low(-1) ) {
    if(close() > high(-1) || high() > high(-1) && !Strategy.isLong() ) {
    Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
    }
    else
    {
    if(close() > low(-1) || low() > low(-1) && Strategy.isLong() ) { //* inside bar
    Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.THISBAR);
    }
    }

    }
    else
    {
    if(high() > high(-1) && !Strategy.isLong()) {

    if(low() <= low(-1)) { //* if engulfing candle (NOTE last change: made <= instead of < )
    if(close() > open()) { //* removed '=' sign from '>='
    Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
    }
    else
    {
    Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
    }
    }
    else
    {
    //* if HH/HL candle
    Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
    }
    }
    else
    {
    if(high(-2) < high(-1) && low(-2) < low(-1) && high() < high(-1) ) {
    if(close() < low(-1) || low() < low(-1) && !Strategy.isShort() ) {
    Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
    }
    else
    {
    if(close() > low(-1) || low() > low(-1) && Strategy.isShort() ) { //* inside bar
    Strategy.doCover("Cover Short", Strategy.MARKET, Strategy.THISBAR);
    }
    }
    }
    else
    {
    if(low() < low(-1) && !Strategy.isShort()) {

    if(high() >= high(-1)) { //* if engulfing candle (NOTE last change made >= instead of > )
    if(close() < open()) { //* removed '=' sign from '<='
    Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
    }
    else
    {
    Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
    }
    }
    else
    {
    //* if LL/LH candle
    Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
    }
    }
    }
    }
    }
    } //if BARSTATE_NEWBAR
    ;


    if(Strategy.isLong()){
    setPriceBarColor(Color.lime);
    }
    else
    {
    if(Strategy.isShort()){
    setPriceBarColor(Color.red);
    }
    else
    //not Long or Short = default color: grey
    {
    setPriceBarColor(Color.lightgrey);
    }
    }
    ;

    return;
    }

  • #2
    If it helps, here is an example chart with my efs - it hasn't been reloaded in a while:
    Attached Files

    Comment


    • #3
      Here's the same chart after the efs was reloaded:
      Attached Files

      Comment


      • #4
        Just bringing this up to the top... Can somebody help me fix this efs please?

        Thanks.

        Comment


        • #5
          Hello wavetrader,

          The central problem I see with your code is that your trying to use a back testing formula for real time analysis. The Strategy object is intended for analyzing historical bars only. What you need to do is rewrite your formula and use global variables to track positions and signals. At the bottom of your formula you'll replace the coloring routine with something like the following.

          PHP Code:

          if(vPosition == "long") {
                  
          setPriceBarColor(Color.lime);
          } else if(
          vPosition == "short") {
                  
          setPriceBarColor(Color.red);
          } else { 
          //not Long or Short = default color: grey
                  
          setPriceBarColor(Color.lightgrey);

          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


          • #6
            Painted Price Bars

            Is there an EFS available that will paint the price bars when the price bar is an inside bar?

            Comment


            • #7
              Hello hipp,

              This could be developed using the Formula Wizard. Have you tried this route? There was also a recent formula developed to find breakouts from inside bars here. You could make a few modifications to this formula as well to get what you need.
              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