jason5480

Trailing Take Profit Trailing Stop Loss

This script demonstrated a dual trailing take profit and stop loss strategy. Where you take 50% (configurable) of the profit when a price level is reached and then you get the rest when a trailing stop loss is hit.
Sürüm Notları:
  • Logic for short positions added
  • Logic to exit when "trend" (based on the two sma) changes. This prevents overlapping positions and results in more clear demonstration.
  • Add option to enable/disable stop loss trailing
  • Add min max for inputs
  • Add plots for short take profit and stop loss
Sürüm Notları:
  • Fix bug that caused Stop Loss to not set correctly when Take Profit was triggered in the very first candle
  • Give more descriptive names to strategy orders
Sürüm Notları:
  • Fix quantity taken on "Short Take Profit" order to match the given quantity percentage given by the user
Sürüm Notları:
  • Add the option to start Stop Loss trailing from the beginning of the entry order as @Soincoin proposed
  • Trailing Stop Loss is enabled when TP order is filled not when TP target is reached
  • Simplified Take Profit and Stop Loss Price code to be more readable
  • Simplified strategy orders
  • Add offset to the plots to have a more intuitive representation
  • Fixed a bug where TP and SL orders were not filled if they triggered in the very first candle
  • Don't draw the TP price if the TP order is filled
Sürüm Notları:
  • Fixed a rare bug that caused some transactions to not exit 100% of the position size when Stop Loss and take Profit was hit at the same candle.
  • Fixed a bug that made the percentage quantity handled by the Stop loss order incorrect.
  • Changed the name of "Take Profit" odrers to "Take Profit / Stop Loss" to better reflect the fact that the order will exit if stop loss price is reached first.
  • Simplified strategy order code and added closeLongDeal and closeShortDeal variable to make code more readable.
Sürüm Notları:
  • Add check to calculate TP and SL prices when it is within backtest period to avoid unnecessary calculations and painting outside the area of interest
  • Add check to the Take Profit Executed condition that compare the high/low price with the take profit price
Sürüm Notları:
  • Replace deprecated transp argument with color.new to prevent warnings during compilation of the script
Sürüm Notları:
  • Fix a rare bug that were causing the stop loss to be calculated wrong when there was a back to back entry with the previous one
  • Use strategy.percent_of_equitity
  • Draw lines with width 1
  • Add highlighter for positive and negative price moves
Sürüm Notları:
  • Update to pinescript V5
  • Take profit steps to 0..05 and deviation steps to 0.01
Sürüm Notları:
  • Minor transparency issue
Sürüm Notları:
  • Transparency deprecation
Açık kaynak kodlu komut dosyası

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Bu komut dosyasını bir grafikte kullanmak ister misiniz?