Announcement

Collapse
No announcement yet.

formula assistance

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

  • formula assistance

    hi,
    i'm trying to write a simple formula and am getting hung up. basically, all i'm trying to achieve is:

    var MACD = study.getValue(MACDStudy.MACD);

    if (MACD(-1 //yesterday)) < 0 && (MACD( //current bar)) > 0

    // buy

    If found a good starter script which I'm trying to modify:

    var MACD = study.getValue(MACDStudy.MACD);

    var Signal = study.getValue(MACDStudy.SIGNAL);

    if(Signal < MACD && !Strategy.isLong())

    Strategy.doLong("Long", Strategy.MARKET, Strategy.NEXTBAR);

  • #2
    Hello stvchez,

    If you're having trouble with a formula your are working with, please post it as an attachment and I'll take a look. If you are looking to have a formula built from scratch, I suggest you use the Formula Wizard. Have you tried the Wizard yet?
    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
      i have a working EFS which I'm trying to extend for what I need. here is what i have and i'll comment out the small section I'm trying to extend

      var study = new MACDStudy(13,26, 9, "Close", false);



      function preMain() {

      setPriceStudy(false);

      setColorPriceBars(true);

      setDefaultPriceBarColor(Color.grey);

      setStudyTitle("MACD Strategy");

      setCursorLabelName("MACD", 0);

      setCursorLabelName("SIGNAL", 1);

      setDefaultBarFgColor(Color.blue, 0);

      setDefaultBarFgColor(Color.RGB(192,75,0), 1);

      }



      function main() {

      var MACD = study.getValue(MACDStudy.MACD);

      var Signal = study.getValue(MACDStudy.SIGNAL);

      if(Signal < MACD && !Strategy.isLong())

      /* HERES WHERE I'M TRYING TO EXTEND.

      if (MACD(-1)) < 0 && (MACD > 0)

      in other words... if MACD (one bar back) is less than zero and MACD (current bar) is greater than 0, buy
      */



      Strategy.doLong("Long", Strategy.MARKET, Strategy.NEXTBAR);

      if(Signal > MACD && !Strategy.isShort())

      Strategy.doShort("Short", Strategy.MARKET, Strategy.NEXTBAR);



      if(Strategy.isLong())

      setPriceBarColor(Color.blue);

      else if(Strategy.isShort())

      setPriceBarColor(Color.RGB(192,75,0) );



      return new Array(MACD,Signal);

      }

      Comment


      • #4
        stvchez
        Create another variable in main() to define MACD of one bar ago
        var MACD_1 = study.getValue(MACDStudy.MACD,-1);
        Then you can use that variable in your conditional statement
        if(Signal < MACD && !Strategy.isLong() &&
        MACD_1<0 && MACD >0)
        Strategy.doLong("Long", etc...)

        Hope this helps
        Alex

        Comment

        Working...
        X