2 bars late on entry and exit

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #239391 quote
    alejandrocorbut
    Participant
    New

    if i back test this simple code, entry and exit are 2 bars late. i want position to open or close on OPEN as the conditions are met.

    new to this! any advice much appreciated

     

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated

    // Conditions to enter long positions
    indicator1 = MACD[12,26,9](Open )
    c1 = (indicator1 >= 0)

    IF c1 THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF

    // Conditions to exit long positions
    indicator2 = MACD[12,26,9](Open )
    c2 = (indicator2 < 0)

    IF c2 THEN
    SELL AT MARKET
    ENDIF

    #239394 quote
    GraHal
    Participant
    Master

    Code is read at the end of each bar and positions are opened or closed at the Open of the next bar … which is only a few miliiseconds after close of previous bar.

    Hope above helps, if not just say.

    #239395 quote
    alejandrocorbut
    Participant
    New

    thank you for feed back.

    if i replace with close, is still 1 bar late.

    i would like to enter position on market open.

    i attach screen shot of graph showing that MACD histogram positive on oct 1 but position doesnt open till nov 1.

     

    how do i trigger open on oct 1 when macd is positive?

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated

    // Conditions to enter long positions
    indicator1 = MACD[12,26,9](close)
    c1 = (indicator1 >= 0)

    IF c1 THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF

    // Conditions to exit long positions
    indicator2 = MACD[12,26,9](close)
    c2 = (indicator2 < 0)

    IF c2 THEN
    SELL AT MARKET
    ENDIF

    Screenshot-2024-10-24-at-09.49.02.jpg Screenshot-2024-10-24-at-09.49.02.jpg
    #239397 quote
    phoentzs
    Participant
    Master

    If this is a monthly time frame, then the “close” of a monthly bar is at the end of the month…

    #239398 quote
    GraHal
    Participant
    Master

    how do i trigger open on oct 1 when macd is positive?

    Use multi-Timeframe.

    For example, conditions could be satisfied on a monthly timeframe, but the trade could be opened on a 1 minute timeframe … so 1 minute into the October bar or said another way … 1 minute after the end of the September bar.

    Multi timeframe – MTF indicators for ProRealTime

    Iván González thanked this post
    #239399 quote
    alejandrocorbut
    Participant
    New

    thank you!  i get it now!

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

2 bars late on entry and exit


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/24/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...