Closed youshaoqing closed 3 years ago
I would have to see your data yo be sure. But looking at the plot it appears to me that the signals have values of simply 1.0 and 0.0 therefore they are being plotted on their own axis (see axis on right). This is just my guess without seeing the data. I am not sure what you mean klines, but if you want the signals near the market data then you have to give them values close yo the values of the market data. Alternatively, if you want them just close to the center of the plot, you can pass ylim=(low,high)
into the addplot for the signals choosing low,high values that will expand the right axis appropriately. Hth
Sometimes I like to put the signals slightly above, or slightly below the market data. You can see this in cells In [7]:
and In [12]:
of the addplot examples notebook where the signal
value is set to either 0.99*price
or 1.01*price
. This is a quick and easy way to get the signal markers to appear near the market data; but it is not the best way, because with this approach the markers will be further from the data for larger prices and closer to the data for smaller prices.
To place the markers at equal distances from the data, an adequate solution is to add or subtract a small percentage of the entire y-axis range. To do this, we first calculate the range, and then take 2% (or 3% or whatever you feel looks nice) and set the signal to that value above or below the high or low for the signal date:
yrange = max(df['High']) - min(df['Low'])
offset = yrange * 0.02 # 2% of range
# Then do something like this to put sell signals
# above the data, and buy signals below the data:
if sell_signal[date] != np.nan:
signals.append(df['High'][date]+offset) # add offset above High
if buy_signal[date] != np.nan:
signals.append(df['Low'][date]-offset) # subtract offset below Low
hth
Thanks! Your advice helps me a lot.
I draw the signals on the picture, but they appear on the top and bottom of the pictures, how can I draw them on the klines?
the code now about drawing :