SimpleCryptoLife

TrailingStops

SimpleCryptoLife Uppdaterad   
Library "TrailingStops"
This library contains functions to output trailing stop lines.

f_marketStructureStop(_restartMode, _flipMode, _restartLowIn, _restartHighIn)
  Parameters:
    _restartMode - Defines how the stop lines persist. Allowed values are:
  • "Always On" - The stop lines are always present and they just reset when they're crossed.
  • "Flip" - The stop lines flip when they're crossed.
  • "Manual" - The stop lines turn off when they're crossed, and turn back on again when _restartLowIn or _restartHighIn are passed into the function as true.
    _flipMode - Defines whether the stop lines are broken by wicks or closes. Allowed values are "Wick", and "Close".
    _restartLowIn - If _restartMode is "Manual", passing this parameter as true restarts the Low stop line.
    _restartHighIn - If _restartMode is "Manual", passing this parameter as true restarts the High stop line.
@returns - floats for the Low and High stop line.
Versionsinformation:
v2

Updated:
f_marketStructureStop(_restartMode, _flipMode, _restartLowIn, _restartHighIn, _strictMode)
New parameter:
    _strictMode - If false, this library uses Enhanced Simple Highs/Lows from the MarketStructure library. If true, it uses True Highs/Lows.

Also added some explanation about the behaviour of the stop lines if you choose the Flip and Close options. In this case, the stop line that's displayed can regress on a wick, but the underlying value for flipping does not regress. This is by design and is not a bug. The function doesn't know when you might take a position in either direction. If you choose to take a long when the long stop line has been pierced by a wick but not a close, it will display the appropriate value for a stop on that bar, which is the bar's Low.
Versionsinformation:
v3
Fixed default value for restartMode
Versionsinformation:
v4

New function:
@function f_complexStop - Outputs a stop line using more complex criteria than f_marketStructureStop, but still based on market structure generated by Local Lows and Highs. This is NOT a market structure indicator (for that, I've written a free, open-source indicator, and you could easily construct one yourself using my MarketStructure library). This function gives intuitive, rule-based places to put a stop loss; that's all.
@param float _high - Defaults to the High of the current chart bar. Included for HTF compatibility.
@param float _low - Defaults to the Low of the current chart bar. Included for HTF compatibility.
@param float _close - Defaults to the Close of the current chart bar. Included for HTF compatibility.
@param string _flipMode="Wick" - Defines whether the stop lines are broken by wicks or closes. Allowed values are "Wick", and "Close". If you choose "Close", the stop line that's displayed can regress on a wick, but the underlying value for flipping does not regress. This is by design and is not a bug. The function doesn't know when you might take a position in either direction. If you choose to take a long when the long stop line has been pierced by a wick but not a close, it will display the appropriate value for a stop on that bar, which is the bar's Low.
@param float _lowBuffer - You can add a buffer to the low stop.
@param float _highBuffer - You can add a buffer to the high stop.
@returns - floats for the Low and High stop lines. Bools for whether the lines are active.

Differences between f_complexStop compared to f_marketStructureStop:
It's more complex ;-) It gets stopped out less because it uses the principle that the market goes through three phases : Compression, Expansion, and Trend. The stops do not trail, or trail less, in Compression.
It uses only Enhanced Highs and Lows and there is no option to use Strict Highs and Lows.
It does not flip; the lines are always on. Instead of being set to na, the lines have active and inactive states that are output.
You can add a buffer to the stops, to make it less likely to get stopped out.

Having trouble publishing this update #fingerscrossed

Pinebibliotek

I sann TradingView-anda har författaren publicerat denna Pine-kod som ett bibliotek med öppen källkod så att andra Pine-programmerare från vår community kan återanvända den. Hatten av för författaren! Du kan använda det här biblioteket privat eller i andra publikationer med öppen källkod, men återanvändning av den här koden i en publikation regleras av våra ordningsregler.

Frånsägelse av ansvar

Informationen och publikationerna är inte avsedda att vara, och utgör inte heller finansiella, investerings-, handels- eller andra typer av råd eller rekommendationer som tillhandahålls eller stöds av TradingView. Läs mer i Användarvillkoren.

Vill du använda det här biblioteket?

Kopiera följande rad och klistra in det i ditt skript.