straddle strategy program help (beginner)
Forums › ProRealTime English forum › ProOrder support › straddle strategy program help (beginner)
- This topic has 4 replies, 2 voices, and was last updated 1 month ago by
CameronLoseby21.
-
-
02/05/2025 at 11:20 AM #243474
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.
- 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?
- 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)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// Automated Trading System: Straddle Strategy (Friday 9:00PM)// Set trading parametersTradeSize = 1 // £1 per pipTrailingStopPips = 20 // Trailing stop in pipsBuyOffset = 1.01 // 1% above current market priceSellOffset = 0.99 // 1% below current market priceSessionHour = 21 // 9:00 PMTrailingStopValue = TrailingStopPips * POINTVALUE// Variables to track order levelsONCE BuyPrice = 0ONCE SellPrice = 0// Ensure code only runs on FridaysIF DayOfWeek = 2 THEN// Check if current time is exactly 9:00 PMIF Hour = SessionHour AND Minute = 0 THEN// Check if no trades are open before placing ordersIF NOT OnMarket THEN// Set Buy and Sell order levelsBuyPrice = Close * BuyOffsetSellPrice = Close * SellOffset// Place Buy and Sell pending ordersBUY TradeSize CONTRACTS AT BuyPrice STOPSELL TradeSize CONTRACTS AT SellPrice STOPENDIFENDIF// Manage trailing stop and move untriggered order far awayIF LONGONMARKET THEN // If a buy trade is open// Move the untriggered sell order far below the marketSellPrice = Close * 0.5 // Set it at 50% below current priceSELL TradeSize CONTRACTS AT SellPrice STOPSET STOP TRAILING (TrailingStopValue)ELSEIF SHORTONMARKET THEN // If a sell trade is open// Move the untriggered buy order far above the marketBuyPrice = Close * 1.5 // Set it at 50% above current priceBUY TradeSize CONTRACTS AT BuyPrice STOPSET STOP TRAILING (TrailingStopValue)ENDIFENDIFENDIF02/05/2025 at 11:50 AM #243475There’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):
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// Automated Trading System: Straddle Strategy (Friday 9:00PM)// Set trading parametersONCE TradeON = 1IF LongTriggered OR ShortTriggered THENTradeON = 0ENDIFIF IntraDayBarIndex = 0 THENTradeON = 1ENDIF//TradeSize = 1 // £1 per pipTrailingStopPips = 20 // Trailing stop in pipsBuyOffset = 1.01 // 1% above current market priceSellOffset = 0.99 // 1% below current market priceSessionHour = 21 // 9:00 PMTrailingStopValue = TrailingStopPips * POINTVALUE// Variables to track order levelsONCE BuyPrice = 0ONCE SellPrice = 0// Ensure code only runs on FridaysIF DayOfWeek = 2 AND TradeON THEN// Check if current time is exactly 9:00 PMIF Hour = SessionHour AND Minute = 0 THEN// Check if no trades are open before placing ordersIF NOT OnMarket THEN// Set Buy and Sell order levelsBuyPrice = Close * BuyOffsetSellPrice = Close * SellOffset// Place Buy and Sell pending ordersBUY TradeSize CONTRACTS AT BuyPrice STOPSELL TradeSize CONTRACTS AT SellPrice STOPSET STOP TRAILING (TrailingStopValue)ENDIFENDIF// 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//ENDIFENDIF2 users thanked author for this post.
02/05/2025 at 12:27 PM #243477Thank 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)”.
02/05/2025 at 12:56 PM #243481My 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:
1SELLSHORT TradeSize CONTRACTS AT SellPrice STOP1 user thanked author for this post.
02/05/2025 at 1:04 PM #243484Whoops, silly me. Thank you for your help. I owe you one!
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on