Night_and_Day.efs
File Name: Night_and_Day.efs
Description:
Daytrading With Night Volume by Domenico D'Errico
Formula Parameters:
Night_and_Day.efs
- Length: 5
- Night Session Open: 23:00
- Day Session Open: 08:30
- Day Session Close: 15:00
- Volume Ratio: 1
- Strategy Type: First Hour BreakOut
Notes:
The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.
Download File:
Night_and_Day.efs
EFS Code:
/********************************* Provided By: eSignal (Copyright c eSignal), a division of Interactive Data Corporation. 2016. 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: Daytrading With Night Volume by Domenico D'Errico Version: 1.00 04/12/2017 Formula Parameters: Default: Length 5 Night Session Open 23:00 Day Session Open 08:30 Day Session Close 15:00 Volume Ratio 1 Strategy Type First Hour BreakOut Notes: The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com. **********************************/ var fpArray = new Array(); function preMain(){ setPriceStudy(false); setColorPriceBars(true); setDefaultPrecision(0,0); setDefaultPriceBarColor(Color.RGB(0,148,255)); setStudyTitle("Night&Day"); setPlotType(PLOTTYPE_HISTOGRAM); setCursorLabelName("CumVol"); var x=0; fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER); with(fpArray[x++]){ setName("Length"); setDefault(5); setLowerLimit(1); } fpArray[x] = new FunctionParameter("NightO", FunctionParameter.STRING); with(fpArray[x++]){ setName("Night Session Open"); setDefault("23:00"); } fpArray[x] = new FunctionParameter("DayO", FunctionParameter.STRING); with(fpArray[x++]){ setName("Day Session Open"); setDefault("08:30"); } fpArray[x] = new FunctionParameter("DayC", FunctionParameter.STRING); with(fpArray[x++]){ setName("Day Session Close"); setDefault("15:00"); } fpArray[x] = new FunctionParameter("VolRatio", FunctionParameter.NUMBER); with(fpArray[x++]){ setName("Volume Ratio"); setDefault(1); setLowerLimit(1); } fpArray[x] = new FunctionParameter("StrategyType", FunctionParameter.STRING); with(fpArray[x++]){ setName("Strategy Type"); setDefault("First Hour BreakOut"); addOption("First Hour BreakOut"); addOption("Night & Day"); } } var bInit = false; var bVersion = null; var xHigh = null; var xLow = null; var xClose = null; var xVol = null; var aNightVol = null; var nCurrNightVol = 0; var nLastVol = 0; var nNightSessionOpen = null; var nDaySessionOpen = null; var nDaySessionClose = null; var nFirstHourHighest = null; var nFirstHourLowest = null; function main(Length, NightO, DayO, DayC, StrategyType){ if (bVersion == null) bVersion = verify(); if (bVersion == false) return; if (getBarState() == BARSTATE_ALLBARS){ bInit = false; } if (!bInit){ xHigh = high(); xLow = low(); xClose = close(); xVol = volume(); aNightVol = new Array(Length, 0); nFirstHourHighest = null; nFirstHourLowest = null; nCurrNightVol = 0; nLastVol = 0; nNightSessionOpen = TimeStringToNumber(NightO); nDaySessionOpen = TimeStringToNumber(DayO); nDaySessionClose = TimeStringToNumber(DayC); bInit = true; } var nHigh = xHigh.getValue(0); var nLow = xLow.getValue(0); var nClose = xClose.getValue(0); var barTime = hour(0) * 100 + minute(0); if (getBarState() == BARSTATE_NEWBAR){ if (barTime == nNightSessionOpen) nCurrNightVol = 0; nLastVol = nCurrNightVol; } nCurrNightVol = nLastVol + xVol.getValue(0); if (barTime == nDaySessionOpen){ for (var i = Length - 1; i > 0; i--){ aNightVol[i] = aNightVol[i - 1]; } aNightVol[0] = nCurrNightVol; nFirstHourLowest = nLow; } if (barTime >= nDaySessionOpen && barTime <= TimeMath(nDaySessionOpen, "add", 60)){ if (nHigh > nFirstHourHighest) nFirstHourHighest = nHigh; if (nLow < nFirstHourLowest) nFirstHourLowest = nLow; setPriceBarColor(Color.red); } if (getCurrentBarIndex() != 0){ if(barTime >= TimeMath(nDaySessionOpen, "add", 60 + parseInt(getInterval())) && barTime < TimeMath(nDaySessionClose, "sub", parseInt(getInterval()))){ if (!Strategy.isInTrade()){ if (StrategyType == "First Hour BreakOut"){ if (nHigh > nFirstHourHighest){ Strategy.doLong("First Hour BreakUP", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT); nFirstHourHighest = 0; } else if (nLow < nFirstHourLowest){ Strategy.doShort("First Hour BreakDN", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT); nFirstHourLowest = 0; } } else if (StrategyType == "Night & Day" && aNightVol[0] > AvgVolume(aNightVol, Length)){ if (nHigh > nFirstHourHighest){ Strategy.doLong("N & D BreakUP", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT); nFirstHourHighest = 0; } else if (nLow < nFirstHourLowest){ Strategy.doShort("N & D BreakDN", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT); nFirstHourLowest = 0; } } } } if (barTime >= TimeMath(nDaySessionClose, "add", parseInt(getInterval()))){ if (Strategy.isLong()) Strategy.doSell("Exit BreakUP", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT); else if (Strategy.isShort()) Strategy.doCover("Exit BreakDN", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT); } } if (barTime < nDaySessionOpen) setPriceBarColor(Color.black); else if (barTime > nDaySessionClose) setPriceBarColor(Color.grey); return nCurrNightVol; } function TimeStringToNumber(timeStr){ var tempTime = new Array(); tempTime = timeStr.split(':',2); if (tempTime[0][0] == '0') tempTime[0] = tempTime[0].substr(1); if (tempTime[1][0] == '0') tempTime[1] = tempTime[1].substr(1); tempTime = (parseInt(tempTime[0]) * 100) + parseInt(tempTime[1]); return tempTime; } function AvgVolume(aVolume, Length){ var sumVol = 0; for (var i = 0; i < Length; i++){ sumVol += aVolume[i]; } return (sumVol / Length); } function TimeMath(timeVal, type, value){ if (type == "add"){ timeVal += (value % 60 + Math.floor(value / 60) * 100); } else if (type == "sub"){ timeVal -= Math.floor(value / 60) * 100; if (value % 60 > timeVal % 100) timeVal -= (100 - (60 - value % 60)); } return timeVal; } function verify(){ var b = false; if (getBuildNumber() < 3742){ drawTextAbsolute(5, 35, "This study requires version 12.1 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; }