straddle strategy program help (beginner)

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #243474 quote
    CameronLoseby21
    Participant
    New

    Hi there,

    I’m new to pro real time. I was wondering if anyone here could help point me in the right direction. I’ll keep it quick and concise out of respect for everyone’s time.

    I’m experimenting with a program that sets one straddle trade per session exactly at 9pm. It will set one buy order, 1 percent above market price and one sell order 1% below market price. When either one of these orders are triggered i want it to cancel the other order and set a trailing stop on the one that was triggered.

    1. I tried to create a work around by pushing one trigger far away when the other one was triggered. For example, if the buy order was triggered it would push the sell order far away. Is there a better way to this? Is there a way to cancel an order when the other order is reached?
    2. i Get this error code when i try to automate the program: Trading systems with orders that partially close a position cannot be sent to ProOrder. make sure no quantity is specified in instructions to close positions (in this case the instruction closes all the entire position.)”. I have no idea how to fix it 🙂

    Any info would be appreciated.

    My code:

    // Automated Trading System: Straddle Strategy (Friday 9:00PM)
    
    // Set trading parameters
    TradeSize = 1  // £1 per pip
    TrailingStopPips = 20  // Trailing stop in pips
    BuyOffset = 1.01  // 1% above current market price
    SellOffset = 0.99  // 1% below current market price
    SessionHour = 21  // 9:00 PM
    TrailingStopValue = TrailingStopPips * POINTVALUE
    
    // Variables to track order levels
    ONCE BuyPrice = 0
    ONCE SellPrice = 0
    
    // Ensure code only runs on Fridays
    IF DayOfWeek = 2 THEN
    
      // Check if current time is exactly 9:00 PM
      IF Hour = SessionHour AND Minute = 0 THEN
    
        // Check if no trades are open before placing orders
        IF NOT OnMarket THEN
          // Set Buy and Sell order levels
          BuyPrice = Close * BuyOffset
          SellPrice = Close * SellOffset
    
          // Place Buy and Sell pending orders
          BUY TradeSize CONTRACTS AT BuyPrice STOP
          SELL TradeSize CONTRACTS AT SellPrice STOP
        ENDIF
    
      ENDIF
    
      // Manage trailing stop and move untriggered order far away
      IF LONGONMARKET THEN  // If a buy trade is open
        // Move the untriggered sell order far below the market
        SellPrice = Close * 0.5  // Set it at 50% below current price
        SELL TradeSize CONTRACTS AT SellPrice STOP
        SET STOP TRAILING (TrailingStopValue)
      ELSE
        IF SHORTONMARKET THEN  // If a sell trade is open
          // Move the untriggered buy order far above the market
          BuyPrice = Close * 1.5  // Set it at 50% above current price
          BUY TradeSize CONTRACTS AT BuyPrice STOP
          SET STOP TRAILING (TrailingStopValue)
        ENDIF
    
      ENDIF
    
    ENDIF
    #243475 quote
    robertogozzi
    Moderator
    Master

    There’s NO need to camcel an order, as all pending untriggered orders are camcelled at the end of each bar.

    So, in 1-minute TF, at 09:00 you will place two pending orders. at 09:01 ALL untriggered pending orders will be closed, be it both or just one of them. In the very unlikely case both orders are triggered on the same, the latter one will first close the one that was previously opened, no matter if it was gaining or losing (it’s a Stop & Reverse).

    Try this code ( I also added a flag, TradeON, to allow only 1 trade per day):

    // Automated Trading System: Straddle Strategy (Friday 9:00PM)
    
    // Set trading parameters
    ONCE TradeON = 1
    IF LongTriggered OR ShortTriggered THEN
    TradeON = 0
    ENDIF
    IF IntraDayBarIndex = 0 THEN
    TradeON = 1
    ENDIF
    //
    TradeSize = 1  // £1 per pip
    TrailingStopPips = 20  // Trailing stop in pips
    BuyOffset = 1.01  // 1% above current market price
    SellOffset = 0.99  // 1% below current market price
    SessionHour = 21  // 9:00 PM
    TrailingStopValue = TrailingStopPips * POINTVALUE
    // Variables to track order levels
    ONCE BuyPrice = 0
    ONCE SellPrice = 0
    // Ensure code only runs on Fridays
    IF DayOfWeek = 2 AND TradeON THEN
    // Check if current time is exactly 9:00 PM
    IF Hour = SessionHour AND Minute = 0 THEN
    // Check if no trades are open before placing orders
    IF NOT OnMarket THEN
    // Set Buy and Sell order levels
    BuyPrice  = Close * BuyOffset
    SellPrice = Close * SellOffset
    // Place Buy and Sell pending orders
    BUY  TradeSize CONTRACTS AT BuyPrice  STOP
    SELL TradeSize CONTRACTS AT SellPrice STOP
    SET STOP TRAILING (TrailingStopValue)
    ENDIF
    ENDIF
    // Manage trailing stop and move untriggered order far away
    //IF LONGONMARKET THEN  // If a buy trade is open
    //// Move the untriggered sell order far below the market
    //SellPrice = Close * 0.5  // Set it at 50% below current price
    ////SELL TradeSize CONTRACTS AT SellPrice STOP
    //SET TARGET PRICE SellPrice
    //SET STOP TRAILING (TrailingStopValue)
    //ELSE
    //IF SHORTONMARKET THEN  // If a sell trade is open
    //// Move the untriggered buy order far above the market
    //BuyPrice = Close * 1.5  // Set it at 50% above current price
    ////BUY TradeSize CONTRACTS AT BuyPrice STOP
    //SET TARGET PRICE BuyPrice
    //SET STOP TRAILING (TrailingStopValue)
    //ENDIF
    //ENDIF
    ENDIF
    CameronLoseby21 and Iván González thanked this post
    #243477 quote
    CameronLoseby21
    Participant
    New

    @robertogozzi

    Thank you for the explanation! Also for adding that flag! Greatly appreciated. Do you have any info or tips regarding the error message that is stopping me from automating my program?

    the error:

    “Trading systems with a Working Order that partially close a position cannot be sent to ProOrder. Make sure that no quantity is specified in instructions to close positions with Working Order (in this case, the instruction closes the entire position)”.

    #243481 quote
    robertogozzi
    Moderator
    Master

    My fault, I didn’t realize you incorrectly used SELL to enter a short trade. Use:

    • BUY    to enter a Long trade
    • SELL  to exit  a Long trade
    • SELLSHORT  to enter a Short trade
    • EXITSHORT  to exit  a Short trade

    so you will have to replace line 32 with:

    SELLSHORT TradeSize CONTRACTS AT SellPrice STOP
    CameronLoseby21 thanked this post
    #243484 quote
    CameronLoseby21
    Participant
    New

    @robertogozzi

    Whoops, silly me. Thank you for your help. I owe you one!

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

straddle strategy program help (beginner)


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by CameronLoseby21
1 year ago.

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