Volatility Trailing Stop

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #135625 quote
    bertl
    Participant
    New
    Hallo Forumsmitglieder,
    ich bräuchte mal eure Hilfe!
    Ich habe einen Code für einen “Volatility Trailing Stop” der auf ATR basiert gefunden.
    Dieser Code ist für thinkorswim programmiert.
    Unten habe ich den Code eingefügt.
    Ich wäre euch sehr dankbar, wenn jemand versuchen könnte, diesen Code für PRT zu programmieren?
    Vielen Dank im Voraus.
    Bertl
    Ein Foto, wie das Ganze ausschaut,  hänge ich auch mit an.
    ## Volatility Trailing Stop
    ## Version 1.1
    ## By Steve Coombs
    ## This ATR Trailing Stop is calculated using the Highest Close in an uptrend or
    ## the Lowest Close in a downtrend, rather than just the Close that is used
    ## in the standard TOS ATRTrailing Stop
    
    #input StopLabel = yes; #ATRStop Label is Stop value from yesterdays ATR calculation
    input ATRPeriod = 10;
    input ATRFactor = 1.5;
    input firstTrade = {default long, short};
    input averageType = AverageType.SIMPLE;
    
    Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);
    def trueRange = TrueRange(high, close, low);
    def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);
    
    def state = {default init, long, short};
    def trail;
    def mclose;
    switch (state[1]) {
    case init:
       if (!IsNaN(loss)) {
         switch (firstTrade) {
         case long:
           state = state.long;
           mclose = close;
           trail =  close -loss;
         case short:
           state = state.short;
           mclose = close;
           trail = close + loss;
       }
       } else {
          state = state.init;
          trail = Double.NaN;
          mclose = Double.NaN;
       }
    case long:
       if (close > trail[1]) {
           state = state.long;
           mclose = Max(mclose[1], close);
           trail = Max (trail[1], mclose -loss);
       } else {
           state = state.short;
           mclose = close;
           trail = mclose + loss;
       }
    case short:
       if (close < trail[1]) {
           state = state.short;
           mclose = Min(mclose[1], close);
           trail = Min(trail[1], mclose + loss);
       } else {
           state = state.long;
           mclose = close + 0;
           trail =  mclose -loss;
       }
    }
    
    #AddLabel(StopLabel, "ATR Stop =" + Round(trail[1], 2), color = Color.BLUE);
    plot TrailingStop = trail;
    
    TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
    TrailingStop.SetLineWeight(lineWeight = 3);
    TrailingStop.DefineColor("Buy", GetColor(5));
    TrailingStop.DefineColor("Sell", GetColor(1));
    TrailingStop.AssignValueColor(if state == state.long
       then TrailingStop.Color("Sell")
       else TrailingStop.Color("Buy"));
    
    
    Volatility-Trailing-Stop.jpg Volatility-Trailing-Stop.jpg
    #135670 quote
    Nicolas
    Keymaster
    Master

    Dies ist ein einfacher Supertrend mit ATR, der durch einen gleitenden Durchschnitt der X-Periode geglättet wird. Nichts Neues, in unserer Bibliothek finden Sie viele Arten von ATR-Trailing-Stopps: https://www.prorealcode.com/tag/trailing-stop/ https://www.prorealcode.com/tag/supertrend/

    bertl thanked this post
    #135876 quote
    bertl
    Participant
    New

    Hallo Nicolas,

    vielen Dank für ihre schnelle Antwort mit den beiden Links zur Bibliothek.
    Da finden sich viele schöne Codes! Das werde ich mir einmal alles durchlesen … ich glaube, ich bin aber schon fündig geworden.

    Vielen Dank und ein schönes Wochenende.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Volatility Trailing Stop


ProBuilder: Indikatoren & Custom Tools

New Reply
Author
author-avatar
bertl @bertl Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by bertl
5 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indikatoren & Custom Tools
Language: German
Started: 06/11/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...