class CashAnalyzer(Analyzer):
def __init__(self):
super().__init__()
self.start_cash = None
self.end_cash = None
def start(self):
self.start_cash = self.strategy.broker.getvalue()
def stop(self):
self.end_cash = self.strategy.broker.getvalue()
def get_analysis(self):
return dict(start_cash=self.start_cash, end_cash=self.end_cash)
For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
I
Latest posts made by ismailbayram
-
RE: Broker is left intact for optstrategy?
-
Changing Markers
Hi there,
Firstly thanks for this great library. My question is: How can I change markers of buy/sell orders? For example I open a buy position and close it. But marker of opening short position and marker of close buy position are same. I would like to label exit short/exit long.Current Markers:
Desired Markers:
-
How to buy/sell order in close price for current candle? (not the next one)
Hi there,
Firstly, thank you for this great library and community.I would like to create an order in the current bar. For example I have a strategy that called rsi wma strategy. Order fills in the next bar but I want the order to fill in the current bar.
class RSIWMAStrategy(bt.Strategy): params = dict(rsi=14, wma=13, printlog=True) def log(self, txt, dt=None, doprint=False): if self.params.printlog or doprint: dt = dt or self.datas[0].datetime.datetime() print('%s, %s' % (dt.strftime(settings.DATETIME_STR_FORMAT), txt)) def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataclose = self.datas[0].close # To keep track of pending orders and buy price/commission self.order = None self.buyprice = None self.buycomm = None self.rsi = bt.indicators.RelativeStrengthIndex(self.datas[0], period=self.params.rsi) self.wma = bt.indicators.WeightedMovingAverage(self.rsi, period=self.params.wma) self.crossover = bt.indicators.CrossOver(self.wma, self.rsi) def notify_order(self, order): if order.status in [order.Submitted, order.Accepted]: return if order.status in [order.Completed]: if order.isbuy(): self.log( 'BUY EXECUTED, Price: %.2f, Cost: %.2f, Comm %.2f' % (order.executed.price, order.executed.value, order.executed.comm)) self.buyprice = order.executed.price self.buycomm = order.executed.comm else: # Sell self.log('SELL EXECUTED, Price: %.2f, Cost: %.2f, Comm %.2f' % (order.executed.price, order.executed.value, order.executed.comm)) elif order.status in [order.Canceled, order.Margin, order.Rejected]: self.log('Order Canceled/Margin/Rejected') self.order = None def notify_trade(self, trade): if not trade.isclosed: return self.log('OPERATION PROFIT, GROSS %.2f, NET %.2f' % (trade.pnl, trade.pnlcomm)) def next(self): self.log('Close, %.2f' % self.dataclose[0]) if self.order: return print(self.getposition()) if not self.position: if self.crossover > 0: self.log('BUY CREATE, %.2f' % self.dataclose[0]) self.order = self.buy(exectype=Order.Close) self.close() else: if self.crossover < 0: self.log('SELL CREATE, %.2f' % self.dataclose[0]) self.order = self.sell()
-
How to label the candle in the chart?
I would like to label the candle. For Example:
https://www.tradingview.com/x/Md6u7N4l/