Entry and exit based on bollinger bands touches
Forums › ProRealTime English forum › ProOrder support › Entry and exit based on bollinger bands touches
- This topic has 7 replies, 3 voices, and was last updated 1 year ago by Nicolas.
-
-
01/25/2023 at 4:56 PM #208253
Hi, don’t know if this is the right forum, but i’m having trouble finding answers on google.
I need help with a simple thing in the trading system. How do I write the code so that a position is opened when the price touches the upper bollinger band and closes the position when the price touches the lower bollinger band?
I have only managed to get the position to open if the candle CLOSES outside the upper bollinger band.
Grateful for help!
01/25/2023 at 5:01 PM #208255Hi,
please take into account forum guidance in yellow box at bottom of this page for subsequent posts, here in particular the “meaningful title” rule to prevent topics being all called “help with…”), thanks. I edit your title “help with code” to replace it by “entry and exit based on bollinger bands touches”.
01/25/2023 at 5:43 PM #208263We can use pending limit orders placed on bollingerbands to trigger entries at the right price.
12345678defparam cumulateorders=falseif not longonmarket thenbuy 1 contract at BollingerDown[20](close) limitendifif not shortonmarket thensellshort 1 contract at BollingerUp[20](close) limitendif1 user thanked author for this post.
01/25/2023 at 5:55 PM #208266Thank you for the fast response, im new to this, so how exactly would i intergrate this into my code today?
This is my code:
123456789101112131415161718192021222324252627282930313233343536373839404142// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = ExponentialAverage[200](close)c1 = (close > indicator1)indicator2 = BollingerDown[20](close)c2 = (close <= indicator2)IF c1 AND c2 THENBUY 0.55 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator3 = BollingerUp[20](close)c3 = (close >= indicator3)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator4 = ExponentialAverage[200](close)c4 = (close <= indicator4)indicator5 = BollingerUp[20](close)c5 = (close >= indicator5)IF c4 AND c5 THENSELLSHORT 0.55 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator6 = BollingerDown[20](close)c6 = (close <= indicator6)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pTRAILING 16SET TARGET pPROFIT 1601/26/2023 at 10:15 AM #208311So I replace your original entries with the ones I coded above:
1234567891011121314151617181920212223242526272829303132333435363738// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = ExponentialAverage[200](close)c1 = (close > indicator1)IF c1 THENbuy 0.55 contract at BollingerDown[20](close) limitENDIF// Conditions to exit long positionsindicator3 = BollingerUp[20](close)c3 = (close >= indicator3)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator4 = ExponentialAverage[200](close)c4 = (close <= indicator4)IF c4 THENsellshort 0.55 contract at BollingerUp[20](close) limitENDIF// Conditions to exit short positionsindicator6 = BollingerDown[20](close)c6 = (close <= indicator6)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pTRAILING 16SET TARGET pPROFIT 16not tested
1 user thanked author for this post.
01/26/2023 at 1:11 PM #20836301/27/2023 at 8:30 AM #208439I have tried to play around a bit but don’t seam to get it to work, how do i write the code if i alos want the exit of the trade to trigger when price hits the bollinger band? I assume the principal would be the same with pending limit orders?
01/27/2023 at 5:47 PM #208508Exit on bollinger bands are already defined in your code, but you are using the Close, you can use a precise price touch as define in the below modification:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = ExponentialAverage[200](close)c1 = (close > indicator1)IF c1 THENbuy 0.55 contract at BollingerDown[20](close) limitset target price BollingerUp[20](close)ENDIFif longonmarket thenset target price BollingerUp[20](close)endif// Conditions to exit long positionsindicator3 = BollingerUp[20](close)c3 = (close >= indicator3)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator4 = ExponentialAverage[200](close)c4 = (close <= indicator4)IF c4 THENsellshort 0.55 contract at BollingerUp[20](close) limitset target price BollingerDown[20](close)ENDIFif shortonmarket thenset target price BollingerDown[20](close)endif// Conditions to exit short positionsindicator6 = BollingerDown[20](close)c6 = (close <= indicator6)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pTRAILING 16SET TARGET pPROFIT 161 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on