TradingView
TanHef
17 May 2023 00:55

Limit Order + ATR Stop-Loss [TANHEF] 

Bitcoin all time history indexINDEX

Açıklama

This indicator enables interactive placement of limit or stop-limit orders with a trailing ATR stop-loss and optional profit target (with alerts). Refer to the images below for further clarification.

Why use a trailing stop-loss?
A trailing stop-loss serves as an exit strategy when price moves against you, while also allowing you to adjust the exit point further into profit when price moves favorably. The ATR (Average True Range), a reliable measure of volatility, acts as an effective risk management tool, functioning as a trailing stop-loss.

Indicator Explanation
  • Initial indicator placement: Select Long Limit or Long-Stop Limit order.
  • Change Entry Type: Switch between Long and Short within settings.
  • Modify entry price: Drag circle, adjust in settings, or re-add indicator to chart.
  • Optional Profit Target: Use Risk/Reward ratio or specify price.
  • Entry anticipation: Estimated ATR stop-loss and profit target as blue circles (fluctuates with volatility changes).
  • Entry triggered: Actual ATR stop-loss and profit target plotted.
  • Exit conditions: Stop-loss or profit target hit, exit entry.
  • Update Frequency: Continuously, Bar Open, or Bar Open on entry then continuously.
  • ATR Overlap: no entry occurs if the ATR overlaps with price (stop-loss 'hit' already on entry bar)
  • Table: Displays input settings selected.
  • Show Only On Ticker: Ability to hide indicator on other tickers.



Long Limit


Long Stop-Limit


Short Limit


Short Stop-Limit



Alerts
1. 'Check' alerts to use within indicator settings (entry, trailing stop hit, profit target hit, and failed entry).
2. Select 'Create Alert'
3. Set the condition to 'Limit Order + ATR Stop-Loss''
4. Select create.

Additional details can be added to the alert message using these words in between Curly (Brace) Brackets:
  • {{trail}} = ATR trailing stop-loss (price)
  • {{target}} = Price target (price)
  • {{type}} = Long or Short stop-loss (word)
  • {{traildistance}} = Trailing Distance (%)
  • {{targetdistance}} = Target Distance (%)
  • {{starttime}} = Start time of position (day:hr:min)
  • {{maxdrawdown}} = max loss
  • {{maxprofit}} = max profit
  • {{update}} = stoploss update frequency
  • {{entrysource}} = entry as 1st bar source (yes/no)
  • {{triggerentry}} = Wick/Close Trigger entry input
  • {{triggerexit}} = Wick/Close Trigger exit input
  • {{triggertarget}} = Wick/Close Trigger target input
  • {{atrlength}} = ATR length input
  • {{atrmultiplier}} = ATR multiplier input
  • {{atrtype}} = ATR type input
  • {{ticker}} = Ticker of chart (word)
  • {{exchange}} = Exchange of chart (word)
  • {{description}} = Description of ticker (words)
  • {{close}} = Bar close (price)
  • {{open}} = Bar open (price)
  • {{high}} = Bar high (price)
  • {{low}} = Bar low (price)
  • {{hl2}} = Bar HL2 (price)
  • {{volume}} = Bar volume (value)
  • {{time}} = Current time (day:hr:min)
  • {{interval}} = Chart timeframe
  • {{newline}} = New line for text

Sürüm Notları

Fixed label issue during active entry.

Sürüm Notları

Removed unnecessary moving average inputs.

Sürüm Notları

Alerts now function as intended.

Update Stop-Loss Frequency:
  • Always = update continuously. (Trailing)
  • Bar Open = update bar from prior close. (Trailing)
  • Entry Bar Open, then Always = update bar from prior close for entry bar, then every bar after updates continuously. (Trailing)
  • Never = static, not updated after entry open. (Non-Trailing)
Yorumlar
vincentauvv
@TanHef, thanks for sharing this script. I found it very useful. Have been manually adjusting the "start point" to trail the many Longs and shorts.
Could you guide how to automatically adjust the "start point" to the bar's close when there are Long Signal (SMA30 crossover SMA50) and Short Signal (SMA30 crossunder SMA50).
Thank You.
jaysea777
Perfect, I am with IBKR and love TV.... I finally switched from Fidelity and also love trading from the charts but was disappointed there was no trailing stop.
TanHef
@jaysea777, Thanks
j3ffrey54749
@jaysea777, also with IBKR and love TV and couldn't believe no trailing stops.. does this fix this problem, or as I understand it you still have to do the stop moves your self? this just automates the alert side?
TanHef
@j3ffrey54749, At this time this indicator just creates alerts. You can either manually exit positions after receiving an alert or use webhooks to automate it with IBKR.

TradingView previously stated: "Strategy trading is limited to the backtesting mode only. Automated strategy trading with a brokerage account is not available on TradingView yet. We are considering implementing this in the future." (therefore, possibly in the future we can directly integrate an ATR trailing stop-loss)
Mattyd777
Hello again, I didnt get a reply the last time I asked is someone able to reply, how do I get the start point to always be at current time in a chart? If I change charts how is it possible to have the start point with the green circle to be at the current point so I can create a TP/SL entry at the current point in the chart im currently in??

Thanks in advance
TanHef
@Mattyd777, To set the start point dot at the current time in a chart, I recommend you remove then re-add the indicator to the chart each time, but you can adjust the date/time within the indicator's settings.

Unfortunately, the start point can't always be automatically set to the most recent time but you could modify the default time in the pinescript code to a recent time so if you reset settings to default it is still visible a recent time. To do this you would change the code to have xBarTime of timestamp("Jun 01 2023 12:00:00") instead of 0, as seen below:

xBarTime = input.time(timestamp("Jun 01 2023 12:00:00"), title='', inline='Start', group='Interactive Position', tooltip=tt_Interact, confirm=true)
Mattyd777
@TanHef, thanks for your reply, what a shame as scalping from one stock to the next at random ad hoc times the time spend setting up a scalp with doing this reach time would really limit the buy in point, doesn't make it feesable but thank you anyway it's a great add-on all the same thank you
ibayrak17
You have 2 similar indicators and they are great
But can you update it so that it works without us intervening?
TanHef
@ibayrak17, Thanks. Can you describe what you'd like to work without having to intervene?
Daha Fazla