2008 Sept: The Midas Touch, Part I

ICE Data Services -

Midas.efs  

EFSLibrary - Discussion Board  

File Name: Midas.efs

Description:
The following study is based on the September 2008 article, The Midas Touch, Part I, by Andrew Cole.

Formula Parameters:

  • Start Date: [Enter date]
  • Start Time: 00:00

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

Download File:
Midas.efs



EFS Code:

/*********************************
Provided By:  
    eSignal (Copyright © eSignal), a division of Interactive Data 
    Corporation. 2007. 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:        The Midas Touch Part I
                    by Andrew Coles, PhD

Version:            1.0  7/11/2008

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

Formula Parameters:                     Default:
Start Date (mm/dd/yyyy)                 1/2/2008
Start Time hh:mm (use 00:00 if Daily)   00:00
**********************************/


function preMain(){
    setPriceStudy(true);
    setStudyTitle("MIDAS")
    setCursorLabelName("MIDAS");
    setDefaultBarFgColor(Color.blue);
    setDefaultBarThickness(1);
    
    var fp1 = new FunctionParameter("StartDate", FunctionParameter.STRING);
        fp1.setName("Start Date (mm/dd/yyyy)");
        fp1.setDefault("1/2/2008");
    var fp2 = new FunctionParameter("StartTime", FunctionParameter.STRING);
        fp2.setName("Start Time hh:mm (use 00:00 if Daily)");
        fp2.setDefault("00:00");
}

var bVersion    = null;
var bInit = false;
var xDay; 
var xMonth;
var xYear;
var xHour;
var xMinute;
var xMP = null;
var xVolume = null;
var CumVol = 0;
var CumVol_1 = 0;
var CumPriceVol = 0;
var CumPriceVol_1 = 0;
var CumVolAtStart = 0;
var CumPriceVolAtStart = 0;
var BarCounter = 0;
var Start = false;

function main(StartDate,StartTime){
    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;    
    if(bInit==false){
        var xStartDate = StartDate.split("/");
        var xStartTime = StartTime.split(":")
        xMonth = xStartDate[0];
        xDay = xStartDate[1];
        xYear = xStartDate[2];
        xHour = xStartTime[0];
        xMinute = xStartTime[1];
        xMP = hl2();
        xVolume = volume();
        bInit = true;
    }
    var nBarState = getBarState();
    if(nBarState==BARSTATE_NEWBAR){
        CumVol_1 = CumVol;
        CumPriceVol_1 = CumPriceVol;
        if(Start==true) BarCounter++;
    }
    var nVolume = xVolume.getValue(0);
    var nMP = xMP.getValue(0);
    if(nVolume==null||nMP==null) return;
    if(getCurrentBarCount()==1){
        CumVol = nVolume;
        CumPriceVol = nMP*nVolume;
    }else{
        CumVol = CumVol_1+nVolume;
        CumPriceVol = CumPriceVol_1+(nMP*nVolume);
    }
    if(Start==false && month(0)==xMonth && day(0)==xDay && year(0)==xYear && hour(0)==xHour && minute(0)==xMinute) {
        CumVolAtStart = CumVol-nVolume;
        CumPriceVolAtStart = CumPriceVol-(nMP*nVolume);
        BarCounter=1;
        Start = true;
    }
    if(BarCounter==0){
        return;
    }else if(BarCounter==1){
        var MIDAS = nMP;
    }else if(BarCounter>1){
        var Denom = CumVol-CumVolAtStart;
        if(Denom==0) Denom = 1;
        var MIDAS = (CumPriceVol-CumPriceVolAtStart)/Denom
    }
    return MIDAS;
}
    
function verify() {
    var b = false;
    if (getBuildNumber() < 779) {
        drawTextAbsolute(5, 35, "This study requires version 8.0 or later.", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "error");
        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "upgrade");
        return b;
    } else {
        b = true;
    }
    return b;
}