Heiken EMA Strategi
Forums › ProRealTime English forum › ProOrder support › Heiken EMA Strategi
- This topic has 8 replies, 4 voices, and was last updated 8 months ago by robertogozzi.
-
-
01/19/2024 at 2:59 PM #226586
Hi,
I need help to make this work:
I want to trade when the Heiken changes colour and EMA 2 crosses EMA 6.
DEFPARAM CumulateOrders = False //MACD[12,26,9](close) Cumulating positions deactivated
// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the “FLATBEFORE” time.
DEFPARAM FLATBEFORE = 093000
// Cancel all pending orders and close all positions at the “FLATAFTER” time
DEFPARAM FLATAFTER = 205000a = EMA[2](close)
b = EMA[6](close)//heiken ashi
xClose = (Open+High+Low+Close)/4
if(barindex>2) then
xOpen= (xOpen[1] + xClose[1])/2
//xHigh= Max(xOpen, xClose)
//xLow= Min(xOpen, xClose)
endif
xBullish = xClose > xOpen
xBearish = xClose < xOpen
ColorChange = (xBullish AND xBearish[1]) OR (xBullish[1] AND xBearish)// Conditions to enter long positions
IF NOT LongOnMarket AND a crosses over b THEN
BUY 1 CONTRACTS AT MARKET
ENDIF// Conditions to exit long positions
IF LongOnMarket AND Colorchange THEN
SELL AT MARKET
ENDIF// Conditions to enter short positions
IF NOT ShortOnMarket AND a crosses under b THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF01/19/2024 at 3:07 PM #22658701/27/2024 at 10:36 AM #226937I made some changes to improve it, though a strategy based solely on EMAs is difficult to be turned into a profitable system:
- I used the HA close (xClose) for the calculations of the two moving averages, replacing the regular close
- I added the short exit
- I changed the CROSSOVER condition with a retracement of the price to the lowest EMA,while the close must still be above both of them
- I added a condition that the HA candle must be bullish for Long trades and Bearish for the short trades (but this should have been automatically the case, nonetheless)
- I changed the periods for the two EMAs
- I added both SL and TP
1234567891011121314151617181920212223242526272829303132333435363738394041424344DEFPARAM CumulateOrders = False //MACD[12,26,9](close) Cumulating positions deactivated// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.DEFPARAM FLATBEFORE = 093000// Cancel all pending orders and close all positions at the "FLATAFTER" timeDEFPARAM FLATAFTER = 205000//heiken ashixClose = (Open+High+Low+Close)/4if(barindex>2) thenxOpen = (xOpen[1] + xClose[1])/2xHigh = Max(xOpen, xClose)xLow = Min(xOpen, xClose)endifxBullish = xClose > xOpenxBearish = xClose < xOpenColorChange = (xBullish AND xBearish[1]) OR (xBullish[1] AND xBearish)a = ExponentialAverage[5](xClose)//(close)b = ExponentialAverage[20](xClose)//(close)UP= xBullish AND (a > b) AND (xClose > a) AND (xLow <= b)DN= xBearish AND (a < b) AND (xClose < a) AND (xHigh >= b)// Conditions to enter long positionsIF NOT LongOnMarket AND UP THENBUY 1 CONTRACTS AT MARKETENDIF// Conditions to exit long positionsIF LongOnMarket AND Colorchange THENSELL AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND DN THENSELLSHORT 1 CONTRACTS AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket AND Colorchange THENEXITSHORT AT MARKETENDIFSET STOP pLOSS 100SET TARGET pPROFIT 300you may also add a trailing stop (lines 17-56 at this link https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/ are commonly used).
01/28/2024 at 5:49 PM #226979Roberto, ciao.
I’ve just tested your strategy but it’s not giving nice results.
Just a question:
is this line correct xOpen = (xOpen[1] + xClose[1])/2 or it should be xOpen = (Open[1] + Close[1])/2 ??
where do you get the value of xOpen[1] ?
many thanks for your reply
01/29/2024 at 10:59 AM #226997It’s correct.
There should be this line, just before “if (barindex>2) then“:
1xOpen = openbut it will work the same after the 3rd candle.
1 user thanked author for this post.
02/16/2024 at 10:42 AM #22826502/16/2024 at 11:35 AM #228275ColorChange triggers an exit.
What do you mean?
02/28/2024 at 9:15 AM #22891502/28/2024 at 12:04 PM #228922That’s exactly what ColorChange does,
-
AuthorPosts
Find exclusive trading pro-tools on