Bollinger Strategy problems with exit orders
Forums › ProRealTime English forum › ProOrder support › Bollinger Strategy problems with exit orders
- This topic has 3 replies, 2 voices, and was last updated 1 year ago by JS.
-
-
08/13/2022 at 9:31 AM #199003
Hello everyone,
I am having problems implementing a Bollinger Strategy.
The following code should buy and sell with the shown condition. But we have trouble with the exits. They do not as they should
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950defparam cumulateorders = falsestartTradingTime = 090500stopTradingTime = 210000positionSize = 1// TRADING HOURStimeCondition = 0IF(time >= startTradingTime) AND (time <= stopTradingTime) THENtimeCondition = 1ENDIFAmountOfSigmas = 2BollingerAmountOfPeriods = 20BollingerBandsMeanAtCurrentClose = average[BollingerAmountOfPeriods,0](close)standardDeviation = STD[BollingerAmountOfPeriods](close)upperBollingerBand = BollingerBandsMeanAtCurrentClose + (AmountOfSigmas * standardDeviation)lowerBollingerBand = BollingerBandsMeanAtCurrentClose - (AmountOfSigmas * standardDeviation)AmountOfSigmascloseMean = 0.1UpperBollingerCloseMean = BollingerBandsMeanAtCurrentClose + AmountOfSigmascloseMean*standardDeviationLowerBollingerCloseMean = BollingerBandsMeanAtCurrentClose - AmountOfSigmascloseMean*standardDeviation// Onboard ConditionCurrentValueAboveUpperBollinger = close > upperBollingerBand // BollingerUp[BollingerAmountOfPeriods](close)//upperBollingerBand //BollingerUp[BollingerAmountOfPeriods](close)CurrentValueBelowLowerBollinger = close < lowerBollingerBand //BollingerDown[BollingerAmountOfPeriods](close)//lowerBollingerBand// BollingerDown[BollingerAmountOfPeriods](close) //BuyShortCondition = CurrentValueAboveUpperBollinger AND timeConditionBuyLongCondition = CurrentValueBelowLowerBollinger AND timeCondition// EXIT CONDITIONsellLongCondition = close >= LowerBollingerCloseMeansellShortCondition = close <= UpperBollingerCloseMeansellstoplong = 40sellstopshort = 40IF BuyLongCondition AND NOT LONGONMARKET THENBUY positionSize PERPOINT AT MARKET//SET STOP PLOSS sellstoplongSET TARGET PROFIT (BollingerBandsMeanAtCurrentClose +AmountOfSigmascloseMean*standardDeviation)*pipsize // POINT WHERE IT SHOULD SELLENDIFIF BuyShortCondition AND NOT SHORTONMARKET THENSELLSHORT positionSize PERPOINT AT MARKET//SET STOP PLOSS sellstopshortSET TARGET PROFIT (BollingerBandsMeanAtCurrentClose-AmountOfSigmascloseMean*standardDeviation)*pipsize // POINT WHERE IT SHOULD SELLENDIF08/13/2022 at 11:25 AM #199008I don’t see exit orders, I do see “Exit Condition” but these are not used in the code…
You go Long with “Buy” but I don’t see “Sell” as “exit order”
You go Short with “SellShort” but I don’t see “ExitShort” as “exit order”
LONG: Buy vs Sell
SHORT: SellShort vs ExitShort
08/13/2022 at 12:22 PM #19901312345678IF sellLongCondition THENsell at marketENDIFIF sellShortCondition THENexitshort at marketENDIFYes you are right, but how would I use a SET TARGET PROFIT with UpperBollingerCloseMean or LowerBollingerCloseMean as example?
08/13/2022 at 2:51 PM #199021Bollinger Exits12345678910111213141516171819202122232425262728DefParam CumulateOrders = FalsePeriod = 20xMean = Average[Period](Close)xStd = Std[Period](Close)BBUp = xMean + 2 * xStdBBDown = xMean - 2 * xStdIf Close Crosses Over BBUp thenSellShort 1 contract at MarketEndIfIf Close Crosses Under BBDown thenBuy 1 contract at MarketEndIfxMeanUp = xMean + 0.1 * xStdxMeanDown = xMean - 0.1 * xStdIf LongOnMarket thenSell at xMeanUp LIMITEndIfIf ShortOnMarket thenExitShort at xMeanDown LIMITEndIfHi @taklause
You can use a LIMIT order to exit your positions…
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on