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提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?