Hi, I am new to coding but have made an efs script that was working fine.
I wanted it to only initiate trades during regular trading hours and close out any open position by the end of the day.
I did this by declaring a time variable:
var time = (getHour()*100 + getMinute());
Then adding this code to the main function where the rest of the trading instructions are:
if (Strategy.isLong() == true && (time >= 1600 || time <= 930))
{
Strategy.doSell("CoverLT",Strategy.MARKET,Strategy .THISBAR);
}
This worked perfectly fine and functioned the way i wanted it to.
After this I added this line to my code with the rest of my entry condition right under the line Strategy.doLong("Long Signal", Strategy.MARKET, Strategy.NEXTBAR);:
Strategy.setStop(close(0)- 0.1);
After I added this I wanted it to have a 10c stop from the close of the entry candle, and exit no matter what by 16:00.
Now when I run the back test it holds position over night and many trades are over a 10c loss......
I have tried a few variations and nothing I do seems to work. I am pretty new to coding so I could be looking over something simple.
Any help here would be greatly appreciated.
I wanted it to only initiate trades during regular trading hours and close out any open position by the end of the day.
I did this by declaring a time variable:
var time = (getHour()*100 + getMinute());
Then adding this code to the main function where the rest of the trading instructions are:
if (Strategy.isLong() == true && (time >= 1600 || time <= 930))
{
Strategy.doSell("CoverLT",Strategy.MARKET,Strategy .THISBAR);
}
This worked perfectly fine and functioned the way i wanted it to.
After this I added this line to my code with the rest of my entry condition right under the line Strategy.doLong("Long Signal", Strategy.MARKET, Strategy.NEXTBAR);:
Strategy.setStop(close(0)- 0.1);
After I added this I wanted it to have a 10c stop from the close of the entry candle, and exit no matter what by 16:00.
Now when I run the back test it holds position over night and many trades are over a 10c loss......
I have tried a few variations and nothing I do seems to work. I am pretty new to coding so I could be looking over something simple.
Any help here would be greatly appreciated.
Comment