EXIT ON WEEKEND

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #27961 quote
    TempusFugit
    Participant
    Veteran

    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

    #27992 quote
    Derek
    Participant
    Veteran

    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.

    TempusFugit, Nicolas and Midlanddave thanked this post
    #48195 quote
    T-rader
    Participant
    Average

    How do I implement this into my code?

    Where do I put sig=1 and sig=0?

     

    Thanks

    #48196 quote
    Nicolas
    Keymaster
    Master

    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
    Midlanddave thanked this post
    #174415 quote
    ausrod
    Participant
    New

    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?

    #174419 quote
    robertogozzi
    Moderator
    Master

    It’s impossible to trade when the market is closed, so there’s no way to do what is already being done.

    #174426 quote
    ausrod
    Participant
    New

    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.

    #174427 quote
    robertogozzi
    Moderator
    Master

    Can you post an example?

    #174437 quote
    ausrod
    Participant
    New

    I’ll find one. But I guess I’m asking can I simply find a way to not trade between certain hours?

    #174439 quote
    robertogozzi
    Moderator
    Master

    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
    Midlanddave thanked this post
    #174481 quote
    bertrandpinoy
    Participant
    Veteran

    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.

    #174485 quote
    robertogozzi
    Moderator
    Master

    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?

    #174487 quote
    bertrandpinoy
    Participant
    Veteran

    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.

    #174489 quote
    robertogozzi
    Moderator
    Master

    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
    bertrandpinoy thanked this post
    #174491 quote
    robertogozzi
    Moderator
    Master

    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.

    bertrandpinoy thanked this post
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

EXIT ON WEEKEND


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 14 replies,
has 3 voices, and was last updated by robertogozzi
4 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/09/2017
Status: Active
Attachments: No files
Logo Logo
Loading...