A chronologically dependant condition?
Forums › ProRealTime English forum › ProOrder support › A chronologically dependant condition?
- This topic has 8 replies, 4 voices, and was last updated 2 years ago by robertogozzi.
-
-
02/02/2022 at 8:18 PM #187402
Hello everyone! I’m basically a noobie when it comes to coding so I’m expecting that my problem is “easily” solvable for some coders here.
My problem is that I want to make a condition for my strategy that is chronologically dependant. Meaning this indicator needs to be at a value at FIRST and then cross a line thereafter and then after it crossed the line the indicator do not need to be at that value later since it already was there. I know my english is severly incomprehensible but I’m trying my best. Sincerely//julopax
02/02/2022 at 10:13 PM #187408You can use the statement “ONCE”
Your code is executed at the end of each bar, but “once” is only executed the first time hence “once”Example from the documentation:
Statement123456789ONCE myfirstlowest = lowest[10](low)IF(low < myfirstlowest OR low < recentlow) THENrecentlow = lowELSErecentlow = recentlowENDIFRETURN recentlow02/03/2022 at 12:13 AM #187411Well… I did read the documentation on the ONCE instruction and it turns out it’s not my case at all. The ONCE instruction is only going to run a command ONCE. And in my case I need my condition to follow a chronological order meaning it can repeat indefinitely but only in a specific order
02/03/2022 at 3:17 AM #187413Can you post an example?
02/03/2022 at 7:59 AM #18742602/03/2022 at 6:07 PM #187488I’m going to post an example since it’s too hard to explain in plain text.
Let’s say my strategy is based off the Adaptive Moving Average indicator and the Stochastic indicator exclusively.
The first screenshot is what it looks like in a 30min chart (1k candles)
My code (example, used probuilder):
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positions
My problem lies in
indicator1 = AdaptiveAverage[20,2,3000](close)
indicator2 = AdaptiveAverage[70,2,3000](close)
c1 = (indicator1 CROSSES OVER indicator2)
indicator3 = Stochastic[100,50](close)
c2 = (indicator3 < 20) IF c1 AND c2 THEN BUY 1 CONTRACT AT MARKET ENDIF // Conditions to exit long positions indicator4 = AdaptiveAverage[20,2,3000](close) indicator5 = AdaptiveAverage[70,2,3000](close) c3 = (indicator4 CROSSES UNDER indicator5) IF c3 THEN SELL AT MARKET ENDIF // Conditions to enter short positions indicator6 = AdaptiveAverage[20,2,3000](close) indicator7 = AdaptiveAverage[70,2,3000](close) c4 = (indicator6 CROSSES UNDER indicator7) indicator8 = Stochastic[100,50](close) c5 = (indicator8 > 80)c2
andc5
where I only need it the stochastic K% line to be under 20 when the “faster, black” adaptive MA crosses over the “slower, red” one. The K% line doesn’t need to be under 20 if the K% line keeps being over the D% line, meaning if the K% line crosses under the D% line before the K% line hits the value 80 only then can the system halt buying new contracts. If not then the system can solely rely on the adaptive MA indicators as long as the K% line keeps being over the D% lineIF c4 AND c5 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF// Conditions to exit short positions
indicator9 = AdaptiveAverage[20,2,3000](close)
indicator10 = AdaptiveAverage[70,2,3000](close)
c6 = (indicator9 CROSSES OVER indicator10)IF c6 THEN
EXITSHORT AT MARKET
ENDIF02/05/2022 at 4:16 PM #187602Your code is a mess, can you tide it up and post it as plain text?
02/05/2022 at 4:28 PM #187604Just in case it is difficult for julopax with the blue button lacking :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = AdaptiveAverage[20,2,3000](close)indicator2 = AdaptiveAverage[70,2,3000](close)c1 = (indicator1 CROSSES OVER indicator2)indicator3 = Stochastic[100,50](close)c2 = (indicator3 < 20)IF c1 AND c2 THENBUY 1 CONTRACT AT MARKETENDIF // Conditions to exit long positionsindicator4 = AdaptiveAverage[20,2,3000](close)indicator5 = AdaptiveAverage[70,2,3000](close)c3 = (indicator4 CROSSES UNDER indicator5)IF c3 THENSELL AT MARKETENDIF // Conditions to enter short positionsindicator6 = AdaptiveAverage[20,2,3000](close)indicator7 = AdaptiveAverage[70,2,3000](close)c4 = (indicator6 CROSSES UNDER indicator7)indicator8 = Stochastic[100,50](close)c5 = (indicator8 > 80)// My problem lies in c2 and c5 where I only need it the stochastic K% line// to be under 20 when the “faster, black” adaptive MA crosses over the “slower,// red” one. The K% line doesn’t need to be under 20 if the K% line keeps being// over the D% line, meaning if the K% line crosses under the D% line before// the K% line hits the value 80 only then can the system halt buying new// contracts. If not then the system can solely rely on the adaptive MA// indicators as long as the K% line keeps being over the D% lineIF c4 AND c5 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator9 = AdaptiveAverage[20,2,3000](close)indicator10 = AdaptiveAverage[70,2,3000](close)c6 = (indicator9 CROSSES OVER indicator10)IF c6 THENEXITSHORT AT MARKETENDIF02/07/2022 at 3:41 PM #187812It’s not clear enough.
I’ll ask you one question at a time.
Let’s talk only about LONG trades (Short is just the reverse). Question #1: what are the conditiuons to enter a LONG trade? -
AuthorPosts
Find exclusive trading pro-tools on