Hi, I have a system that uses heiken ashi candles and it will go long when the simple moving average(9) crosses a bullish candle and then closes and goes short when it crosses a bearish candle. I need any help making it as I’m having trouble doing so. It’s a pretty basic system and I’ve tried stuff like what you can see below but that doesn’t work. Please help.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = close
indicator2 = Average[9](close)
c1 = (indicator1 CROSSES OVER indicator2)
IF c1 THEN
BUY 500 PERPOINT AT MARKET
ENDIF
// Conditions to exit long positions
indicator3 = close
indicator4 = Average[9](close)
c2 = (indicator3 CROSSES UNDER indicator4)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator5 = close
indicator6 = Average[9](close)
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 THEN
SELLSHORT 500 PERPOINT AT MARKET
ENDIF
// Conditions to exit short positions
indicator7 = close
indicator8 = Average[9](close)
c4 = (indicator7 CROSSES OVER indicator8)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
Hello, I have not tested your strategy code but it seems right. Why do you think this is not working?
Hi, this code is correct but it doesn’t do my system correctly. The main problem I’ve been having is getting the system to recognize when the moving average has crossed a candle, then to recognize what direction the candle is.
Your code is catching correctly the moment when price are crossing the moving average. If you want to add a condition on the candlestick direction, you can code it like this:
bullish = close[1]>open[1]
bearish = close[1]<open[1]
IF c1 and bullish THEN
BUY 500 PERPOINT AT MARKET
ENDIF
IF c3 and bearish THEN
SELLSHORT 500 PERPOINT AT MARKET
ENDIF
Hi, thank you for your help it’s helped me a lot. I have realized that the problem i was having is that I use heiken ashi candles but ProOrder uses regular candlesticks. How can I get my code to buy/sell according to Heiken Ashi candles instead of regular candlesticks? thank you
Here is Heiken Ashi candlestick codes for Open and Close:
once haclose=close
once haopen=open
if barindex>1 then
haclose=(open+close+low+high)/4
haopen=(haopen[1]+haclose[1])/2
endif
thank you, you have been very helpful, but can you direct me where to put that code in order to make my system work? thank you