One-time buy Signal at System Start
Forums › ProRealTime English forum › ProOrder support › One-time buy Signal at System Start
- This topic has 22 replies, 4 voices, and was last updated 27 minutes ago by stalba.
-
-
10/29/2024 at 9:59 AM #239684
I’m setting up a simple trading system and need a way to trigger a one-time entry (either long or short) at the start if there’s no existing position. This is particularly important after rolling contracts and restarting the system, so it can re-enter immediately if required. I’ve tried using ONCE and various flags, but the system keeps triggering unintended signals. Looking for a simple, reliable code solution to execute an entry just once at the start without affecting ongoing trade signals. Any suggestions?
123456789101112131415161718192021222324252627282930313233343536373839// Set code parametersDEFPARAM CumulateOrders = False // Cumulating positions disabledONCE checkLongPosition = NOT LONGONMARKET// Buy only once on system startIF checkLongPosition THENBUY 1 SHARE AT MARKETENDIFsuperTrendValue = SuperTrend[5.4,36]// Conditions for entering long positionsc1 = (close CROSSES OVER superTrendValue)IF NOT LONGONMARKET AND c1 THENBUY 1 SHARES AT MARKETENDIF// Conditions for exiting long positionsc2 = (close CROSSES UNDER superTrendValue)IF LONGONMARKET AND c2 THENSELL AT MARKETENDIF// Conditions for entering short positionsc3 = (close CROSSES UNDER superTrendValue)IF NOT SHORTONMARKET AND c3 THENSELLSHORT 1 SHARES AT MARKETENDIF// Conditions for exiting short positionsc4 = (close CROSSES OVER superTrendValue)IF SHORTONMARKET AND c4 THENEXITSHORT AT MARKETENDIF10/30/2024 at 1:32 AM #239751Not a bad idea from ChatGPT… 🙂
Once EntryFlag123456789101112131415DEFPARAM CumulateOrders = False // Prevents multiple entriesONCE EntryFlag = 0 // Initialization for one-time entry// Check if there is no position at the start and EntryFlag is 0IF NOT OnMarket AND EntryFlag = 0 THEN// Define your entry condition hereIF /* Your Entry Condition */ THENBUY 1 CONTRACT AT MARKET // Long EntryEntryFlag = 1 // Set the flag to avoid re-triggeringELSEIF /* Alternative Short Condition */ THENSELLSHORT 1 CONTRACT AT MARKET // Short EntryEntryFlag = 1 // Set the flag to avoid re-triggeringENDIFENDIF3 users thanked author for this post.
10/30/2024 at 9:42 AM #239753Thank you! ChatGPT couldn’t solve this, that’s why I am here haha
Unfortunately I’m not getting any entries with this code. I’ve tried it both nested and un-nested, as well as with and without additional conditions, but nothing seems to happen:
1234567891011// Set code parametersDEFPARAM CumulateOrders = False // Prevents multiple entries// Initialize flag for one-time entryONCE EntryFlag = 0// Check for initial entry at the start if there's no position and EntryFlag is 0IF NOT ONMARKET AND EntryFlag = 0 THENBUY 1 SHARES AT MARKET // Long entryEntryFlag = 1 // Set the flag to prevent re-triggering the initial entryENDIFSorry… newby here 😅
10/30/2024 at 9:42 AM #239754This was another try, with the full code, but nothing happens:
1234567891011121314151617// Set code parametersDEFPARAM CumulateOrders = False // Prevents multiple entriesONCE EntryFlag = 0 // Initialization for one-time entrysuperTrendValue = SuperTrend[5.4,36]// Check if there is no LONG position at the start and EntryFlag is 0IF NOT LONGONMARKET AND EntryFlag = 0 THENBUY 1 CONTRACT AT MARKETIF NOT LONGONMARKET AND close CROSSES OVER superTrendValue THENBUY 1 CONTRACT AT MARKET // Long EntryEntryFlag = 1 // Set the flag to avoid re-triggeringELSIF NOT SHORTONMARKET AND close CROSSES UNDER superTrendValue THENSELLSHORT 1 CONTRACT AT MARKET // Short EntryEntryFlag = 1 // Set the flag to avoid re-triggeringENDIFENDIF10/30/2024 at 10:01 AM #23975510/30/2024 at 11:09 AM #239765Thanks, the one-time entry works now! 🙏🏼
With the following code, the other conditions also seem to work, except the first 2 Supertrend crossings directly after the one-time entry are missing (see attachment) – any idea why? The rest of the signals work fine!
123456789101112131415161718192021222324252627// Set code parametersDEFPARAM PreLoadBars = 0DEFPARAM CumulateOrders = False // Prevents multiple entriesONCE EntryFlag = 0 // Initialization for one-time entrysuperTrendValue = SuperTrend[5.4,36]// Check if there is no position at the start and EntryFlag is 0IF NOT ONMARKET AND EntryFlag = 0 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Long ConditionsIF NOT LONGONMARKET AND close CROSSES OVER superTrendValue THENBUY 1 CONTRACT AT MARKET // Long EntryEntryFlag = 1 // Set the flag to avoid re-triggeringELSIF LONGONMARKET AND close CROSSES UNDER superTrendValue THENSELL 1 CONTRACT AT MARKET // Long ExitENDIF// Short ConditionsIF NOT SHORTONMARKET AND close CROSSES UNDER superTrendValue THENSELLSHORT 1 CONTRACT AT MARKET // Short EntryEntryFlag = 1 // Set the flag to avoid re-triggeringELSIF SHORTONMARKET AND close CROSSES OVER superTrendValue THENEXITSHORT 1 CONTRACT AT MARKET // Short ExitENDIF10/30/2024 at 11:24 AM #23976710/30/2024 at 12:27 PM #239772Hi,
Try this one:
Once EntryFlag1234567891011121314151617181920212223242526// Set code parametersDEFPARAM PreLoadBars = 0DEFPARAM CumulateOrders = False // Prevents multiple entriesONCE EntryFlag = 0 // Initialization for one-time entrysuperTrendValue = SuperTrend[5.4,36]// Check if there is no position at the start and EntryFlag is 0IF NOT ONMARKET AND EntryFlag = 0 THENSELLSHORT 1 CONTRACT AT MARKETEntryFlag=1ENDIF// Long ConditionsIF NOT LONGONMARKET AND EntryFlag=1 and close CROSSES OVER superTrendValue THENBUY 1 CONTRACT AT MARKET // Long EntryELSIF LONGONMARKET AND EntryFlag=1 and close CROSSES UNDER superTrendValue THENSELL 1 CONTRACT AT MARKET // Long ExitENDIF// Short ConditionsIF NOT SHORTONMARKET AND EntryFlag=1 and close CROSSES UNDER superTrendValue THENSELLSHORT 1 CONTRACT AT MARKET // Short EntryELSIF SHORTONMARKET AND EntryFlag=1 and close CROSSES OVER superTrendValue THENEXITSHORT 1 CONTRACT AT MARKET // Short ExitENDIF1 user thanked author for this post.
10/30/2024 at 12:49 PM #239775When i use your code 1:1 the entry on the backtest starting date is missing – it enters a short position on the next Supertrend short signal (Screenshot attached) – the problem is that I want to do auto trading with Futures, and when I have an open position and need to roll over to a new contract, I have to close that position but might want to continue with the position / auto trading within the new contract (as the trend is still ongoing), and don’t want to wait until the next signal.
Also, opening a position manually won’t work with auto trading systems:
PRT Conditions of execution of automatic trading systems
“When you begin an automatic trading system, any pre-existing positions placed manually are closed first and any pre-existing orders placed manually are canceled. The first position of the system may be opened at the earliest at the open of the next bar after the system is started.”
How do you handle this, as this is sub-optimal for Futures auto trading? It’s kinda frustrating 🥲
10/30/2024 at 1:09 PM #239777With short position on start/backtest date:
Once EntryFlag v21234567891011121314151617181920212223242526272829// Set code parametersDEFPARAM PreLoadBars = 0DEFPARAM CumulateOrders = False // Prevents multiple entriesONCE EntryFlag = 0 // Initialization for one-time entrysuperTrendValue = SuperTrend[5.4,36]// Check if there is no position at the start and EntryFlag is 0IF NOT ONMARKET AND EntryFlag = 0 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Long ConditionsIF NOT LONGONMARKET and close CROSSES OVER superTrendValue THENBUY 1 CONTRACT AT MARKET // Long EntryEntryFlag = 1 // Set the flag to avoid re-triggeringELSIF LONGONMARKET and close CROSSES UNDER superTrendValue THENSELL AT MARKET // Long ExitEntryFlag = 1ENDIF// Short ConditionsIF NOT SHORTONMARKET AND close CROSSES UNDER superTrendValue THENSELLSHORT 1 CONTRACT AT MARKET // Short EntryEntryFlag = 1 // Set the flag to avoid re-triggeringELSIF SHORTONMARKET and close CROSSES OVER superTrendValue THENEXITSHORT AT MARKET // Short ExitEntryFlag = 1ENDIF10/30/2024 at 1:22 PM #23977910/30/2024 at 1:29 PM #23978210/30/2024 at 1:31 PM #23978510/30/2024 at 1:47 PM #23978810/30/2024 at 2:22 PM #239793 -
AuthorPosts
Find exclusive trading pro-tools on