I am trying to add the code necessary to exit all my trades at the end of Friday. I thought it would be easy but I can´t make it work. This is what I tried…
IF ONMARKET AND CURRENTDAYOFWEEK = 5 AND CURRENTTIME = 230000 THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
I´ve been trying to find it in the forum but no way
Some help please.
Thanks in advance
You almost had it right.
if opendayofweek = 5 and openhour >= 22 and openminute >= 55 then
sig=1
else
sig=0
endif
The currenttimeof… constants cause PRT to act one bar later. Using opentimeof… fixes this.
How do I implement this into my code?
Where do I put sig=1 and sig=0?
Thanks
You can implement it like this:
if opendayofweek = 5 and openhour >= 22 and openminute >= 55 then
sig=1
else
sig=0
endif
IF sig=1 THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
Thanks this is very helpful. Being in Australia the IG markets are closed on our weekends eg from say Sat at 6am our time. I can certainly use the above to exit before close and ill make sure im set in my own time zone.
What about a way of not entering trades unless a market is open?
I could set something like the above to only enter IF market meets time positions – is that the best way? Or is it even necessary? I wonder what my algos do when the market is closed here? Are they still watching the data and not being able to trade? any ideas?
It’s impossible to trade when the market is closed, so there’s no way to do what is already being done.
Yes except if like the algo to not be “trying” when the market is closed. Maybe start 5 mins after the market here opens. If that makes sense. In case there are rapid changes.
I’ll find one. But I guess I’m asking can I simply find a way to not trade between certain hours?
That makes sense, there you go:
TradingHours = (time >= 090000) AND (time <= 170000) //you may replace TIME with OPENTIME, if you prefer
IF MyLongConditions AND TradingHours THEN
BUY AT Market
ENDIF
thank you for this topic. can you bring the piece of code that says “if the trade is positive” (we only come out if the trade is winning) + resuming the strategy on Monday according to open defined by everyone of course.
Well, I remember having read a similar question months ago, but I can’t find it.
It can easily be done, but you will have to pay spread as any new trade.
To recap, you want to close a profitable trade on Friday night at 22:00 (or any time of your choice), then it must be reopened on Monday (on the first Monday bar or at a time?) no matter conditions as if it were the same trade that had been closed?
Hi Roberto, thank U
It can easily be done, but you will have to pay spread as any new trade. yes sure
To recap, you want to close a profitable trade on Friday night at 22:00 (or any time of your choice), yes exact. no more trading after this close of course.
then it must be reopened on Monday (on the first Monday bar or at a time?) reopening on Monday according to the general conditions listed in the strategy
no matter conditions as if it were the same trade that had been closed? no forget the past, only trading according to the general conditions listed in the strategy
hope is clear, thanks again.
So, it’s just a matter of closing a profitable trade on Friday Night. There you go:
IF OnMarket AND PositionPerf > 0 AND OpenDayOfWeek = 5 AND OpenTime >= 220000 THEN
EXITSHORT AT Market
SELL AT Market
ENDIF
The above snippet will close any open trade, but it won’t prevent orther trades from being opened beyond that date. You need to use another snippet, like this one:
NoTradeHours = (OpenDayOfWeek = 5 AND OpenTime >= 210000)
IF MyLongConditions AND Not NoTradeHours THEN
BUY AT Market
ENDIF
this will prevent your strategy from entering new trades after 21:00 on Friday night.