Vladimir hi how can i compare the current price to the price on which i had bought BTC.
the code is same
# Rolling Window
# --------------------------
CRYPTO = "BTCUSD"; BARS = 2;
# --------------------------
class CryptoConsolidator(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2022, 5, 2)
self.SetEndDate(2022, 5, 3)
self.SetCash(1000)
self.crypto = self.AddCrypto(CRYPTO, Resolution.Minute, Market.FTX).Symbol
self.window = RollingWindow[TradeBar](BARS)
self.Consolidate(self.crypto, Resolution.Minute, self.CustomBarHandler)
def CustomBarHandler(self, bar):
self.window.Add(bar)
def OnData(self, data):
if not self.window.IsReady: return
curr_close = np.array([self.window[i].Close for i in range(BARS)])[0]
past_close = np.array([self.window[i].Close for i in range(BARS)])[1]
self.Plot(self.crypto, "curr_close", curr_close)
self.Plot(self.crypto, "past_close", past_close)
if not self.Portfolio[self.crypto].Invested:
if curr_close <= past_close*0.999:
self.SetHoldings(self.crypto, 1.00 )
elif self.Portfolio[self.crypto].Invested:
if curr_close >= past_close*1.001:
self.Liquidate(self.crypto,"sell")
Blackpanther
Vladimir can now u take a look into this code ?
Vladimir
Blackpanther
Thanks for understanding.
--> how can i compare the current price to the price on which i had bought BTC.
We can use curr_close as the current price or define it like this:
curr_price = self.Securities[self.crypto].Price
The price on which we had bought may be define like this:
price_paid = self.Securities[self.crypto].Holdings.AveragePrice
Blackpanther
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!