Heiken Ashi Daily Candle to determine Trend

Created at 15 Jan 2014, 20:26
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Delta_Gamma's avatar

Delta_Gamma

Joined 02.06.2013

Heiken Ashi Daily Candle to determine Trend
15 Jan 2014, 20:26


Hi,

I am a strong believer in trading with the trend and as such I have designed an indicator which works very well when the trend is in place, I use this indicator in a robot I programmed which only follows the trend, i.e. it will only buy during uptrends and only sell during downtrends.

What I want to do is use the Daily candles of the Heiken Ashi indicator to basically determine when the robot trades, i.e. if it is in an uptrend and the daily chart is a red candle, the bot does not trade. Can someone please help me with the code for this? I assume I need to access the multi-timeframe capability.

The conditions are (for an uptrend only):

If the market is in an uptrend on the daily chart AND the daily candle is blue then the parameter Buy = true and the bot trades that day.

If the market is in an uptrend on the daily chart AND the daily candle is red then the parameter Buy = false and no trading takes place on that day.

I've attached the heiken ashi daily chart as an example.

Thank you very much for the help, I really appreciate it.

 

 


@Delta_Gamma
Replies

jeex
16 Jan 2014, 09:08

no indicator needed

cAlgo has no Heiken Ashi, while the cWeb does. So you would need to add an external indicator that makes HA and add a reference.

Easier is to just calculate the HA-values and determine if Up or Down:

  • xClose = (Open+High+Low+Close)/4
    o Average price of the current bar
     
  • xOpen = [xOpen(Previous Bar) + Close(Previous Bar)]/2
    o Midpoint of the previous bar
     
  • xHigh = Max(High, xOpen, xClose)
    o Highest value in the set
     
  • xLow = Min(Low, xOpen, xClose)
    o Lowest value in the set

You can calculate that with two functions.

        private double haClose(int bar)
        {
            return (MarketSeries.Open[bar] + MarketSeries.Low[bar] + MarketSeries.Close[bar] + MarketSeries.High[bar]) / 4.0;
        }
        private double haOpen(int bar)
        {
            if (bar < 1)
                return MarketSeries.Median[bar];
            else
                return (haOpen(bar - 1) + MarketSeries.Close[bar - 1]) / 2.0;
        }

And then in the calculate() method simply

            double hopen = haOpen(index);
            double hclose = haClose(index);

            if (hopen < hclose)
            {
                // TREND UP
            }
            else
            {
                // TREND DOWN
            }

Now i'm sure that in return you will share your winning strategy with us on this forum ;-)


@jeex

Delta_Gamma
16 Jan 2014, 11:57 ( Updated at: 21 Dec 2023, 09:20 )

Hey jeex!

 

Thanks for much for the help, I just have one question.

My bot works with onTick to determine the trade, would this method still work? (unfortunately the onTick has to be used, onBar doesn't work with my strategy.

Also, to use the Heiken Ashi for only the daily chart but still trade on the other charts I referenced it like this, not sure if it's right?

 

  [Parameter(DefaultValue = 2)]
  public int HPeriod { get; set; }

private HeikenAshi H;

var DailyH = MarketData.GetSeries(this.Symbol, TimeFrame.Daily);
            H = Indicators.GetIndicator(DailyH, HPeriod);

Thanks for the help!

Oh and since you asked, I can share a back-test but keep in mind it is only during an uptrend and therefore isn't a long period (2 months), also it uses mini-lots.

I recognise that it requires a much longer period of time to test it properly however before I can do that I need to be able to get this Heiken Ashi working so that I can determine trend pauses and trend changes.

 

 


@Delta_Gamma

jeex
17 Jan 2014, 09:12

Martingale

On Tick still works of course. I use my Indicator Temporary Fair Value to make sure that a single tick does not start a trade, if that price is not supported by more action.

I looks like you use a martingale construction in your robot. Isn't that an unnecessary risk?

Good luck with it. Keep us posted with more results please.


@jeex

Delta_Gamma
17 Jan 2014, 09:38

Hey Jeex,

Thanks for that indicator, it's perfect for the purposes of my bot.

The martingale-type function is definitely risky I agree, however I have found that given a strong trend it tends to work quite well, that is why I am so focused on determining trend directions. Also my function does not trade in the opposite direction of a losing trade, nor does it double positions like the martingale does, what it does, is it adds to profitable positions while the trend matures.

Basically what I want the finished product to do is determine the overall trend, trade in that direction and stop or email me once it reaches a certain profit, that way I can re-evaluate the market before I start the bot again. The idea behind this is that it takes away all the emotion and greed/fear of trading but still uses my trend trading strategies that have been successful in the past.

Anyway, thanks again for the help. Things are progressing again thanks to your help.

See ya!


@Delta_Gamma

jeex
17 Jan 2014, 13:54

Delta

Same aproach, different solution...

I use three bots for that.

  1. The first bot monitors all relevant pairs on specific criteria (like strong trend or strong reversal). This is where my TFV comes in handy.
  2. This is my job: making the right decision.
  3. A second bot calculates the volume and SL & TP and openes a trade.
  4. A third bot trails the trade, partially closes it, if relevant, all by modifying the SL and TP.
  5. The server closes the trade on the SL or TP. So no harm done if internet fails or the computer goes down.

This way psycho-actions :-) are mostly avoided. I do not have to stare in screens all day; only when my alert tells me to.

