You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am running the basic RSI example from your documentation and observed some strange behaviour
defprice_event(price, symbol, state: blankly.StrategyState):
"""This function will give an updated price every 15 seconds from our definition below"""state.variables["history"].append(price)
rsi=blankly.indicators.rsi(state.variables["history"])
ifrsi[-1] <30andnotstate.variables["owns_position"]:
# Dollar cost average buybuy=int(state.interface.cash/price)
state.interface.market_order(symbol, side="buy", size=buy)
state.variables["owns_position"] =Trueelifrsi[-1] >70andstate.variables["owns_position"]:
# Dollar cost average sellcurr_value=state.interface.account[state.base_asset].availablestate.interface.market_order(symbol, side="sell", size=int(curr_value))
state.variables["owns_position"] =Falsedefinit(symbol, state: blankly.StrategyState):
# Download price data to give context to the algostate.variables["history"] =state.interface.history(
symbol, to=150, return_as="deque", resolution=state.resolution
)["close"]
state.variables["owns_position"] =Falseif__name__=="__main__":
exchange=blankly.Oanda()
# Use our strategy helper on coinbase prostrategy=blankly.Strategy(exchange)
# Run the price event function every time we check for a new price - by default that is 15 seconds# strategy.add_price_event(price_event, symbol="XAU-USD", resolution="15m", init=init)strategy.add_price_event(price_event, symbol="BCO-USD", resolution="15m", init=init)
# Start the strategy. This will begin each of the price event ticks# strategy.start()# Or backtest using thisresults=strategy.backtest(to="1y")
print(results)
I get a nice html plot at the end of backtesting, I noticed that the code above is using all the cash in my account [state.interface.cash](http://state.interface.cash) and that number is being used to determine buy size. But say I want a stake of e.g. $1000 rather than use all the cash in my account, when I change the code to calculate the buy size using the stake it has a bizarre effect on the BCO (crude oil) plot - the y axis is completely different? (I’ve attached the plots)
Any idea why this might be case? everything else is the same in both cases so I would expect the BCO plot to remain the same. The same thing happens if I manually set the size e.g. to 1 state.interface.market_order(symbol, side="buy", size=1) In this case I see the BCO plot bars are all set to 1?
The text was updated successfully, but these errors were encountered:
This seems like correct behavior, I dont't know the value of your account of course so I can't really explain why it's only trading one share, maybe by default you have slightly more cash than 1 share and its getting trunced to an int? I would have to see the numbers to get a better idea.
Description
I am running the basic RSI example from your documentation and observed some strange behaviour
I get a nice html plot at the end of backtesting, I noticed that the code above is using all the cash in my account
[state.interface.cash](http://state.interface.cash)
and that number is being used to determine buy size. But say I want a stake of e.g. $1000 rather than use all the cash in my account, when I change the code to calculate the buy size using the stake it has a bizarre effect on the BCO (crude oil) plot - the y axis is completely different? (I’ve attached the plots)Any idea why this might be case? everything else is the same in both cases so I would expect the BCO plot to remain the same. The same thing happens if I manually set the size e.g. to 1
state.interface.market_order(symbol, side="buy", size=1)
In this case I see the BCO plot bars are all set to 1?The text was updated successfully, but these errors were encountered: