im backtesting a program and i need to have the positions closed out at 4:00. i tried a gethour and == 1600 then cover/sell but that doesnt work anyone know what i need to do?
Announcement
Collapse
No announcement yet.
close positions at end of day
Collapse
X
-
couldn't get it to work
i used that code and adjusted it a little and it didn't close the trade in backtesting....any idea what im doing wrong??
else if (
(getHour()*100)+getMinute()==1600&&Strategy.isLong ()==true)
onAction5();
function onAction5() {
Strategy.doSell("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
vLastAlert = 5;
Comment
-
Here is how I handle it..
var vStartHour = 6;
var vStartMin = 32;
var vEndHour = 12;//9;
var vEndMin = 58;
var vHour;
var vMin;
var vSec;
var vDay;
var vMonth;
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;
// Within trading times..
if (((vHour > vStartHour) && (vHour < vEndHour)) || ((vHour == vStartHour) && (vMin >= vStartMin)) || ((vHour == vEndHour) && (vMin <= vEndMin)) ) { //Execute New Stop
}
// End within trading times
//---------------------------------------------------
// Close any OPEN trades after ENDTIME ....
if ( ((vHour > vEndHour)) || ((vHour == vEndHour) && (vMin > vEndMin)) ) { //Close all OPEN Trades
if (Strategy.isInTrade()) {
if ((Strategy.isShort() == true)) {
Strategy.doCover("Close Short EOD", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, close());
drawShapeRelative(0, low() +1.25, Shape.UPARROW, null, Color.black, Shape.ONTOP, getValue("rawtime") + "EOD");
OpenContracts = 0;
}
if ((Strategy.isLong())) {
Strategy.doSell("Close Long EOD", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, close());
drawShapeRelative(0, high() +1.25, Shape.DOWNARROW, null, Color.black, Shape.ONTOP, getValue("rawtime") + "EOD");
OpenContracts = 0;
}
}
} // END CLOSE OPEN TRADES
}Brad Matheny
eSignal Solution Provider since 2000
Comment
Comment