a_maxwell

PSAR-risk strategy

a_maxwell 已更新   
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.
版本注释:
Entry detection logic made for robust for very rare corner cases.
版本注释:
Added alert for when a new milestone has been met, suggesting an update of the exit condition as soon as possible.
版本注释:
Improved alert messages and triggering.
版本注释:
When soft exit condition is equal to hard exit condition, only a hard exit alert will be triggered.
版本注释:
* 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.
版本注释:
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.
版本注释:
  • 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".
版本注释:
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.
版本注释:
Removed price formatting, so that it can also work correctly with crypto values.
版本注释:
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.
版本注释:
Fix for the new "Hard Exit" output information: it was not plotting after the soft exit condition.
版本注释:
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.
版本注释:
Small code rework: hard exit value available for the alert but not plotted in the candlestick of the event.
版本注释:
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.
版本注释:
  • 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
版本注释:
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.
版本注释:
Hard exit (market value) sale price fixed in alerts.
版本注释:
alerts now provide trade performance (profit) at close (sell alert).
受保护脚本
该脚本是闭源发布的,您可以自由使用它。您可以收藏它以在图表上使用。您无法查看或修改其源代码。
免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?