Hi,
I have need to test a strategy that close an open trade just before (say 17:20 when the session close at 17:30) close of the 5th day.
Do anyone have a code snippet for this?
this should do it:
if CurrentDayOfWeek = 5 and time = 172000 then
sell at market
exitshort at market
endif
When using the example given by nonetheless you have to ensure that the chart you are using the strategy on has a 172000 candle. So you must run it on a TF of 10 minutes or faster.
Thank you
I guess I was a bit unclear about the day of exit. I meant 5th day after entry not day of week.
Do I have to choose a time unit in backtesting that correspond to time? In the this case 1 hour of less?
In this strategy I have only daily bars. Does that mean I can’t solve my need?
@Vonasi: You answered one of my question before I had written it 😉
In this strategy I have only daily bars
Sorry Erike, when you mentioned 17:20, I assumed you were working with a short time frame. I may be wrong but I don’t think you can close in the middle of a daily candle without using MTF
No problems @nonetheless .
I guess I have to read up on MTF. Any suggestions were to start?
There you go (not tested):
Timeframe(Daily,UpdateOnClose)
Once Count = 0
Count = Count + OnMarket
If MyLongConditions and Not OnMarket then
Buy 1 contract at Market
Count = 1
Set Target pProfit 500
Set Stop pLoss 250
Endif
If MyShortConditions and Not OnMarket then
Sellshort 1 contract at Market
Count = 1
Set Target pProfit 500
Set Stop pLoss 250
Endif
//
Timeframe(default)
If Count = 5 and Time = 172000 Then
Sell at Market
Exitshort at Market
Endif
You need to run this strategy from a 10-minute (or lower) chart.