strStochCrsvr.efs
EFSLibrary - Discussion Board
File Name: strStochCrsvr.efs
Description:
Stochastic Crossover
Formula Parameters:
- nLength : 7
- nSmoothing : 1
- nDLength : 3
- Overbought : 80
- Oversold : 20
Notes:
This back testing strategy generates a long trade at the Open of the following bar when the %K line crosses below the %D line and both are above the Overbought level.
It generates a short trade at the Open of the following bar when the %K line crosses above the %D line and both values are below the Oversold level.
Download File:
strStochCrsvr.efs
EFS Code:
/********************************* Provided By: eSignal (Copyright c eSignal), a division of Interactive Data Corporation. 2009. 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: Stochastic Crossover Version: 1.0 05/12/2009 Formula Parameters: Default: nLength 7 nSmoothing 1 nDLength 3 Overbought 80 Oversold 20 Notes: This back testing strategy generates a long trade at the Open of the following bar when the %K line crosses below the %D line and both are above the Overbought level. It generates a short trade at the Open of the following bar when the %K line crosses above the %D line and both values are below the Oversold level. **********************************/ var fpArray = new Array(); var bInit = false; function preMain() { setPriceStudy(true); setColorPriceBars(true); setStudyTitle("Stochastic Crossover"); setDefaultPriceBarColor(Color.black); var x = 0; fpArray[x] = new FunctionParameter("nLength", FunctionParameter.NUMBER); with(fpArray[x++]) { setLowerLimit(1); setDefault(7); } fpArray[x] = new FunctionParameter("nSmoothing", FunctionParameter.NUMBER); with(fpArray[x++]) { setLowerLimit(1); setDefault(1); } fpArray[x] = new FunctionParameter("nDLength", FunctionParameter.NUMBER); with(fpArray[x++]) { setLowerLimit(1); setDefault(3); } fpArray[x] = new FunctionParameter("Oversold", FunctionParameter.NUMBER); with(fpArray[x++]) { setLowerLimit(1); setDefault(20); } fpArray[x] = new FunctionParameter("Overbought", FunctionParameter.NUMBER); with(fpArray[x++]) { setLowerLimit(1); setDefault(80); } } var xStochK = null; var xStochD = null; function main(nLength, nSmoothing, nDLength, Oversold, Overbought) { var nBarState = getBarState(); if (nBarState == BARSTATE_ALLBARS) { if (nLength == null) nLength = 7; if (nSmoothing == null) nSmoothing = 1; if (nDLength == null) nDLength = 3; if (Overbought == null) Overbought = 80; if (Oversold == null) Oversold = 20; } if (bInit == false) { xStochK = stochK(nLength, nSmoothing, nDLength); xStochD = stochD(nLength, nSmoothing, nDLength); bInit = true; } if(getCurrentBarIndex() == 0) return; var vFast = xStochK.getValue(0); var vSlow = xStochD.getValue(0); if(vFast == null || vSlow == null) return; if(vFast < vSlow && vFast > Overbought && vSlow > Overbought && !Strategy.isLong()) Strategy.doLong("Long", Strategy.MARKET, Strategy.NEXTBAR); if(vFast >= vSlow && vFast < Oversold && vSlow < Oversold && !Strategy.isShort()) Strategy.doShort("Short", Strategy.MARKET, Strategy.NEXTBAR); if(Strategy.isLong()) setPriceBarColor(Color.lime); else if(Strategy.isShort()) setPriceBarColor(Color.red); return; }