Back

Getting Volume in a Heikin Ashi tradebar

I am a great fan of the heikin ashi tradebars, as they are very suitable for my style and speed of trading.
Right now I am a bit puzzled on how to get the "Volume" in a Heikin Ashi Tradebar, so I can also use indicators on them that require (a tradebar and) a volume input.
for demonstration I tried two indicators (Williams % R and Mfi) with the Heikin Ashi tradebar and Williams % R worked fine, but Mfi (in the absence of a volume value produced only "0").

heikinAshi.Updated += (sender, consolidated) =>
{
if (heikinAshi.IsReady)
{
var tradeBar = new TradeBar(heikinAshi.Current.EndTime, _symbol, heikinAshi.Open, heikinAshi.High, heikinAshi.Low, heikinAshi.Close, 0);
_willr.Update(tradeBar);
_mfi.Update(tradeBar);
}
};

my guess would be to replace the "0" with the volume from a "classic tradebar, but somehow I dont really know how to do that.
data[_symbol].Volume doesnt work.

Any ideas or suggestions  to help me out here?

best,

Andreas.
 

Update Backtest








Please checkout the docs under the Securities and Portfolio section.
We can access the security volume in the Securities property. Also note that we should use the consolidated parameter to create the tradebar that will be used to update the indicators.

heikinAshi.Updated += (sender, consolidated) =>
{
if (heikinAshi.IsReady)
{
var tradeBar = new TradeBar(
consolidated.Current.EndTime,
_symbol,
consolidated.Open,
consolidated.High,
consolidated.Low,
consolidated.Close,
Securities[_symbol].Volume);

_willr.Update(tradeBar);
_mfi.Update(tradeBar);
}
};

 

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


@Alexandre, thanks for your fast reply!
I will try it.

What I dont understand still, is that when i am using the consolidated parameter also for OHLC, am I not losing the Heikin Ashi values, I would put in that tradebar with heikinAshi.Open etc?
best,

Andreas.

0

@Andreas, at the moment the HeikinAshi indicator does not store volume for the underlying input series, so it now always returns zero.

I have submitted a PR to the LEAN project on GitHub to add the Volume series here:
https://github.com/QuantConnect/Lean/pull/662
hopefully it will be merged soon.

Also there is no need to create a new TradeBar in heikinAshi.Updated, you can simply pass consolidated.CurrentBar (which is the current HeikinAshi bar) as input to the other indicators.

Example backtest attached (will print volume = 0 until the fix is applied):

2

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


@Stefano, your answer was spot on. again. thanks.

there is something strange I noticed.

The values returned for the Williams % R dont make any sense.

The formula to calculate it is (or should be):

100 * (close - highestHigh) / (highestHigh - lowestLow)


The indicator is meant to only have values between -100 and 0, yet the extremes returned are above 150 and when logging with Log("Will%R: " + _willr); it always returns 0.

Am I missing something, or is there a flaw somewhere?

best,

Andreas.

 

0

it seems, I am missing something indeed.

when plotted the _willr actually shows normal values between -100 and 0.

still I dont understand why logging

Log("Williams% max: " + _willr.Maximum);

returns not the indicators value, but a price value.

0

The formula for Williams%R looks correct, you can see the source code for the indicator here:
https://github.com/QuantConnect/Lean/blob/master/Indicators/WilliamsPercentR.cs

The reason why you are seeing zero values is because the period (20 in the example) is greater than the number of days in the backtest. If you try a longer period, you should see the correct values.

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Williams%R Maximum and Minimum properties are actually the highest and lowest prices in the period.
The return value of the indicator is scaled to the range [-100, 0]

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed