If I use an interval other than 1 minute how do I ensure that I close positions at 16:15 (I'm working with emini's). With 1 minute interval, I can look at each minute and close at 16:14. What if I use 30 minutes?
Announcement
Collapse
No announcement yet.
How to exit position at EOD or MOC?
Collapse
X
-
Try this...
You would have to do something like the following....
PHP Code:var vHour;
var vMin;
var vSec;
var vDay;
var vMonth;
var vEndHour = 13;
var vEndMin = 14;
function main() {
var vTime = new Date();
//---------------------------------------------------
// Get Time Variables
vTime = getValue("Time", 0);
vHour = vTime.getHours();
vMin = vTime.getMinutes();
vSec = vTime.getSeconds();
vDay = vTime.getDate();
vMonth = vTime.getMonth() +1;
var currentChartInterval = parseFloat(getInterval());
// Calculate "if needed MOC on this bar".
var TempHour = vHour;
var TempMin = vMin+currentChartInterval;
if (TempMin >= 60) {
TempHour ++;
TempMin -= 60;
}
if ((TempHour > EndHour) || ((TempHour == EndHour) && (TempMin >= EndMin)) {
// Issue MOC Order on the CLOSE of this bar
if (Strategy.isLong()) {
Strategy.doSell("MOC", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, close()):
}
if (Strategy.isShort()) {
Strategy.doCover("MOC", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, close()):
}
}
}
Brad Matheny
eSignal Solution Provider since 2000
Comment