Heikin Ashi Bollinger Bands Strategy
Forums › ProRealTime English forum › ProOrder support › Heikin Ashi Bollinger Bands Strategy
- This topic has 5 replies, 3 voices, and was last updated 1 hour ago by
GraHal.
-
-
02/17/2025 at 11:26 PM #243965
Hi everyone,
Wondered if anyone can help me. I’m trying to build a strategy based around Heikin Ashi Candles and Bollinger bands. To enter a buy position a red heikin ashi candle must close below the lower Bollinger band and then on the next green heikin candle open a buy of 0.5 contracts. If the price goes against the position, if the entry conditions are met again with a minimum of a 10 point distance, enter another position of 0.1 etc. Close all positions when the price meets the weighted position price + 5 points (or whatever set). It should do the opposite for short positions. This is what I have so far, apologies for my code, I’m a novice…
Heikin Ashi Bollinger Strategy12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182DEFPARAM CumulateOrders = True//Calculate Bollinger BandsBollMid = Average[20](close)BollUpper = BollingerUp[20](close)BollLower = BollingerDown[20](close)HaClose = (Open + High + Low + Close) / 4if(barindex>2) thenHaOpen = (HaOpen[1] + HaClose[1]) / 2endif//Fixing HaHigh calculationTempHigh = max(HaOpen, HaClose)HaHigh = max(High, TempHigh)//Fixing HaLow calculationTempLow = min(HaOpen, HaClose)HaLow = min(Low, TempLow)//Define Heikin-Ashi color changeHaGreen = (HaClose > HaOpen)HaRed = (HaClose < HaOpen)//Track entry pricesONCE EntryPrice = 0ONCE PositionSize = 0//Entry conditionsLongCondition = (HaGreen AND HaClose > BollLower AND HaClose[1] <= BollLower)ShortCondition = (HaRed AND HaClose < BollUpper AND HaClose[1] >= BollUpper)//Re-entry conditions (add positions if price moves 10 points against the trade)MinMove = 10AddLongCondition = (LongCondition AND abs(close - EntryPrice) >= MinMove)AddShortCondition = (ShortCondition AND abs(close - EntryPrice) >= MinMove)//Exit condition (close all positions at weighted average + 5 points)IF PositionSize > 0 THENWeightedExitPrice = POSITIONPRICEExitCondition = (close >= WeightedExitPrice)ELSEExitCondition = 0ENDIF//Execute tradesIF LongCondition THENBUY 0.5 CONTRACT AT MARKETEntryPrice = closePositionSize = PositionSize + 0.5ENDIFIF ShortCondition THENSELLSHORT 0.5 CONTRACT AT MARKETEntryPrice = closePositionSize = PositionSize + 0.5ENDIF//Add positions if price moves against initial tradeIF AddLongCondition THENBUY 0.1 CONTRACT AT MARKETPositionSize = PositionSize + 0.1ENDIFIF AddShortCondition THENSELLSHORT 0.1 CONTRACT AT MARKETPositionSize = PositionSize + 0.1ENDIF//Close all positions when reaching WeightedExitPriceIF ExitCondition THENIF PositionSize > 0 THENIF LONGONMARKET THENSELL AT MARKETELSEIF SHORTONMARKET THENEXITSHORT AT MARKETENDIFENDIFENDIFENDIF02/18/2025 at 9:57 AM #243974Bonjour
Sorry, I replied in French, surely it is better in english as this is the english forum
Some remarks
- The condition in line 40 If PositionSize > 0 is it also valid for short trtades ?
I would recommend to split Long and Short trades and to create ExitConditionLong and ExitConditionShort- If LongonMarket then… ExitConditionLong = (close >= WeightedExitPrice + 5) …
- and If Shortonmarket then … sortie ExitConditionShort = (close <= WeightedExitPrice – 5)
- In the block of exit orders, I would rcommend to reset after exit eht PositionSize to 0ne faut-il pas mettre après la sortie une ligne de réactualisation PositionSize = 0 dans la boucle
IF ExitConditionLong THENIF PositionSize > 0 THEN
…. ordres
PositionSize = 0
endif
endif - and the same for IF ExitConditionShort
Hope this will be helpful, let us exchange about the modified code
1 user thanked author for this post.
02/21/2025 at 3:57 PM #244164Hi,
Thanks for replying. I’ve made some modifications to the code but I still can’t get it to open any positions. Would anyone be able to help?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778DEFPARAM CumulateOrders = True//Calculate Bollinger BandsBollMid = BollingerUp[20](close) + BollingerDown[20](close) / 2BollUpper = BollingerUp[20](close)BollLower = BollingerDown[20](close)PositionSize = 0.5PositionIncrease = 0.5Pointsgain = 5heikinlow = 0heikinhigh = 0// Calculate Heikin-Ashi candlesHaClose = (Open + High + Low + Close) / 4HaOpen = (HaOpen[1] + HaClose[1]) / 2HaHigh = max(HaOpen, HaClose)HaLow = min(HaOpen, HaClose)//Define Heikin-Ashi color changeHaGreen = (HaClose > HaOpen)HaRed = (HaClose < HaOpen)//Heikin cross lowIf HaClose < BollLower thenheikinlow = 1ENDIF//Heikin cross HighIf HaClose > BollUpper thenheikinhigh = 1ENDIF//Buy entry conditionsIF heikinlow = 1 and HaGreen THENbuy PositionSize CONTRACTS AT MARKETENDIF//Sell entry conditionsIF heikinhigh = 1 and HaRed THENSELLSHORT PositionSize CONTRACTS AT MARKETENDIF//Re-entry conditions (add positions if price moves 10 points against the trade)MinMove = 10AddLongCondition = (LONGONMARKET AND abs(HaClose - TRADEPRICE) >= MinMove)AddShortCondition = (SHORTONMARKET AND abs(HaClose - TRADEPRICE) >= MinMove)//Exit conditions (close all positions at weighted average + points gain)IF PositionSize <> 0 THENExitConditionlong = (close >= (POSITIONPRICE + Pointsgain))ENDIFIF PositionSize <> 0 THENExitConditionshort = (close <= (POSITIONPRICE - Pointsgain))ENDIF//Add positions if price moves against initial tradeIF AddLongCondition and heikinlow = 1 and HaGreen THENBUY PositionIncrease CONTRACTS AT MARKETENDIFIF AddShortCondition and heikinhigh = 1 and HaRed THENSELLSHORT PositionIncrease CONTRACTS AT MARKETENDIF//Close all positions when reaching WeightedExitPriceIF ExitConditionlong THENSELL AT MARKETheikinlow = 0ELSEIF SHORTONMARKET and ExitConditionshort thenEXITSHORT AT MARKETheikinhigh = 0ENDIFENDIF02/21/2025 at 4:20 PM #24416502/21/2025 at 4:38 PM #24417102/21/2025 at 6:19 PM #244174 - The condition in line 40 If PositionSize > 0 is it also valid for short trtades ?
-
AuthorPosts
Find exclusive trading pro-tools on