Announcement

Collapse
No announcement yet.

Comparing 3 Moving Averages - on interval data (beginner with eSignal)

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

  • Comparing 3 Moving Averages - on interval data (beginner with eSignal)

    I am a newbie to eSignal and API development, however, I have a programming background. I am trying to create a simple strategy that compares a 6/20/40 interval simple moving average(interval=15 minutes). The strategy is summarized as follows:

    If 6>20>40, I want to go long. I then want to enter in a stop-limit/loss. However, if the signals reverse (40>20>6), I want to close out my long position and go short. And again - I would want to enter a stop limit/loss order. So, there are two ways to exit a position: 1.) the stop/loss limit (that I would like to set) and 2.) indicators reverse.

    I would like to run this from 3/1/2006 to current.

    Thank you for your time. I have reviewed many backtesting samples, but I am having trouble with how to structure my historical data set (again, I'm a new eSignal user), and what form my output will take. My sample programs are only running over 1 day of data (I'm sure this has to do with the chart that I run my code against - in eSignal).

    Any help/guidance to get started with this and process of how to set this test up within eSignal -- would be greatly appreciated.

  • #2
    Hello petersg,

    You should start with our Guide to Developing EFS Strategies. Strategies also refers to back testing formulas. In EFS the object used to pass trade information to the Strategy Analyzer is the Strategy Object. In your EFS, you will use the Moving Average Series functions to establish your moving average studies. There are some code examples there as well to show you how to reference the values that you will use in your conditional statements. The link to the Strategy Object will give you the syntax for how to submit stop/limit orders. In your EFS, for the stop trades, you'll want to track that price level with a global var and have a section above your entry logic to look for a stop. To run the test from a specified date, you can control that with the Time Template settings, which would be easiest. You could also add a Function Parameter that would allow you to enter a date the the formula would check against before allow the rest of main() to evaluate. You can reference each bar's date and time info with the Series Functions, day(), month(), hour(), minute(), second() etc.

    Give it a go and if you run into specific problems, post your code and questions here and we'll help guide you through it.
    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
      Simple MA cross-over strategy with stop-limit/loss

      I seem to be having trouble with entering a stop-loss and validating my intervals -- with my simple moving average strategy (6-step, 20-step, 45-step) -- step is defined as a 15-minute interval. My basic logic is as follows (I'm trying a contrarian strategy):

      When the 45>20 & 20>6, I want to enter long, and when 6>20 & 20>45, I want to close out my long and enter short. However, I want to put in a stop-loss with my strategy (I want my stop-loss to be 10 points -- totaling $500). I don't know where to put that in my code. My code is below (I'm a beginner, so I'm not confident my code even reflects my strategy above). Thank you in advance for your help.

      PHP Code:
      var fast = new MAStudy(60"Close"MAStudy.SIMPLE);
      var 
      medium = new MAStudy(200"Close"MAStudy.SIMPLE);
      var 
      slow = new MAStudy(400"Close"MAStudy.SIMPLE);

      function 
      preMain() {
          
      setPriceStudy(true);
          
      setColorPriceBars(true);
          
      setDefaultPriceBarColor(Color.black);

      }

      function 
      main() {
          var 
      fast.getValue(MAStudy.MA);
          var 
      medium.getValue(MAStudy.MA);
          var 
      slow.getValue(MAStudy.MA);
          
          if(
      == null || == 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.lime);
          else if(
      Strategy.isShort())
              
      setPriceBarColor(Color.red);
          return new Array(
      f,m,s); 

      Comment


      • #4
        peterstg
        In this and this post you can find two basic examples of a moving average strategy that also sets the profit and loss stops when entering a trade.
        Also the Guide to Developing EFS Strategies that Jason mentioned in his reply contains a section (complete with sample code) on setting targets and stops
        Alex

        Comment


        • #5
          peterstg,

          I would be in shock and awe if the system you are trying to develop will bear anything useful. Moving average systems that rely on crosses for signals are not worth your valuable time.

          Instead, look into what PRICE is doing in RELATION to the moving averages that you're interested in. It's okay that you want a series of moving averages to be in a sequential ordering before looking for a signal, but don't focus on the crossing of moving averages for an actual buy/sell signal.

          Think about it. Isn't it counterintuitive to expect that, in the long run, a lagging indicator crossing another lagging indicator is going to lead anywhere but a result that lags???

          Price action + market internals bias + good money/risk management is the ticket laddy.

          Comment

          Working...
          X