I have been searching this BB for days now and found many great ideas from the posts, however I am still having some difficulties with the EFS that I have cobbled together. I am trying to get the EFS to EXIT all trades at the end of the day, but the present version still holds some trades overnight. Also, I have a stop loss set at +/- 10 points but the EFS takes some of the stop losses, and at other times goes right past it. Any ideas on how to rectify these issues would be greatly appreciated. I based the EFS on the formula wizzard and then modified it (with little coding knowledge on my part) in the editor. Thanks in advance.
Announcement
Collapse
No announcement yet.
EOD exit and Stop Loss
Collapse
X
-
Try and start off with something simple, get that working then take small steps to build on it, checking along the way. e.g.
if (Strategy.isInTrade() == false) {
}
else if (Strategy.isLong() == true) {
}
else if (Strategy.isShort() == true) {
}
I'll try and help you if you get stuck on a given step.Paul Williams
Strategy & Applications
www.futurenets.co.uk
-
Solution...
You need an ENDTIME variable and something that tracks the bar time to exit at that time...
Here is a sample..
The user variables control the time to allow start of trading and end of trading.
PHP Code:// user variables.
var vStartHour = 6;
var vStartMin = 30;
var vEndHour = 13;
var vEndMin = 13;
// system variables
var vHour;
var vMin;
var vSec;
var vDay;
var vMonth;
function main() {
//---------------------------------------------------
// Get Time Variables
//---------------------------------------------------
var vTime = new Date();
vTime = getValue("Time", 0);
vHour = vTime.getHours();
vMin = vTime.getMinutes();
vSec = vTime.getSeconds();
vDay = vTime.getDate();
vMonth = vTime.getMonth() +1;
if (((vHour > vStartHour) && (vHour < vEndHour)) || ((vHour == vStartHour) && (vMin >= vStartMin)) || ((vHour == vEndHour) && (vMin <= vEndMin)) ) {
//Allow normal entries/stops/profit targets
Buy()...
Sell()...
}
// End of DAY exits.
if ((vHour > vEndHour) || ((vHour == vEndHour) && (vMin > vEndMin)) ) { //Execute EOD Orders
if (Strategy.isLong()) {
drawShapeRelative(0, high()+0.25, Shape.UPARROW, null, Color.black, Shape.ONTOP, BLBarOffset+"EODL");
Strategy.doSell("EOD Long Exit", Strategy.LIMIT, Strategy.THISBAR, Exit1Contracts, open());
}
if (Strategy.isShort()) {
drawShapeRelative(0, low()-0.25, Shape.DOWNARROW, null, Color.black, Shape.ONTOP, BLBarOffset+"EODS");
Strategy.doCover("EOD Short Exit", Strategy.LIMIT, Strategy.THISBAR, Exit1Contracts, open());
}
}
}
Brad Matheny
eSignal Solution Provider since 2000
Comment
-
Thanks for the help
Excellent,
Thank you all for the replies. I tried the suggestions and finally got the EOD orders to work on the normal days. Thanks for the help.
Underdog...if you don't mind could you expand on the beginning of day check and function that you use for short trading days?
Thanks in advance.
Comment
-
I just have the EFS check at the beginning of the day if the system is long or short (which would indicate that the EOD exit failed) and then have the system exit at the previous day's closing price. My system doesn't start trading until 30 minutes after the start so there isn't any problem with conflicts (and this only exists in the version for backtesting, not the Dynaorder based real time version). It isn't a very elegant solution but it works so I've kept using it.
Comment
Comment