Buy and Limit orders with relation to a price at a specific hour

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #144258 quote
    MICH
    Participant
    Junior

    Hello,

    I’m trying to set limit orders to buy and sell based on the price at a certain time.

    For example, if the price of a contract at 16:00 is 185, set a buy limit order to 5 pt less and a sell limit order to 2 pt more. Purchase and sale orders, in the example of 185, would be at 180 and 187.

    I tried with:

    IF (CurrentTime = 1600) THEN

    BUY 1 CONTRACT AT close[1]-5 LIMIT

    SHORTSELL 1 CONTRACT AT close[1]+2 LIMIT

    END IF

    But if in the timeframe considered (e.g. 5 min) these price levels are not touched the orders are not executed. If by 16:05 the price levels are not touched the orders are not opened. What can I do to have the orders open for the following periods? 

    Thank you very much in advance!

    #144259 quote
    robertogozzi
    Moderator
    Master

    160000, always 6 digits.

    Sellshort, not Shortsell.

    Pending orders always expire each bar. If conditions are still valid you need to place them again and again.

    #144260 quote
    MICH
    Participant
    Junior

    Thank you very much for the correction and for the advice!

    But, how can to replace the orders for a specific time? E.g for 4 hours?

    Thank you in advance!

    #144264 quote
    robertogozzi
    Moderator
    Master

    The simplest way is to run your strategy from a 4-hour chart.

    If you want to run your strategy from a 5-minute chart but want the pending orders be placed for the next 4 hours, then you have to do the math yourself to compute the correct expiration time or you may use the number of 5-minute bars required (each hour has 12 5-minute bars, so it’s a total 48 bars) to keep placing your pending order(s).

    #144266 quote
    MICH
    Participant
    Junior

    Thank you very much Roberto!

    #240207 quote
    HOPLITE
    Participant
    Average

    Dear All,

    How to set up a buy limit above the previous candle high plus 1 ?

    BUY 1 CONTRACT AT HIGH[1]+1 LIMIT
    SET TARGET PPROFIT 150
    SET STOP ploss 80
    ENDIF

    This code buy at the open instead of the previosu candle high +1

    Could you please advise what shoul be written ? to activate it ?

    Thanks

    Capture-decran-2024-11-10-153738.png Capture-decran-2024-11-10-153738.png
    #240212 quote
    robertogozzi
    Moderator
    Master

    Without the code you used I cannot exactly tell, but you are likely not to have checked whether the order has to be a STOP or LIMIT order:

    IF close >  HIGH[1]+1 THEN
       BUY 1 CONTRACT AT HIGH[1]+1 LIMIT
    ELSIF close <  HIGH[1]+1 THEN
       BUY 1 CONTRACT AT HIGH[1]+1 STOP
    ENDIF

    You cannot use STOP or LIMIT at your own discretion, but based on the position of the current price. i.e. CLOSE, compared to the entry point (see attached dpic).

    Pending-STOP-LIMIT-Orders-Ordini-Pendenti.jpg Pending-STOP-LIMIT-Orders-Ordini-Pendenti.jpg
    #240329 quote
    HOPLITE
    Participant
    Average

    Thank you Roberto for your reply.

    I am just looking for a buy signal when the price crosses the previous candle high in the same timeframe.

    #240362 quote
    robertogozzi
    Moderator
    Master

    Then the above code should do.

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

Buy and Limit orders with relation to a price at a specific hour


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
MICH @mich Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by robertogozzi
1 year, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/14/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...