new user and can't seem to work with the time properly. just need to see a sample of it's use and i should be fine.
Announcement
Collapse
No announcement yet.
can anyone volunteer code for closing out at all trades at the end of the day, i'm a
Collapse
X
-
asherisaac
Here is an example. This will close all open trades if a bar has a timestamp >=1600. It will use the Close of the bar prior to the cutoff time as the closing price
Alex
PHP Code:if((getHour()*100)+getMinute()>=1600){
if(Strategy.isLong()==true){
Strategy.doSell("Closeout Long(s)",Strategy.STOP,Strategy.THISBAR,Strategy.ALL,close(-1));
}
if(Strategy.isShort()==true){
Strategy.doCover("Closeout Short(s)",Strategy.STOP,Strategy.THISBAR,Strategy.ALL,close(-1));
}
}
-
asherisaac
You may want to add another condition in case you do not have a bar with a time stamp >= [your time]. This could happen due to the Time Template used or on a short day or with thinly traded products.
Below is the revised condition which also checks for a change of date
Alex
PHP Code:if((getHour()*100)+getMinute()>=1600||getDay()!=getDay(-1)){
if(Strategy.isLong()==true){
Strategy.doSell("Closeout Long(s)",Strategy.STOP,Strategy.THISBAR,Strategy.ALL,close(-1));
}
if(Strategy.isShort()==true){
Strategy.doCover("Closeout Short(s)",Strategy.STOP,Strategy.THISBAR,Strategy.ALL,close(-1));
}
}
Comment
Comment