a_maxwell

PSAR-risk strategy

a_maxwell Cập nhật   
This indicator is a tool to know at all times at what price to close a trade, using entry and exit SAR values as hard limits, to protect profits or to not risk more than expected.
Parameters:
  • Source: a PSAR source with calibrated parameters to use as entry and hard exit. Be it the TradingView's official one or TradingView's legacy SAR ported by me (Legacy PSAR).
  • Commission: broker/exchange commission to account for when executing buy/sell orders.
  • Risk: a statistically determined risk of how much loss to tolerate with the current SAR parameters. This doesn't account for commission, it's just a raw loss below entry price. A stop-limit sale is suggested at this price.
  • Milestone #: when reaching a certain percentage above entry, what is the new exit criteria (M# exit). Each milestone must be of a higher value than the previous one, in order to be considered.
  • M# exit: negative values don't account for commission and are raw losses below entry price. Values greater than or equal to zero represent the percentage of the peak profit, with commission accounted for, to sell at. A value of zero means recouping the original investement.

Alerts:
  • Entry condition: SAR-signaled entry. Market price entry or a pre-programmed stop-loss buy at the previous SAR value is suggested.
  • Soft exit condition: this tool's exit. Limit price exit at this tool's current value or a pre-programmed stop-limit sale at the latest available value is suggested.
  • Hard exit condition: SAR-signaled exit. Market price exit or a pre-programmed stop-loss sale at the previous SAR value is suggested

Case study
Let's assume a commission of 0.1%, a studied risk of -5% with the current SAR parameters (you have observed that most good entries don't need to come near 5% down before starting an upside swing), only one programmed milestone at 3% securing a profit of 25% of the peak profit reached.
Let's say that we have an entry executed at $100 with the current SAR value 3% below the current candle. Since -3% > -5% programmed risk, the exit will be marked at the SAR value. If in that candle or in a future one, we reach $103 (3% milestone met) the current peak profit is ~2.8% (($103/$100) * (1 - 0.001)^2) so an exit will be marked at 25% of 2.8%, meaning 0.7% or an exit price of $100.9, if that's higher than the current SAR. The greater value between the current SAR or this indicator calculated value is the current exit price.
Phát hành các Ghi chú:
Entry detection logic made for robust for very rare corner cases.
Phát hành các Ghi chú:
Added alert for when a new milestone has been met, suggesting an update of the exit condition as soon as possible.
Phát hành các Ghi chú:
Improved alert messages and triggering.
Phát hành các Ghi chú:
When soft exit condition is equal to hard exit condition, only a hard exit alert will be triggered.
Phát hành các Ghi chú:
* Risk now accounts for commission, showing true risk.
* After seeing in practice the live "re-drawing", soft exit condition has been consolidated for same behavior in live and historic bars.
Phát hành các Ghi chú:
Corrected exit condition drawing if the exit happens in a bull candle. This could cause a discrepancy between soft exit alert and value in graphic in very rare cases.
Phát hành các Ghi chú:
  • Soft exit alert simply trigger with a bearish candle and its low being less than its PRS value. Either current low must be less than previous PRS value or current close must be lower than current PRS value to account for a valid exit.
  • New milestone alert won't trigger if the previous SAR value (current "hard exit") is already greater than the milestone-based "soft exit".
Phát hành các Ghi chú:
Usability and presentation improvements:
  • Default format of PRS value is now price with a precision of 2 (two decimal digits). This avoids alerts with price with 8 decimal digits.
  • All parameters are now validated to prevent erratic behavior due to illegal values.
  • Some parameters now have increments in order of their expected values or suggested step size. Examples: "Commission" moves in increments of 0.1 (%) and "Risk" in increments of 0.5 (%), instead of the default step size of 1.
Phát hành các Ghi chú:
Removed price formatting, so that it can also work correctly with crypto values.
Phát hành các Ghi chú:
Indicator outputs more information for the alerts, without adding noice to the chart. All alerts now send exact execution price information; ideal for consumption by bots or additional reference for users.
Phát hành các Ghi chú:
Fix for the new "Hard Exit" output information: it was not plotting after the soft exit condition.
Phát hành các Ghi chú:
Hard exit price was already cleared by the time it was attempted to be shown in the hard exit alert; now that value will be cleared in the next candlestick.
Phát hành các Ghi chú:
Small code rework: hard exit value available for the alert but not plotted in the candlestick of the event.
Phát hành các Ghi chú:
Migration to new TradingView alert system in preparation to script migration from indicator to strategy. New alerts can be sent to either a Discord webhook or as a TradingView notification. They no longer need to be configured by the user, a single alert covers all events (entry, new milestone, soft exit, and hard exit), triggered once per bar.
Phát hành các Ghi chú:
  • Minor fix in graphical representation of a hard exit
  • Input parameters have been organized for a more logical understanding, after TradingView's new feature implementation
Phát hành các Ghi chú:
Changes:
  • Alerts now give chart periodicity information, should you wish to send alerts for the same asset in different timeframes.
  • Only crypto alerts are formatted with as many decimals as possible; any other asset type is formatted as currency (two decimal digits).
  • Support for TradingView's new chart color transparency.
Phát hành các Ghi chú:
Hard exit (market value) sale price fixed in alerts.
Phát hành các Ghi chú:
alerts now provide trade performance (profit) at close (sell alert).
Mã được bảo vệ
Tập lệnh này được xuất bản mã nguồn đóng và bạn có thể sử dụng một cách tự do. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ. Bạn không thể xem hoặc sửa đổi mã nguồn.
Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?