Replies: 1 comment
-
After scouting internet for a day i came to a conclusion that apparently neither entry limit and entry stop orders are supported due to performance reasons. I came up with this solution: def generate_order_signals(signal: pd.Series, side: TradeDirection, order_type: int, price: pd.Series, lifetime: int, high: pd.Series, low: pd.Series):
if lifetime > 0:
signal = signal.ffill(limit=lifetime)
price = price.ffill(limit=lifetime)
new_signal = pd.Series(data=[0]*len(signal), index=signal.index)
if (side == TradeDirection.Long and order_type == 0) or (side == TradeDirection.Short and order_type == 1):
new_signal.loc[(signal == 1) & (price > low.shift(-1))] = 1 # Limit long or stop short
elif (side == TradeDirection.Long and order_type == 1) or (side == TradeDirection.Short and order_type == 0):
new_signal.loc[(signal == 1) & (price < high.shift(-1))] = 1 # Stop long or limit short
return new_signal
df['enter_long'] = generate_order_signals(df['enter_long'], TradeDirection.Long, 0, limit_long, 0, df['high'], df['low']) This function foward-fills signals in order to make limit/stop order valid for multiple candles. Then each candle with a signal is evaluated, checking whether next candle goes far enough top fill the order. Candles that would result in a fill keep a signal, other signals are discarded. If someone looked into it and commented on validity of this approach i would be extremely grateful. Since this turned out to be simpler than i anticipated, im not sure if this is valid or whether i am reinventing a wheel and vectorbt already offers such functionality. Thanks! 🙏 |
Beta Was this translation helpful? Give feedback.
-
How can i simulate entering on stops? For example, going long if a certain price above current market price is reached?
from_signals()
method hasstop_entry_price
, but from reading docs i see it is supposed to be a value of enumStopEntryPrice
. How can i specify actual stop entry price?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions