how can be define customised stop loss & target price #504
PythonTechh
started this conversation in
General
Replies: 1 comment 2 replies
-
@polakowo Your response will be appreciated |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently we define stop loss based average entry price, ex if entry price is 100 then initially SL will be 1% upper /lower based on direction of the trade
Trailing will be 0.5% when difference between SL & close will be greater than 1%
Existing function for SL & target:
def sl_price(ohlc, buy_sell):
"""function to calculate stop loss """
if buy_sell == "buy":
sl = ohlc["Adj Close"].iloc[-1]*0.995
elif buy_sell == "sell":
sl = ohlc["Adj Close"].iloc[-1]*1.005
return round(sl,2)
def tp_price(ohlc, buy_sell):
"""function to calculate take profit"""
if buy_sell == "buy":
tp = ohlc["Adj Close"].iloc[-1]*1.01
elif buy_sell == "sell":
tp = ohlc["Adj Close"].iloc[-1]*0.99
return round(tp,1)
i tried to used below function but its not giving me exact SL & target bcz its considering close of the candle for target & SL
pf_both = vbt.Portfolio.from_signals(ohlc.Close, entries=entries, exits=exits, direction='both',init_cash=10000,sl_stop= 0.01, tp_stop= 0.02,sl_trail=True, fees=0.0003, slippage=0.0005)
i have also tried to use "adjust_sl_func_nb" but not able to understand much
How can i put SL & TP as calculated in the function.
@polakowo - Your help will be much appreciated as i am new to this framework
Thanks
Navneet
Beta Was this translation helpful? Give feedback.
All reactions