Not opening trades on Sunday

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #204125 quote
    Gaby
    Participant
    Average

    Hello,

    in order to avoid to open any position on Sunday I have coded the following (Sunday = 0):

    DayCond = OpenDayOfWeek >= 1 AND OpenDayOfWeek <= 5
    TimeCond = OpenTime <= 204500 AND OpenTime >= 014500

    IF TimeCond and DayCond THEN

    However the algo managed to open a position on Sunday. DO you know why the DayCond was disregarded by Prorealcode?

    Many thanks for your help, Gaby

    #204137 quote
    robertogozzi
    Moderator
    Master

    Maybe you are placing a pending order on the very last candle on Friday, so it will be executed when the next bar opens, which might be on Sunday.

    This code works correctly:

    DEFPARAM CumulateOrders = true
    sell at market
    DayCond  = OpenDayOfWeek >= 1 AND OpenDayOfWeek <= 5
    TimeCond = OpenTime <= 204500 AND OpenTime >= 014500
    IF DayCond AND TimeCond THEN
       buy at market
    ENDIF
    graph DayCond
    #204179 quote
    Gaby
    Participant
    Average

    Thanks Roberto, you spot on!

    It was a daily signal started on Fri @ 00.00.00 and given at the closure of the bar (on Friday day’s close). And the program correctly took the trade as soon as possible (Sunday @ 21.00 GMT).

    Actually, I made a mistake on my first message, as in my first post analysis I did not see it was a daily signal. The daily program includes only the check on the DayCond (and not the TimeCond).

    I have now modified my code as follow – and it works (it now prevent trading on Sunday evening at the opening to execute signals generated on Friday’s close):

    // Avoid to open new trades on Sunday at 21.00.00 (for signals generated on Friday’s close), to avoid wide spreads on Sunday night
    // Avoid to open new trades on Monday at 00.00.00 (for signals generated on Sunday’s close), to avoid to consider Sunday as a relevant day to generate the signal.
    DayCond = OpenDayOfWeek >= 1 AND OpenDayOfWeek <= 5
    Sunday = DayOfWeek[0]
    IF DayCond AND NOT Sunday THEN

    Thank you for your support. Gaby

    #204180 quote
    Gaby
    Participant
    Average

    ========= ERRATA CORRIGE ========

    This is the code that works (preventing trades to be opened on Sunday):

    // Avoid to open new trades on Sunday at 21.00.00 (for signals generated on Friday’s close), to avoid wide spreads on Sunday night
    // Avoid to open new trades on Monday at 00.00.00 (for signals generated on Sunday’s close), to avoid to consider Sunday as a relevant day to generate the signal.
    DayCond = OpenDayOfWeek >= 1 AND OpenDayOfWeek <= 5
    NoSunday = currentdayofweek=1 or currentdayofweek=2 or currentdayofweek=3 or currentdayofweek=4 or currentdayofweek=5

    IF DayCond and NoSunday THEN

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

Not opening trades on Sunday


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Gaby @gaby Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Gaby
3 years, 2 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/14/2022
Status: Active
Attachments: No files
Logo Logo
Loading...