How to write a Heiken Ashi
Forums › ProRealTime English forum › ProOrder support › How to write a Heiken Ashi
- This topic has 7 replies, 3 voices, and was last updated 4 years ago by
robertogozzi.
-
-
07/28/2020 at 9:11 PM #140342HiI would like to write a code where after a EMA crosses over another I buy a contract and sell when the Heiken Ashi (HA) turns from green to red.The EMA element is fine but cannot get the HA bit.I have the basics of the below but cannot work out how to write the code to get from green to red, a then vice a versa when going short from red to green1234567//heiken ashixClose = (Open+High+Low+Close)/4if(barindex>2) thenxOpen= (xOpen[1] + xClose[1])/2xHigh= Max(xOpen, xClose)xLow= Min(xOpen, xClose)endifCan anyone help please?07/29/2020 at 12:10 AM #140348
There you go:
12345678910//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)COLORCHANGE will be true whenever two adjacent HA candlesticks have different colours.
07/30/2020 at 12:52 PM #14045907/30/2020 at 6:57 PM #140517Hi
I applied the above code but cannot get it to work. I had to //REM xHigh and xLow as the system said it was not included in the code.
Same idea as before, When the MACD crosses over buy on a green HA. Close that order when the HA turns red (but do not automatically sell to open a new position).
Any pointers to where I am going wrong would be appreciated.
Sorry cant see where to “insert PRT code”.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647//————————————————————————-// Main code : MACD with HA End//————————————————————————-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 = 200000// Cancel all pending orders and close all positions at the “FLATAFTER” timeDEFPARAM FLATAFTER = 205000a = MACDline[12,26,9](close)b = MACD[12,26,9](close)//heiken ashixClose = (Open+High+Low+Close)/4if(barindex>2) thenxOpen= (xOpen[1] + xClose[1])/2//xHigh= Max(xOpen, xClose)//xLow= Min(xOpen, xClose)endifxBullish = xClose > xOpenxBearish = xClose < xOpenColorChange = (xBullish AND xBearish[1]) OR (xBullish[1] AND xBearish)// Conditions to enter long positionsIF NOT LongOnMarket AND a crosses over b THENBUY 1 CONTRACTS AT MARKETENDIF// Conditions to exit long positionsIF LongOnMarket AND Colorchange THENSELL AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND a crosses under b THENSELLSHORT 1 CONTRACTS AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket AND Colorchange THENBUY AT MARKETENDIF// Stops and targets : Enter your protection stops and profit targets hereSET TARGET PPROFIT 40SET STOP Ptrailing 1507/30/2020 at 7:50 PM #140520You posted in the wrong forum, this is a strategy and therefore the correct support forum is ProOrder.
To exit a Short trade you need EXITSHORT, since BUY will open a Long trade.
07/31/2020 at 3:08 PM #140561You do not need to start a new topic, please append your further questions here, if relatedto the same topic.
07/31/2020 at 4:13 PM #140567Sorry about any confusion I thought you wanted me to open a new post.
I tried the EXITSHORT and positions still did not open. There was a trade this afternoon that would have made 73 points. MACD crossed under and red HA candle present afterwards. Short position did not open.
08/01/2020 at 2:45 PM #140613Line 11 is correct.
Replace line 12 with:
1b = ExponentialAverage[9](MACDline[12,26,9](close)) //Signal lineand use EXITSHORT.
-
AuthorPosts