Finally it's my personal skills that decide on opening a trade. So no need of martingale calculations as my winning percentage is almost at 80 of the trades (and going up), where as my TP is always higher than my SL. The software does all the tedious work, i only surf the waves of the charts.


@jeex

oktrader
17 Jan 2014, 14:21

RE: Delta

jeex said:

2.  This is my job: making the right decision.

 

Hi Jeex,

I've been thinking about what have you said here. Don't you think that at  last you could code step 2? 

If you really follow a strong strategy and your free decisions aren't martingale based, you have to be able to code them. If you always consider the same patterns for "making the right decision", it's just a matter of time to finally code them.

Otherwise, if you can't code them, it means that your "decision" is more martingale based than you thought.


@oktrader

Delta_Gamma
17 Jan 2014, 17:58

RE: Delta

Hey Jeex,

I like that approach, that's actually what I wanted to do. I rely on my trading abilities but what I have found is I focus way too much on the charts and that tends to make me do stupid things. Letting the bot automate the trades while relying on a human decision is definitely the best method in my opinion because I don't believe any indicators will ever be consistently successful since they are mostly lagging, even a moving average isn't a substitute for the human eye, that is why my indicator I designed actually just simulates trend-lines.

Regarding your second point, I think that's a good way to do things because even with a heiken ashi the bot is still liable to make losses because of pull-backs etc. I think I'm going to take after your lead and do that too.

I'm curious how your bot decides on TP and SL, do you mind sharing? My bot only determines TP at the moment but SL I have found to be troubling.

I'd be interested to see some backtests too if you're willing.

jeex said:

Same aproach, different solution...

I use three bots for that.

  1. The first bot monitors all relevant pairs on specific criteria (like strong trend or strong reversal). This is where my TFV comes in handy.
  2. This is my job: making the right decision.
  3. A second bot calculates the volume and SL & TP and openes a trade.
  4. A third bot trails the trade, partially closes it, if relevant, all by modifying the SL and TP.
  5. The server closes the trade on the SL or TP. So no harm done if internet fails or the computer goes down.

This way psycho-actions :-) are mostly avoided. I do not have to stare in screens all day; only when my alert tells me to.

Finally it's my personal skills that decide on opening a trade. So no need of martingale calculations as my winning percentage is almost at 80 of the trades (and going up), where as my TP is always higher than my SL. The software does all the tedious work, i only surf the waves of the charts.

 


@Delta_Gamma

jeex
17 Jan 2014, 18:47

SL and TP

When opening the trade, i decide the maximum loss in pips, or by appointing one of the lines in the Ichimoku: Tenkan Sen, Kijun Sen or the max or min of Senkou Span A or B. The robot calculates SL and calculates the lot size, as that is my max risk.

The same way i can appoint one of these lines as TP, or i appoint a fixed TP and let the bot close half of the trade at that point, set SL to BE for the remaining half and let the bot trail the rest by modifying the TP to the appointed Ichimoku line level. The bot can repeat that scheme and half the remaining trade again. Usually the first profit + BE is taken at a fixed pip rate = fixed SL rate, then the second is taken at  crossing the Tenkan Sen, and often the third at crossing the Kijun Sen.

