Calculate prevoius Bars & seed recursive value

Back

I am implementing Hekin Ashi strategy in python i want to fetch previous bar data in Update function and also seed recursive value to ha_open

```

def Update(self, input, lastBar):
        self.atr.Update(input)
        if self.atr.IsReady:
            self.o  =  input.Open         ## Open price
            self.h  =  input.High         ## High price
            self.l  =  input.Low          ## Low price
            self.c  =  input.Close        ## Close price

            #lastBar.Open

            self.ha_close = (self.o + self.h + self.l + self.c) / 4.0
            self.ha_open = (self.lastBar.Open + self.lastBar.ha_close) / 2.0

```

when i try to fetch self.lastBar.ha_close its giving error also i want to feed ha_open recursively

as i did in backtrader

self.ha_open = (self..ha_open(-1) + ha_close(-1)) / 2.0

def prenext(self):
# seed recursive value
self.l.ha_open[0] = (self.data.open[0] + self.data.close[0]) / 2.0
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,

Please attach a backtest which demonstrates the issue so we can assist more easily.

Best,
Gahl Goziker

1

Attached backtest

0


actually i am cloning thinkorswim (Supertrend and Hekin Ashi) strategy in quqntconnect
 

https://github.com/sureshja/ThinkOrSwim/blob/master/HeikinAshiSuperTrendStrategy.ts

 

0

Hi Muhammad, 

The error is caused because lastBar is a TradeBar, which doesn't have an ha_close property.

For users transitioning from a different platform I suggest checking out our BootCamp paired with our free Udemy course.

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