Only one trade/trend
Forums › ProRealTime English forum › ProOrder support › Only one trade/trend
- This topic has 14 replies, 4 voices, and was last updated 3 years ago by robertogozzi.
Tagged: supertrend
-
-
01/26/2021 at 4:47 PM #159504
How can i limit the code to only do one trade per trend? Lets say im following supertrend and after take profit or loss i want to stay flat till next direction on supertrend.
BR. Lasse
01/26/2021 at 4:57 PM #159506To take an order only when the Supertrend turn from green to red or red to green, use that code snippet:
12345678st=supertrend[3,10]if close crosses over st thenbuy at marketendifif close crosses under st thensellshort at marketendif1 user thanked author for this post.
01/26/2021 at 5:05 PM #159509I moved the topic from ProBuilder to ProOrder support, as it deals with a strategy.
Please make sure you have carefully read the rules highlighted below (in yellow) in order to correctly use this forum. Thank you 🙂
1 user thanked author for this post.
01/26/2021 at 6:02 PM #159515Hi Nicolas
I attach the code for better understanding. For an example i want to the sell 25-jan 11:00 then take profit 13:37. Then i want the system to stay flat til 25-jan 22:10 when the upptrend starts and after stopploss 26-jan 02:25 stay flat again til next downtrend.
I only want one trade per trend (trend =30min supertrend 3:10)Open itf in 1minute 5k units and Wall street cash.
Many Thanks.
01/26/2021 at 6:47 PM #15951801/26/2021 at 6:51 PM #1595191234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedtimeframe(30 minutes,updateonclose)// Conditions to enter long positionsindicator1 = Average[5](close)indicator2 = SuperTrend[3,10]c1 = (indicator1 > indicator2)timeframe(1 minutes,updateonclose)indicator3 = Average[1](close)indicator4 = Average[5](close)c2 = (indicator3 crosses over indicator4)IF c1 AND c2 THENBUY 1 CONTRACT AT MARKETENDIFtimeframe(30 minutes,updateonclose)// Conditions to exit long positionsindicator5 = Average[5](close)indicator6 = SuperTrend[3,10]c3 = (indicator5 CROSSES UNDER indicator6)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionstimeframe(30 minutes,updateonclose)indicator7 = Average[5](close)indicator8 = SuperTrend[3,10]c4 = (indicator7 < indicator8)timeframe(1 minutes,updateonclose)indicator9 = Average[1](close)indicator10 = Average[5](close)c5 = (indicator9 crosses under indicator10)IF c4 AND c5 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionstimeframe(30 minutes,updateonclose)indicator11 = Average[5](close)indicator12 = SuperTrend[3,10]c6 = (indicator11 > indicator12)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pLOSS 100SET TARGET pPROFIT 10001/26/2021 at 6:56 PM #159521You need to set a flag every time you send an entry order to market and not reset that flag until the trend changes direction. The flag not being set is a condition for allowing entry.
1 user thanked author for this post.
01/26/2021 at 7:04 PM #159524sounds right, but i don’t know how to do it. flag?
01/26/2021 at 8:21 PM #159536flag = just a variable that you set to 1 or 0. If it is 1 then you have already opened a trade. If it is zero then no trade has been opened since the last change in supertrend direction. I don’t have time to amend your code for you right now.
01/26/2021 at 8:46 PM #159537OK please help me when you have time.
Thanks.01/26/2021 at 11:09 PM #159541Something like this (not tested and coded after a couple of glasses of wine!):
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedtimeframe(30 minutes,updateonclose)// Conditions to enter long positionsindicator1 = Average[5](close)indicator2 = SuperTrend[3,10]c1 = (indicator1 > indicator2)newtrend = (SuperTrend[3,10] > SuperTrend[3,10](close[1]) and SuperTrend[3,10](close[1]) < SuperTrend[3,10](close[2])) or (SuperTrend[3,10] < SuperTrend[3,10](close[1]) and SuperTrend[3,10](close[1]) > SuperTrend[3,10](close[2]))if newtrend thenflag = 0endiftimeframe(1 minutes,updateonclose)indicator3 = Average[1](close)indicator4 = Average[5](close)c2 = (indicator3 crosses over indicator4)IF c1 AND c2 and not flag THENBUY 1 CONTRACT AT MARKETflag = 1ENDIFtimeframe(30 minutes,updateonclose)// Conditions to exit long positionsindicator5 = Average[5](close)indicator6 = SuperTrend[3,10]c3 = (indicator5 CROSSES UNDER indicator6)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionstimeframe(30 minutes,updateonclose)indicator7 = Average[5](close)indicator8 = SuperTrend[3,10]c4 = (indicator7 < indicator8)timeframe(1 minutes,updateonclose)indicator9 = Average[1](close)indicator10 = Average[5](close)c5 = (indicator9 crosses under indicator10)IF c4 AND c5 and not flag THENSELLSHORT 1 CONTRACT AT MARKETflag = 1ENDIF// Conditions to exit short positionstimeframe(30 minutes,updateonclose)indicator11 = Average[5](close)indicator12 = SuperTrend[3,10]c6 = (indicator11 > indicator12)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pLOSS 100SET TARGET pPROFIT 1001 user thanked author for this post.
01/27/2021 at 5:06 PM #159591Something is wrong in line 11, im not able to fix it 🙂
01/28/2021 at 11:24 AM #159652Try this:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedtimeframe(30 minutes,updateonclose)// Conditions to enter long positionsindicator1 = Average[5](close)indicator2 = SuperTrend[3,10]c1 = (indicator1 > indicator2)newtrend = (indicator2 > indicator2[1] and indicator2[1] < indicator2[2]) or (indicator2 < indicator2[1] and indicator2[1] > indicator2[2])if newtrend thenflag = 0endiftimeframe(default)indicator3 = Average[1](close)indicator4 = Average[5](close)c2 = (indicator3 crosses over indicator4)if flag = 0 thenmyflag = 0endifIF c1 AND c2 and not myflag THENBUY 1 CONTRACT AT MARKETmyflag = 1ENDIFtimeframe(30 minutes,updateonclose)// Conditions to exit long positionsindicator5 = Average[5](close)indicator6 = SuperTrend[3,10]c3 = (indicator5 CROSSES UNDER indicator6)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionstimeframe(30 minutes,updateonclose)indicator7 = Average[5](close)indicator8 = SuperTrend[3,10]c4 = (indicator7 < indicator8)timeframe(default)indicator9 = Average[1](close)indicator10 = Average[5](close)c5 = (indicator9 crosses under indicator10)IF c4 AND c5 and not myflag THENSELLSHORT 1 CONTRACT AT MARKETmyflag = 1ENDIF// Conditions to exit short positionstimeframe(30 minutes,updateonclose)indicator11 = Average[5](close)indicator12 = SuperTrend[3,10]c6 = (indicator11 > indicator12)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pLOSS 100SET TARGET pPROFIT 1001 user thanked author for this post.
02/06/2021 at 6:28 PM #160539Hi Robertogozzi
Can you help me fix a flag or trade limiter i the code, i only want one trade /supertrend timeframe ( 30min)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedtimeframe(30 minutes,updateonclose)// Conditions to enter long positionsindicator1 = Average[5](close)indicator2 = SuperTrend[3,10]c1 = (indicator1 > indicator2)timeframe(1 minutes,updateonclose)indicator3 = Average[1](close)indicator4 = Average[5](close)c2 = (indicator3 crosses over indicator4)IF c1 AND c2 THENBUY 1 CONTRACT AT MARKETENDIFtimeframe(30 minutes,updateonclose)// Conditions to exit long positionsindicator5 = Average[5](close)indicator6 = SuperTrend[3,10]c3 = (indicator5 CROSSES UNDER indicator6)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionstimeframe(30 minutes,updateonclose)indicator7 = Average[5](close)indicator8 = SuperTrend[3,10]c4 = (indicator7 < indicator8)timeframe(1 minutes,updateonclose)indicator9 = Average[1](close)indicator10 = Average[5](close)c5 = (indicator9 crosses under indicator10)IF c4 AND c5 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionstimeframe(30 minutes,updateonclose)indicator11 = Average[5](close)indicator12 = SuperTrend[3,10]c6 = (indicator11 > indicator12)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pLOSS 200SET TARGET pPROFIT 10002/06/2021 at 8:19 PM #160549Try this (not tested):
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedtimeframe(30 minutes,updateonclose)BarIndex30 = BarIndex// Conditions to enter long positionsindicator1 = Average[5](close)indicator2 = SuperTrend[3,10]c1 = (indicator1 > indicator2)timeframe(1 minutes,updateonclose)ONCE MyBar = 0indicator3 = Average[1](close)indicator4 = Average[5](close)c2 = (indicator3 crosses over indicator4)IF c1 AND c2 AND (MyBar <> BarIndex30) AND Not OnMarket THENBUY 1 CONTRACT AT MARKETMyBar = BarIndex30ENDIFtimeframe(30 minutes,updateonclose)// Conditions to exit long positionsindicator5 = Average[5](close)indicator6 = SuperTrend[3,10]c3 = (indicator5 CROSSES UNDER indicator6)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionstimeframe(30 minutes,updateonclose)indicator7 = Average[5](close)indicator8 = SuperTrend[3,10]c4 = (indicator7 < indicator8)timeframe(1 minutes,updateonclose)indicator9 = Average[1](close)indicator10 = Average[5](close)c5 = (indicator9 crosses under indicator10)IF c4 AND c5 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionstimeframe(30 minutes,updateonclose)indicator11 = Average[5](close)indicator12 = SuperTrend[3,10]c6 = (indicator11 > indicator12)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pLOSS 200SET TARGET pPROFIT 100 -
AuthorPosts
Find exclusive trading pro-tools on