Tradingview pine script to convert Strategy to Study with trailing stoploss

Job ID: 31711625

Budget: $30 – $250 USD

//The requirements as below
//convert the below strategy to study that has alert message to connect to 3commas bot
// The strategy is based on 2 conditions for BUY signal. We need to make sure the system doesn’t make another BUY signal if the //position is already open. Same for the SELL signal
//We need to calculate the number of bars after making the BUY signal, if the position still open for more than 40 bars then we //need to reduce the takeprofit & stoploss to 50%
// We need to write a code for trailing stoploss, once we each to the initial takeprofit target we should move the stoploss up by //certain percentage % to ensure maximum profit

//@version=4
strategy(title="Oct 3 Drop v1", initial_capital=1000,currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100,commission_type=strategy.commission.percent, commission_value=0.075,overlay=true, max_bars_back = 4900,scale = scale.right, linktoseries = true)
takeprofitlow = input(2.4, step=0.1, title='Take Profit Low %', type=input.float, minval=0.01)/100
stoplosslow = input(16, step=0.1, title='Stop Loss Low %', type=input.float, minval=0.01)/100
takeprofithigh = input(1.6, step=0.1, title='Take Profit High %', type=input.float, minval=0.01)/100
stoplosshigh = input(6, step=0.1, title='Stop Loss High %', type=input.float, minval=0.01)/100
takeprofit_level_low = strategy.position_avg_price * (1 + takeprofitlow)
takeprofit_level_high = strategy.position_avg_price * (1 + takeprofithigh)
stoploss_level_low = strategy.position_avg_price * (1 - stoplosslow)
stoploss_level_high = strategy.position_avg_price * (1 - stoplosshigh)

buy1 = (close <= 40000)
if (buy1)
strategy.entry("BuyLow", strategy.long)
buy2 = (close <= 50000)
if (buy2)
strategy.entry("BuyHigh", strategy.long)
sell1 = (close >= takeprofit_level_low or close <= stoploss_level_low) // Please add the trailing stoploss coding based on %
sell2 = (close >= takeprofit_level_high or close <= stoploss_level_high) //// Please add the trailing stoploss coding based on %
strategy.close("BuyLow", when = sell1, alert_message = "Sell-Low")
strategy.close("BuyHigh", when = sell2, alert_message = "Sell-High")
Related categories: Pine Script Trading