Heikin Ashi Strategy
Forums › ProRealTime English forum › ProOrder support › Heikin Ashi Strategy
- This topic has 7 replies, 4 voices, and was last updated 1 month ago by
JS.
-
-
03/06/2025 at 2:09 PM #244728
Hi everyone,
I’m having trouble getting this Heikin Ashi Strategy to work. It’s supposed to enter long when heikin ashi drops below lower Bollinger band but only on the next green heikin candle. Also doing the reverse for short positions. Can anyone help with my code please?:
Heikin Ashi Strategy123456789101112131415161718192021222324252627282930313233343536373839// Define Bollinger BandsDEFPARAM CUMULATEORDERS = falseDEFPARAM PreloadBars = 100bollingerMiddle = Average[20](Close)bollingerUpper = BollingerUp[20](close)bollingerLower = BollingerDown[20](close)// Compute Heikin-Ashi CandleshaClose = (Open + High + Low + Close) / 4haOpen = (haOpen[1] + haClose[1]) / 2haHigh = max(haOpen, haClose)haLow = min(haOpen, haClose)// Track buy/sell signalslongSignal = 0shortSignal = 0// Detect Heikin-Ashi close below lower Bollinger Bandif haClose < bollingerLower thenlongSignal = 1 // Mark as potential buy signalendif// Detect Heikin-Ashi close above upper Bollinger Bandif haClose > bollingerUpper thenshortSignal = 1 // Mark as potential sell signalendif// Confirm Buy: First Green HA Candle After Long Signalif longSignal = 1 and haClose > haOpen thenbuy 1 CONTRACT at marketlongSignal = 0 // Reset signalendif// Confirm Sell: First Red HA Candle After Short Signalif shortSignal = 1 and haClose < haOpen thensellshort 1 contract at marketshortSignal = 0 // Reset signalendif03/06/2025 at 5:11 PM #244735Hi,
Try this one:
HA Strategy12345678910111213141516171819202122232425262728293031323334353637383940414243DefParam CumulateOrders=FalseDefParam PreLoadBars=1000ONCE LongSignal = 0ONCE ShortSignal = 0BollingerMiddle = Average[20](Close)BollingerUpper = BollingerUp[20](close)BollingerLower = BollingerDown[20](close)haClose = (Open + High + Low + Close) / 4If barindex=0 thenhaOpen=OpenelsehaOpen = (haOpen[1] + haClose[1]) / 2EndIfhaHigh = max(High, max(haOpen, haClose))haLow = min(Low, min(haOpen, haClose))// Detect Heikin-Ashi close below lower Bollinger Bandif haClose[1] < BollingerLower[1] thenLongSignal = 1 // Mark as potential buy signalendif// Detect Heikin-Ashi close above upper Bollinger Bandif haClose[1] > bollingerUpper[1] thenShortSignal = 1 // Mark as potential sell signalendif// Confirm Buy: First Green HA Candle After Long Signalif LongSignal = 1 and haClose > haOpen thenBuy 1 Contract at MarketlongSignal = 0 // Reset signal after entryendif// Confirm Sell: First Red HA Candle After Short Signalif ShortSignal = 1 and haClose < haOpen thenSellShort 1 Contract at MarketShortSignal = 0 // Reset signal after entryendifGraphOnPrice BollingerUpper as "Upper"GraphOnPrice BollingerLower as "Lower"3 users thanked author for this post.
03/11/2025 at 8:53 AM #24482403/12/2025 at 9:54 AM #244851Thank-you very much. This works well.
I tried it in various underluyings and different timeframes. The results are bad. In which one do you tried it?
03/17/2025 at 9:10 AM #24497303/17/2025 at 9:22 AM #244974Hi everyone,
So I’ve been playing around with this Heikin Ashi Strategy and made a few adjustments. The strategy is to run on a 30 min GBP/USD chart but I’ve attempted to change the code to exit using the 5 min TF to get more precise exits.
I’m trying to get it to add orders if the price moves against and the initial conditions are met again. I’ve been somewhat successful but it seems to add several positions 5 mins apart and not when the original conditions are met again.
Can anyone adjust the code to get this to work, I’m struggling.
Thanks
JimHeikin Multi Position MTF Strategy123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081DEFPARAM CUMULATEORDERS = trueDefParam PreLoadBars=1000TIMEFRAME(30mn)ONCE LongSignal = 0ONCE ShortSignal = 0BollingerMiddle = Average[20](Close)BollingerUpper = BollingerUp[20](Close)BollingerLower = BollingerDown[20](close)//Heikin Ashi Candle calchaClose = (Open + High + Low + Close) / 4If BarIndex=0 thenhaOpen = OpenelsehaOpen = (haOpen[1] + haClose[1]) / 2EndIfhaHigh = max(High, max(haOpen, haClose))haLow = min(Low, min(haOpen, haClose))//Trigger possible longif haClose[1] < BollingerLower[1] thenLongSignal = 1endif//Trigger possible shortif haClose[1] > BollingerUpper[1] thenShortSignal = 1endif//Enter long on first green heikin candle after triggerif LongSignal = 1 and haClose > haOpen thenBuy 1 Contracts at MarketLongSignal = 0endif//Enter short on first red heikin candle after triggerif ShortSignal = 1 and haClose < haOpen thenSellShort 1 Contracts at MarketShortSignal = 0endif//Add long positions if on the market and conditions met againIF LONGONMARKET and LongSignal=1 and haClose > haOpen thenBuy 1 Contracts at MarketLongSignal = 0endif//Add short positions if on the market and conditions met againif SHORTONMARKET and ShortSignal = 1 and haClose < haOpen thenSellShort 1 Contracts at MarketShortSignal = 0endifTIMEFRAME(5mn)//If one position open and close crosses bollinger middle exit market.If LONGONMARKET and COUNTOFPOSITION=1 and close CROSSES OVER BollingerMiddle THENSELL AT MARKETENDIF//If one position open and close crosses bollinger middle exit market.IF SHORTONMARKET and COUNTOFPOSITION=-1 and close CROSSES UNDER BollingerMiddle THENEXITSHORT AT MARKETENDIF//If multiple positions open exit when close is weighted position price + 5 pointsIf COUNTOFPOSITION > 1 THENIf Close >= POSITIONPRICE + 5 THENSELL AT MARKETENDIFENDIF//If multiple positions open exit when close is weighted position price + 5 pointsIf COUNTOFPOSITION < -1 THENIf Close <= POSITIONPRICE - 5 THENEXITSHORT AT MARKETENDIFENDIF03/17/2025 at 10:26 AM #244979If you have CUMULATEORDERS = true it will keep adding to your order when conditions are true.
Shuld add “not onmarket” to your first buy/sell short Conditions on row 34 and 40.
Also, what are you trying to do on the block starting on row 77?
COUNTOFSHORTSHARES is the comand for short postions, and COUNTOFPOSITION cant be a negative value.
03/17/2025 at 11:56 AM #244982The strategy can open positions every 5 minutes because the different conditions are out of sync…
Try these…
(CountOfPosition can be both positive and negative)
Heikin Ashi Strategy v212345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182DEFPARAM CUMULATEORDERS = trueDefParam PreLoadBars=1000TIMEFRAME(30mn)ONCE LongSignal = 0ONCE ShortSignal = 0BollingerMiddle = Average[20](Close)BollingerUpper = BollingerUp[20](Close)BollingerLower = BollingerDown[20](close)//Heikin Ashi Candle calchaClose = (Open + High + Low + Close) / 4If BarIndex=0 thenhaOpen = OpenelsehaOpen = (haOpen[1] + haClose[1]) / 2EndIfhaHigh = max(High, max(haOpen, haClose))haLow = min(Low, min(haOpen, haClose))//Trigger possible longif haClose[1] < BollingerLower[1] thenLongSignal = 1endif//Trigger possible shortif haClose[1] > BollingerUpper[1] thenShortSignal = 1endif//Enter long on first green heikin candle after triggerif LongSignal = 1 and haClose > haOpen thenBuy 1 Contracts at MarketLongSignal = 0 // Reset triggerendif//Enter short on first red heikin candle after triggerif ShortSignal = 1 and haClose < haOpen thenSellShort 1 Contracts at MarketShortSignal = 0 // Reset triggerendif//Add long positions only if initial conditions met againif LONGONMARKET and haClose[1] < BollingerLower[1] and haClose > haOpen thenBuy 1 Contracts at Marketendif//Add short positions only if initial conditions met againif SHORTONMARKET and haClose[1] > BollingerUpper[1] and haClose < haOpen thenSellShort 1 Contracts at MarketendifTIMEFRAME(5mn)//Exit if single position and close crosses Bollinger middleIf LONGONMARKET and COUNTOFPOSITION=1 and close CROSSES OVER BollingerMiddle THENSELL AT MARKETENDIFIf SHORTONMARKET and COUNTOFPOSITION=-1 and close CROSSES UNDER BollingerMiddle THENEXITSHORT AT MARKETENDIF//Exit if multiple positions when price reaches weighted entry + 5 pointsIf COUNTOFPOSITION > 1 THENIf Close >= POSITIONPRICE + 5 THENSELL AT MARKETENDIFENDIFIf COUNTOFPOSITION < -1 THENIf Close <= POSITIONPRICE - 5 THENEXITSHORT AT MARKETENDIFENDIFGraphOnPrice BollingerMiddleGraphOnPrice BollingerUpperGraphOnPrice BollingerLowerGraphOnPrice PositionPrice1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on