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
Again I ran into an issue. If i have multiple panes to display, I created multiple axes. As I keep pressing the right key, one bar at a time gets added. But the zoom factor also increases so much so that just after 4 right key presses both the charts are in a max zoomed state . I am attaching the full code below.
I tried with mulltiple docks like shown in the examples/dockable.py. I end up with the same result
I am attaching the full code for reference
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QWidget
from PyQt6.QtGui import QKeyEvent
from pyqtgraph.dockarea import DockArea, Dock
from PyQt6.QtCore import QDateTime, Qt
import yfinance as yf
import pandas as pd
import finplot as fplt
stock_ohlcv_data=None
index_ohlcv_data=None
backtestdate_Idx=None
backtestdate_Idx1=None
plots={}
def load_price_history(symbol, interval,backtest_date):
global backtestdate_Idx, stock_ohlcv_data,index_ohlcv_data,backtestdate_Idx1
#print("Getting data for: ",symbol)
#print("Back test Date: ",backtest_date)
stock_ohlcv_data = yf.download(symbol + ".NS",interval=interval)
stock_ohlcv_data.dropna()
stock_ohlcv_data["time"] = pd.to_datetime(stock_ohlcv_data.index)
stock_ohlcv_data = stock_ohlcv_data.drop(["Adj Close"], axis=1)
#print(stock_ohlcv_data)
backtestdate_Idx = stock_ohlcv_data.index.get_loc(backtest_date)
#print("Starting Index of the Backtes Date:",backtestdate_Idx)
index_ohlcv_data = yf.download("^NSEI",interval=interval)
index_ohlcv_data.dropna()
index_ohlcv_data["time"] = pd.to_datetime(index_ohlcv_data.index)
index_ohlcv_data = index_ohlcv_data.drop(["Adj Close"], axis=1)
#print(index_ohlcv_data)
backtestdate_Idx1 = index_ohlcv_data.index.get_loc(backtest_date)
#return stock_ohlcv_data
def compute_data():
global backtestdate_Idx,backtestdate_Idx1
pricedf=stock_ohlcv_data[:backtestdate_Idx]
indexdf=index_ohlcv_data[:backtestdate_Idx1]
#print(pricedf)
#print(indexdf)
price = pricedf ["Open Close High Low".split()]
ma20 = pricedf.Close.rolling(20).mean()
ma50 = pricedf.Close.rolling(50).mean()
volume = pricedf ["Open Close Volume".split()]
index= indexdf["Open Close High Low".split()]
plot_data= {'stockprice':price,
'ma20':ma20,
'ma50':ma50,
'volume':volume,
'indexprice':index,
}
return plot_data
def on_key(event):
global backtestdate_Idx,backtestdate_Idx1
# test for a specific key
if event.key() == Qt.Key.Key_Right:
backtestdate_Idx+=1
backtestdate_Idx1+=1
print("Right Key. New Index=",backtestdate_Idx)
update_plot()
#update_chart()
elif event.key() == Qt.Key.Key_Left:
backtestdate_Idx-=1
backtestdate_Idx1-=1
print("Left Key. New Index=",backtestdate_Idx)
update_plot()
#update_chart()
def update_plot():
data=compute_data()
#print(data)
for k in data:
if data[k] is not None:
plots[k].update_data(data[k], gfx=False)
for k in data:
if data[k] is not None:
plots[k].update_gfx()
def update_chart():
ax0.reset() # remove previous plots
ax1.reset() # remove previous plots
data=compute_data()
global plots
plots["ma20"] = fplt.plot(data['ma20'], legend = "MA-20", ax = ax0)
plots["ma50"] =fplt.plot(data['ma50'], legend = "MA-50", ax = ax0)
plots["stockprice"]=fplt.candlestick_ochl(data['stockprice'], ax = ax0)
plots["volume"]=fplt.volume_ocv(data['volume'], ax = axo)
plots["indexprice"] = fplt.candlestick_ochl(data['indexprice'], ax = ax1)
fplt.refresh() # refresh autoscaling when all plots complete
if name == "__main__":
plots = {}
fplt.y_pad = 0.07 # pad some extra (for control panel)
fplt.max_zoom_points = 7
ax0,ax1= fplt.create_plot("Study", rows=2, init_zoom_periods=300)
axo = ax0.overlay()
ax0.vb.win.keyPressEvent = on_key
#ax1.vb.win.keyPressEvent = on_key
load_price_history(symbol="TCS", interval="1D",backtest_date= "2023-09-06")
update_chart()
fplt.show()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Again I ran into an issue. If i have multiple panes to display, I created multiple axes. As I keep pressing the right key, one bar at a time gets added. But the zoom factor also increases so much so that just after 4 right key presses both the charts are in a max zoomed state . I am attaching the full code below.
I tried with mulltiple docks like shown in the examples/dockable.py. I end up with the same result
I am attaching the full code for reference
Beta Was this translation helpful? Give feedback.
All reactions