Announcement

Collapse
No announcement yet.

Close Position at End of Day

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Close Position at End of Day

    Hello,

    I want to enter positions at 8:30 and close all positions at 15:45, any help with testing for the time in my backtest efs?

    Thank you,

    Patrick

  • #2
    Patrick
    You could do it as in the example below (note that there may be other and better ways to accomplish this)
    Alex


    PHP Code:
    var Trade 1;

    if(
    getHour()*100)+getMinute() >= 830 && (getHour()*100)+getMinute() < 1545)){
    Trade 1;
    }else{
    Trade 0;
    }

    if(
    Trade == && Strategy.isLong() == false && <your conditions>){
    <
    your strategy commands>
    }

    if(
    Trade==0){
        if(
    Strategy.isLong()==true){
            
    Strategy.doSell("Closeout Long",Strategy.LIMIT,Strategy.THISBAR,Strategy.ALL,close(-1));
        }
        if(
    Strategy.isShort()==true){
            
    Strategy.doCover("Closeout Short",Strategy.LIMIT,Strategy.THISBAR,Strategy.ALL,close(-1));
        }

    Comment

    Working...
    X