do not sell between certain times

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #261368 quote
    kvacksa87
    Participant
    Junior

    Hi. I would have liked to have a code that would prevent it from selling between 9:45 PM and 9:15 AM.

    #261369 quote
    Iván González
    Moderator
    Legend

    Hi,

    The trick is that your window crosses midnight (21:45 → 09:15 next day), so you can’t use AND — you need OR. If you write time >= 214500 AND time <= 091500 it will always return false.

    Solution using the native opentime variable (returns the bar’s opening time as an integer in HHMMSS format):

    // Blocked window: from 21:45 to 09:15 next day
    noSellZone = opentime >= 214500 OR opentime < 091500
    canSell = NOT noSellZone
    

    Then guard your sell orders with canSell. Two typical cases:

    To prevent the system from opening shorts:

    IF yourShortEntryCondition AND canSell THEN
        SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    

    To prevent the system from closing longs during that window:

    IF yourExitCondition AND canSell THEN
        SELL AT MARKET
    ENDIF
    


    kvacksa87 thanked this post
    #261419 quote
    kvacksa87
    Participant
    Junior


    Thanks for the code. But I can’t get it to work so that it won’t sell my position that I have between 9:45 PM and 9:15 AM. It sells as usual. When I put the code in my buy script to not place a new order between 9:45 PM and 9:15 AM, it works.




    // Blocked window: from 21:45 to 09:15 next day

    noSellZone = opentime >= 214500 OR opentime < 091500

    canSell = NOT noSellZone


    LongConditions = canSell and defL1  and c156712  and datr215l and datarl60 and datarl30lb


    IF LongConditions and TradeON ThEN

    BUY positionsize CONTRACT AT MARKET


    ENDIF


    iF  datarl60s and defL1  and c156712 and datr215s and noSellZone THEN

    SELL AT MARKET

    ENDIF


    #261420 quote
    kvacksa87
    Participant
    Junior


    I got it working now. I mixed up your codes. Thank you very much

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

do not sell between certain times


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
kvacksa87 @kvacksa87 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by kvacksa87
1 week, 2 days ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/20/2026
Status: Active
Attachments: No files
Logo Logo
Loading...