-
Notifications
You must be signed in to change notification settings - Fork 669
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
Hey all,
Firstly, thanks Daniel for the development of this package - I really like it!
I'm trying to implement markers in my plot for marking my buying/selling signals and did not quite understand/made it work from the documentation given. I have the following code:
ticker = " ^omx "
df = yf.download(ticker, period = "1y", interval = "1d", progress = False, rounding = True)
close = df["Close"].values
df["Row"] = df.reset_index().index
rows = df["Row"]
x = rows
y = close
z = np.polyfit(x, y, 1)
p = np.poly1d(z)
df["Trendline"] = p(x)
df["linearreg"] = talib.LINEARREG(df["Close"],timeperiod=14)
df["stddev"] = talib.STDDEV(df["linearreg"],timeperiod=14)*2
short = df["Trendline"] + df["stddev"]
long = df["Trendline"] - df["stddev"]
df["Go short"] = np.where((df["Close"] > short),1,0)
df["Go long"] = np.where((df["Close"] < long),1,0)
slope = round(z[0],1)
buydates,selldates = [],[]
buyprice,sellprice = [],[]
for index,row in df.iterrows():
if row["Go short"] == 1:
buydates.append(index)
buyprice.append(row["Close"])
if row["Go long"] == 1:
selldates.append(index)
sellprice.append(row["Close"])
This code works for plotting the markers on a plt.plot as:
plt.figure(figsize=(15,15))
plt.plot(df["Close"])
plt.scatter(df.loc[buydates].index,df.loc[buydates].Close,marker="v",color="r")
plt.scatter(df.loc[selldates].index,df.loc[selldates].Close,marker="^",color="g")
plt.show()
But I can't make it work on mpf.plot. I've tried just copying plt.scatter(*kwargs) as
mpf.make_addplot(df.loc[selldates].index,df.loc[selldates].Close,marker="^",color="g")
but since the make_addplot only takes 1 positional argument, I don't know how to proceed.
So how do I create the markers in mpf.make_addplot(*kwargs) ?
Many thanks in advance.
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested