Flat over weekend code

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #141758 quote
    ViSi0nZ
    Participant
    Junior

    Hi guy’s,

    Recently I added some code which notifys my system to close all trades prior to 22:00 on a Friday.. which in turn means I do not hold over the weekend, ramp up overnight fees x 3 and also put my strategy at risk to any weekend gaps.

    I tested the strategy before.. and after to see if there is any difference and the results are exactly the same, which to me means that it hasn’t functioned as intended, as I find it hard to believe that my strategy over 4 years (100,000 units) did not have one single open trade over the weekend.

    No error was generated when initiating the backtest.. so unsure what the issue is here. Could one of you kindly see if what I have written / copied from other post is correct?

    Kind regards.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Closes the system and all open orders prior to Friday end of session close.
    if opendayofweek = 5 and openhour >= 21 and openminute >= 55 then
    sig=1
    else
    sig=0
    endif
    
    IF sig=1 THEN
    SELL AT MARKET
    EXITSHORT AT MARKET
    ENDIF
    #141761 quote
    robertogozzi
    Moderator
    Master

    You need to use  a TF that is <= 5 minutes.

    If you use, say, a 10-minute TF, OpenMinute will never be >= 55 because it will be 50 then 00, both of them are < 55.

    #141784 quote
    swedshare
    Participant
    Senior

    Don’t forget that you will also need a code that prevents your strategy to take position after 21:55 on fridays.

    #141882 quote
    ViSi0nZ
    Participant
    Junior

    You need to use a TF that is <= 5 minutes.

    If you use, say, a 10-minute TF, OpenMinute will never be >= 55 because it will be 50 then 00, both of them are < 55.

    Okay makes sense.. thanks.

    I run the 1 hour time frame so the reason I did this rather was because I presumed that this wouldn’t signal the strategy to trigger close until a second or two after 22:00 therefore would be a executed just after after market close. This inevitably would be too late and would void the idea of implementing the strategy. If the strategy signal performs as I expected then I may need to close it at 21:00 which would be the preceding hour.

    Don’t forget that you will also need a code that prevents your strategy to take position after 21:55 on fridays.

     

    Thanks for this.. I normally limit my automated strategy from opening trades after 21:30ish, is that what you were implying? Or is there a further piece of code required?

    Kind regards

    #141883 quote
    swedshare
    Participant
    Senior

    Exactly, a part from the code in your first post that only manages the closing you also need a piece of code that determines during which time the strategy may or may not open a new position.

    I also used to have the idea that I didn’t want any trades to open during the late high-spread-hours on DJI but realised it’s worth it to let the strategies run as free as possible and only close before the weekends (don’t forget the bank holidays).

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

Flat over weekend code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ViSi0nZ @visi0nz Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/16/2020
Status: Active
Attachments: No files
Logo Logo
Loading...