Announcement

Collapse
No announcement yet.

EMA & MA Crossover

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • EMA & MA Crossover

    File Name: str_ma_ema_crsv.efs

    Description:
    EMA & MA Crossover

    Formula Parameters:
    Length MA: 10
    Length EMA: 10


    Notes:
    The Moving Average Crossover trading strategy is possibly the most popular
    trading strategy in the world of trading. First of them were written in the
    middle of XX century, when commodities trading strategies became popular.
    This strategy is a good example of so-called traditional strategies.
    Traditional strategies are always long or short. That means they are never
    out of the market. The concept of having a strategy that is always long or
    short may be scary, particularly in todayÒs market where you donÒt know what
    is going to happen as far as risk on any one market. But a lot of traders
    believe that the concept is still valid, especially for those of traders who
    do their own research or their own discretionary trading.
    This version uses crossover of moving average and its exponential moving average.


    Download File:
    str_ma_ema_crsv.efs



    EFS Code:
    PHP Code:
    /*********************************
    Provided By:  
        eSignal (Copyright c eSignal), a division of Interactive Data 
        Corporation. 2008. All rights reserved. This sample eSignal 
        Formula Script (EFS) is for educational purposes only and may be 
        modified and saved under a new file name.  eSignal is not responsible
        for the functionality once modified.  eSignal reserves the right 
        to modify and overwrite this EFS file with each new release.


    Description:        
        EMA & MA Crossover

    Version:            1.0  10/14/2008

    Notes:
        The Moving Average Crossover trading strategy is possibly the most popular
        trading strategy in the world of trading. First of them were written in the
        middle of XX century, when commodities trading strategies became popular.
        This strategy is a good example of so-called traditional strategies. 
        Traditional strategies are always long or short. That means they are never 
        out of the market. The concept of having a strategy that is always long or 
        short may be scary, particularly in todayÒs market where you donÒt know what 
        is going to happen as far as risk on any one market. But a lot of traders 
        believe that the concept is still valid, especially for those of traders who 
        do their own research or their own discretionary trading. 
        This version uses crossover of moving average and its exponential moving average. 
        
    Formula Parameters:                     Default:
        Length MA                               10
        Length EMA                              10
    **********************************/

    var fpArray = new Array();
    var 
    bInit false;

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("MA Strategy"); 
        
    setCursorLabelName("MA"0);
        
    setDefaultBarFgColor(Color.red0);
        
    setCursorLabelName("EMA (MA)"1);
        
    setDefaultBarFgColor(Color.blue1);
        
    setColorPriceBars(true);
        
    setDefaultPriceBarColor(Color.grey);

        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("LengthMA"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Length MA");        
            
    setLowerLimit(1);        
            
    setDefault(10);
        }
        
    fpArray[x] = new FunctionParameter("LengthEMA"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Length EMA");        
            
    setLowerLimit(1);        
            
    setDefault(10);
        }
    }

    var 
    xEMA null;
    var 
    xMA null;

    function 
    main(LengthMALengthEMA) {
    var 
    nState getBarState();

        if (
    nState == BARSTATE_ALLBARS) {
            if(
    LengthMA == nullLengthMA 10;
            if(
    LengthEMA == nullLengthEMA 10;
        }

        if (
    bInit == false) {
            
    xMA sma(LengthMA);
            
    xEMA ema(LengthEMAxMA);
            
    bInit true;
        }

        if (
    getCurrentBarCount() < Math.max(LengthMALengthEMA)) return;

        if (
    getCurrentBarIndex() == 0) return;

        if(
    xMA.getValue(-1) > xEMA.getValue(-1) && !Strategy.isLong()) {
            
    Strategy.doLong("Long"Strategy.MARKETStrategy.THISBAR);
        }        
                    
        if(
    xMA.getValue(-1) < xEMA.getValue(-1) && !Strategy.isShort())
            
    Strategy.doShort("Short"Strategy.MARKETStrategy.THISBAR);
        
        if(
    Strategy.isLong())
            
    setPriceBarColor(Color.lime);
        if(
    Strategy.isShort())
            
    setPriceBarColor(Color.red);

        return new Array(
    xMA.getValue(0), xEMA.getValue(0));

Working...
X