So i use Ichimoku to determine SL and TP, and a bit for determining the trade.


@jeex

jeex
17 Jan 2014, 18:49

RE: RE: Delta

oktrader said:

jeex said:

2. This is my job: making the right decision.

 

Hi Jeex,

I've been thinking about what have you said here. Don't you think that at  last you could code step 2? 

If you really follow a strong strategy and your free decisions aren't martingale based, you have to be able to code them. If you always consider the same patterns for "making the right decision", it's just a matter of time to finally code them.

Otherwise, if you can't code them, it means that your "decision" is more martingale based than you thought.

Nope. Robots cannot make decisions. Unless you want to lose money of course. The best robot i've seen so far with the best results, was one that opened trades fully and completely at random and had TP = SL * 4. So no robots for me. At least not when you want to double your balance every month.


@jeex

oktrader
18 Jan 2014, 14:13

RE: RE: RE: Delta

jeex said:

Nope. Robots cannot make decisions. Unless you want to lose money of course. The best robot i've seen so far with the best results, was one that opened trades fully and completely at random and had TP = SL * 4. So no robots for me. At least not when you want to double your balance every month.

I'm not talking about the perfect robot. I don't know if it does exist or not. But humans are like robots: we are not perfect at taking decisions. The only diference is that we can change our strategy while we are trading and a robot always does the same thing. And because the market conditions changes, robots fail.

But you will agree that humans fail for the same reason: because we tend to change too much and we don't follow a strong strategy. 

And here's the paradox: we want to be more like robots, but we want robots to be more like humans.

Sure, random is our enemy. But how can you assure that your pesonal decisions aren't random? Neither robots nor humans can't see the future. The only thing a human could do is to get a strategy and following it without any exceptions. But that's what a robot does. So, I encourage you to code every step, even step 2.


@oktrader

Old Account
18 Jan 2014, 14:43

RE: RE: RE: RE: Delta

oktrader said:

jeex said:

Nope. Robots cannot make decisions. Unless you want to lose money of course. The best robot i've seen so far with the best results, was one that opened trades fully and completely at random and had TP = SL * 4. So no robots for me. At least not when you want to double your balance every month.

I'm not talking about the perfect robot. I don't know if it does exist or not. But humans are like robots: we are not perfect at taking decisions. The only diference is that we can change our strategy while we are trading and a robot always does the same thing. And because the market conditions changes, robots fail.

But you will agree that humans fail for the same reason: because we tend to change too much and we don't follow a strong strategy. 

And here's the paradox: we want to be more like robots, but we want robots to be more like humans.

Sure, random is our enemy. But how can you assure that your pesonal decisions aren't random? Neither robots nor humans can't see the future. The only thing a human could do is to get a strategy and following it without any exceptions. But that's what a robot does. So, I encourage you to code every step, even step 2.

I think jeex is right. I think the dream robot for me would be the one you describe jeex. And when it got to step 2 you would get a image of the chart a option to take the trade or not on you phone. Only problemis that you can't trade when you sleep :/


@Old Account

jeex
18 Jan 2014, 20:37

RE: RE: RE: RE: RE: Delta

MRSV said:

I think jeex is right. I think the dream robot for me would be the one you describe jeex. And when it got to step 2 you would get a image of the chart a option to take the trade or not on you phone. Only problemis that you can't trade when you sleep :/

That's the beauty of trading: within 18 months of saving all your profits and thus compounding balance, you can make enough profits in a day, to sleep for the rest of the week.

And until that goal is reached, trading 4 hours a day, 4 days a week (mon-thu) 40 weeks a year next to a part time job will be rewarded! Keep that up for about 18 months without making withdrawals and with a fixed balance percentage of 3% to calculate lot volume, and you will become a millionaire.

Guys: discipline is the key to success. Discipline in money management as well in trading strategy. Only make trades that are 100% according to the strategy, and filter out the bad trades by getting a good feel for the waves.

Charts are like stochastic music: listen long enough and you will absolutely hear the harmony and feel the rhythm.


@jeex

merc
08 Dec 2015, 08:04

hi delta, any chance you can share your codes on Heiken ashi in private? would appreciate it alot if you do

please email me for discussion : mercilez@gmail.com


@merc