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が提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。

チャートでこのスクリプトを利用したいですか?