Announcement

Collapse
No announcement yet.

2007 Feb: Anticipating Moving Average Crossovers by Dimitris Tsokakis

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

  • 2007 Feb: Anticipating Moving Average Crossovers by Dimitris Tsokakis

    File Name: SMA_CrossPredictor.efs

    Description:
    This study is based on the February 2007 article, Anticipating Moving Average Crossovers, by Dimitris Tsokakis.

    Formula Parameters:
    Fast MA Periods: 20
    Slow MA Periods: 30


    Notes:
    The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.

    Download File:
    SMA_CrossPredictor.efs



    EFS Code:
    PHP Code:
    /***************************************
    Provided By : eSignal (c) Copyright 2006
    Description:  Anticipating Moving Average Crossovers 
                  by Dimitris Tsokakis

    Version 1.0  12/05/2006

    Notes:
    * Feb 2007 Issue of Stocks and Commodities Magazine
    * Study requires version 8.0 or later.


    Formula Parameters:                     Default:
    Fast MA Periods                         20
    Slow MA Periods                         30
    *****************************************************************/

    function preMain() {
        
    setStudyTitle("SMA Cross Predictor ");
        
    setShowTitleParameters(false); 
        
    setCursorLabelName("Close"0);
        
    setCursorLabelName("Fast MA"1);
        
    setCursorLabelName("Slow MA"2);
        
    setCursorLabelName("TC"3);
        
        
    setDefaultBarFgColor(Color.black0);
        
    setDefaultBarFgColor(Color.blue1);
        
    setDefaultBarFgColor(Color.red2);
        
    setDefaultBarFgColor(Color.magenta3);
        
        
    setDefaultBarThickness(20);
        
    setDefaultBarThickness(11);
        
    setDefaultBarThickness(12);
        
    setDefaultBarThickness(23);
        
        
    setDefaultFont("Arial"11);

        var 
    fp1 = new FunctionParameter("MAlen1"FunctionParameter.NUMBER);
            
    fp1.setName("Fast MA Periods");
            
    fp1.setLowerLimit(2);
            
    fp1.setDefault(20);
        var 
    fp2 = new FunctionParameter("MAlen2"FunctionParameter.NUMBER);
            
    fp2.setName("Slow MA Periods");
            
    fp2.setLowerLimit(2);
            
    fp2.setDefault(30);
    }

    // Global Variables
    var bVersion  null;    // Version flag
    var bInit     false;   // Initialization flag

    var xMA1 null;        // fast MA
    var xMA2 null;        // slow MA
    var xTC  null;        // Tomorrow's close


    function main(MAlen1MAlen2) {
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;    

        
    //Initialization
        
    if (bInit == false) {
            
    xMA1 sma(MAlen1);  // fast MA
            
    xMA2 sma(MAlen2);  // slow MA
            
    xTC efsInternal("calcTC"MAlen1MAlen2);
            
    bInit true;
        }

        var 
    nC close(0);
        var 
    nTagID rawtime(0);    
        var 
    nMA1_0 xMA1.getValue(0);
        var 
    nMA1_1 xMA1.getValue(-1);
        var 
    nMA2_0 xMA2.getValue(0);
        var 
    nMA2_1 xMA2.getValue(-1);
        var 
    nTC_0 xTC.getValue(0);
        var 
    nTC_1 xTC.getValue(-1);
        if (
    nMA1_1 == null || nMA2_1 == null || nTC_1 == null) return;
        
        
    // MA-crossover
        
    if (nMA1_0 nMA2_0 && nMA1_1 <= nMA2_1) {
            
    // cross up
            
    drawText("MA"AboveBar2Color.greenText.BOLD|Text.FRAME|Text.CENTER"MA"+nTagID);
            
    drawShape(Shape.UPARROWAboveBar1Color.greennTagID);
        } else if (
    nMA1_0 nMA2_0 && nMA1_1 >= nMA2_1) {
            
    // cross down
            
    drawText("MA"BelowBar2Color.redText.BOLD|Text.FRAME|Text.CENTER"MA"+nTagID);
            
    drawShape(Shape.DOWNARROWBelowBar1Color.rednTagID);
        } else {
            
    removeShape(nTagID);
            
    removeText("MA"+nTagID);
        }
        
        
    // TC cross
        
    if (nTC_0 nC && nTC_1 close(-1)) {
            
    drawShapeRelative(0nTC_0Shape.CIRCLEnullColor.rednull"TC"+nTagID);
        } else if (
    nTC_0 nC && nTC_1 close(-1)) {
            
    drawShapeRelative(0nTC_0Shape.CIRCLEnullColor.greennull"TC"+nTagID);
        } else {
            
    removeShape("TC"+nTagID);
        }
        
        return new Array(
    nCnMA1_0.toFixed(4), nMA2_0.toFixed(4), xTC.getValue(0));
    }

    // TC Globals
    var bInitTC false;
    var 
    xTCMA1 null;
    var 
    xTCMA2 null;

    function 
    calcTC(PfastKslow) {
        
    // k > p
        //TC = Pfast*(Kslow-1) * MA(Kslow-1) - Kslow*(Pfast-1) * MA(Pfast-1)  /  Kslow-Pfast;
        
        
    if (bInitTC == false) {
            
    xTCMA1 sma((Pfast-1));
            
    xTCMA2 sma((Kslow-1))
            
    bInitTC true;
        }
        
        var 
    nTC null;
        var 
    nMAfast xTCMA1.getValue(0);
        var 
    nMAslow xTCMA2.getValue(0);
        if (
    nMAslow == null || nMAfast == null) return;
        
        if (
    Kslow-Pfast == 0) {
            
    nTC = ( (Pfast*(Kslow-1) * nMAslow) - (Kslow*(Pfast-1) * nMAfast) ) /  1;
        } else {
            
    nTC = ( (Pfast*(Kslow-1) * nMAslow) - (Kslow*(Pfast-1) * nMAfast) ) /  (Kslow-Pfast);
        }
        
        return 
    nTC;
    }

    function 
    verify() {
        var 
    false;
        if (
    getBuildNumber() < 779) {
            
    drawTextAbsolute(535"This study requires version 8.0 or later."
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"error");
            
    drawTextAbsolute(520"Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp"
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"upgrade");
            return 
    b;
        } else {
            
    true;
        }
        
        return 
    b;

    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
Working...
X