hi
- User
hi
- Assistant
Hello! How can I assist you today?
- User
i wanna u write strategy for trading view amount = qty by two pairs on chart and stoplose percent = 20% from amount and take profit = minmume 20% after arrive to 20% , stop loose will go to 0 amount , and next take profit is 40 % when arrive to 40% , stop loose will be the 20% profit , and next target is 60%
- Assistant
- User
hi
- Assistant
Hello, how can I assist you today?
- User
can change it to version 5 latest one V
- Assistant
Sure! Here's the same strategy in Pine Script version 5:
//@version=5 strategy("Profit Target Strategy", overlay=true) // Define inputs qty = input.float(title="Trade Size", defval=1.0) sl_percent = input.float(title="Stop Loss Percentage", defval=0.2, step=0.01) tp_percent = input.float(title="Take Profit Percentage", defval=0.2, step=0.01) // Define initial positions position_size = qty * 2 long_position = ta.position_size > 0 short_position = ta.position_size < 0 // Define profit levels profit_1 = position_size * tp_percent profit_2 = position_size * 0.4 profit_3 = position_size * 0.6 // Define stop loss levels stop_loss_1 = position_size * sl_percent stop_loss_2 = profit_1 stop_loss_3 = profit_2 // Submit orders if long_position strategy.exit("SL 1", "Long", stop=entry_price - stop_loss_1) strategy.exit("TP 1", "Long", limit=entry_price + profit_1) strategy.exit("SL 2", "Long", stop=entry_price - stop_loss_2, from_entry="TP 1") strategy.exit("TP 2", "Long", limit=entry_price + profit_2, from_entry="TP 1") strategy.exit("SL 3", "Long", stop=entry_price - stop_loss_3, from_entry="TP 2") strategy.exit("TP 3", "Long", limit=entry_price + profit_3, from_entry="TP 2") if short_position strategy.exit("SL 1", "Short", stop=entry_price + stop_loss_1) strategy.exit("TP 1", "Short", limit=entry_price - profit_1) strategy.exit("SL 2", "Short", stop=entry_price + stop_loss_2, from_entry="TP 1") strategy.exit("TP 2", "Short", limit=entry_price - profit_2, from_entry="TP 1") strategy.exit("SL 3", "Short", stop=entry_price + stop_loss_3, from_entry="TP 2") strategy.exit("TP 3", "Short", limit=entry_price - profit_3, from_entry="TP 2") // Display trades plotchar(long_position, "LONG", "▲", location.top, size = size.tiny, color=color.green, transp=0) plotchar(short_position, "SHORT", "▼", location.bottom, size = size.tiny, color=color.red, transp=0) - User
wht is entry_price
- Assistant
entry_priceis a Pine Script built-in variable that represents the price at which a strategy's last open position was entered.For example, if a long position was opened at a price of 100 and the stop loss for that position is triggered,
entry_pricewould still represent 100.This is useful because it allows you to reference the entry price of a position when setting exit orders, such as using
entry_price + profit_1to set a profit target above the entry price.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.