Back

Fetch previous values

i want to fetch previous values of ha_close as i am able to fetch lastBar.Open, lastBar.Close etc.. and lastBar.finalUn1 and lastBar.finalDn1

def Update(self, input, lastBar):
self.atr.Update(input)
if self.atr.IsReady:
self.test = 0
self.finalUp1 = self.tmpUp1
self.finalDn1 = self.tmpDn1

self.o = input.Open ## Open price
self.h = input.High ## High price
self.l = input.Low ## Low price
self.c = input.Close ## Close price

self.ha_close = (self.o + self.h + self.l + self.c) / 4.0

#self.lastBar.ha_close want to fetch previous value of ha_close

self.ha_open = (lastBar.Open + self.ha_close) / 2.0
self.ha_high = Math.Max(self.o, Math.Max(self.ha_open, self.ha_close))
self.ha_low = Math.Min(self.l, Math.Min(self.ha_open, self.ha_close))
self.hahl2_1 = (self.ha_high + self.ha_low) / 2

self.tmpUp1 = self.hahl2_1 + (self.atr.Current.Value * self.coeff)
self.tmpDn1 = self.hahl2_1 - (self.atr.Current.Value * self.coeff)

if lastBar.Close > self.finalUp1:
self.finalUp1 = max(self.tmpUp1, self.finalUp1)
else:
self.finalUp1 = self.tmpUp1

if lastBar.Close < self.finalDn1:
self.finalDn1 = min(self.tmpDn1, self.finalDn1)
else:
self.finalDn1 = self.tmpDn1

# calculate trendDir1

if input.Close > self.finalDn1:
self.trendDir1 = 1
elif input.Close < self.finalUp1:
self.trendDir1 = -1

if not math.isnan(self.trendDir1):
self.trendDir = self.trendDir1
else:
self.trendDir1 = 1

self.IsReady = self.trendDir1 != 0

 

here is output data
Debug:  time:2019-08-31 00:00:00 open:135.68 high:136.06 low:134.38 close:135.46 ha_close:135.4 ha_open:134.76 ha_high:135.68 ha_low:134.38 hahl2:135.03 tmpUp1:137.17 tmpDn1:132.89 finalUp1:137.17 finalDn1:132.89 atr:2.1376 super trend:1

Debug:  time:2019-09-04 00:00:00 open:134.67 high:134.9 low:133.36 close:134.15 ha_close:134.27 ha_open:134.98 ha_high:134.97 ha_low:133.36 hahl2:134.17 tmpUp1:136.3 tmpDn1:132.04 finalUp1:136.3 finalDn1:132.04 atr:2.13008 super trend:1

Debug:  time:2019-09-05 00:00:00 open:135.85 high:136.43 low:135.15 close:136.31 ha_close:135.94 ha_open:135.3 ha_high:135.94 ha_low:135.15 hahl2:135.54 tmpUp1:137.7 tmpDn1:133.38 finalUp1:137.7 finalDn1:133.38 atr:2.16006 super trend:1

.............

Debug:  time:2019-09-20 00:00:00 open:142.53 high:145.01 low:142.46 close:142.94 ha_close:143.24 ha_open:142.62 ha_high:143.24 ha_low:142.46 hahl2:142.85
 
 

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.


Hi Muhammad,

You could store the values in a RollingWindow and fetch previously calculated values through the RollingWindow.

Best,
Shile Wen

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.


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