Trailing Take Profit Trailing Stop Loss — Strategy by jason5480
By Soincoin
Performance Metrics
- Author: Soincoin
- Symbol: BINANCE:BTCUSDT
- Timeframe: 4 hours
- Net P&L: −18,324.01 USDT (−16.81%)
- Win Rate: 39.4%
- Profit Factor: 0.891
- Max Drawdown: 65,555.74 USDT (53.47%)
- Total Trades: 127
- Sharpe Ratio: −0.012
Description
Apr 18, 2021This 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.Apr 21, 2021Release NotesLogic for short positions addedLogic 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 trailingAdd min max for inputsAdd plots for short take profit and stop lossApr 24, 2021Release Notes 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 ordersApr 25, 2021Release Notes Fix quantity taken on "Short Take Profit" order to match the given quantity percentage given by the userMay 4, 2021Release NotesAdd the option to start Stop Loss trailing from the beginning of the entry order as Soincoin proposedTrailing Stop Loss is enabled when TP order is filled not when TP target is reachedSimplified Take Profit and Stop Loss Price code to be more readableSimplified strategy ordersAdd offset to the plots to have a more intuitive representationFixed a bug where TP and SL orders were not filled if they triggered in the very first candleDon't draw the TP price if the TP order is filledMay 22, 2021Release NotesFixed 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.May 24, 2021Release NotesAdd check to calculate TP and SL prices when it is within backtest period to avoid unnecessary calculations and painting outside the area of interestAdd check to the Take Profit Executed condition that compare the high/low price with the take profit priceMay 24, 2021Release NotesReplace deprecated transp argument with color.new to prevent warnings during compilation of the scriptAug 7, 2021Release NotesFix a rare bug that were causing the stop loss to be calculated wrong when there was a back to back entry with the previous oneUse strategy.percent_of_equitityDraw lines with width 1Add highlighter for positive and negative price movesOct 11, 2021Release NotesUpdate to pinescript V5Take profit steps to 0..05 and deviation steps to 0.01Oct 11, 2021Release NotesMinor transparency issueOct 11, 2021Release NotesTransparency deprecationNov 7, 2021Release NotesNew Break Even feature added!If Break Even check box is checked, then when the take profit price is hit, the stop loss will be moved to the entry price or "better" depending on the stop loss % and the trailing settings. The more strict value will be applied. Nov 28, 2021Release NotesLet's face it a Green-Red color model is more intuitive!Nov 28, 2021Release Notesminor optimizationDec 23, 2021Release Notes Thanks to the user HBGJA for pointing out and solving a bug that caused longs after a short close alerts not to be executed.Jan 1, 2022Release NotesHappy New Year!Most of the questions I had last year was about setting strategy alerts and connecting them with webhooks to your bots.So I added the ALERT MESSAGES section to show you how you can send different execution messages to your bots and execute your orders!If you are using the 3Commas bots all you have to do is to put your bot IDs and email token in the strategy settings. Add an alert, check the webhook, set the URL and write the [[strategy.order.alert_message]] in the message text box.If you are using any other bot system that can be used with webhooks, you can always modify the messages according to your Bots APIMany code refactorings and optimizations to better use this script as a template and plug your own strategy at easeJan 1, 2022Release NotesAdd bot tagsJan 3, 2022Release NotesFix quotes around string message fields of 3Commas messages (message_type, email_tocken, action) Jan 4, 2022Release NotesLet the user put the whole alert message as an argument. Strategy will forward it to the {{strategy.order.alert_message}} place holder as it isJan 6, 2022Release NotesBug fix: (rare/minor) Remove 'strategy.position_size == 0' condition in stop loss calculation that made the very first stop loss price target to be calculated based on previous 'strategy.position_avg_price' instead of 'close' if the previous position closed exactly one bar before! Jan 12, 2022Release NotesNEW FEATURE! After many requests for an ATR based trailing approach I added: A new take profit method that is ATR based. Now you can set the length and the multiplier for long/short in the settings menu. A new deviation method that is also ATR based. Deviation is used for take profit trailing! A new stop loss method that is ATR based. Now you can set the length and the multiplier for long/short in the settings menu.Jan 24, 2022Release NotesNEW FEATURE RELEASE (TOO RISKY :P) Risk/Reward Ratio Take Profit type added! Now you can set price target based on RR and your stop loss Risk management for entry quantity calculation is added! You can set what percentage you are willing to risk for every trade and the amount for the entry is calculated accordingly Leverage variable is added that multiplies the initial amount of every trade Set minimum trade price that your exchange support Set max drawdown percentage to stop strategy Feb 16, 2022Release NotesRe-write the risk quantity formula to clamp the amount between minimum trade and the equity (multiplied by the leverage)Add the option for different leverage factors for long and short tradesFeb 26, 2022Release NotesThis script development has gone far beyond my expectations and from a combination of trailing take profit and stop loss, had became a template for new strategies to develop. New interesting feature requests was implemented. However, I decided to create a separate script that will work as a template for new strategies and that can be found [here](tradingview.com/script/n8bgynWl-Template-Trailing-Strategy/) with even more features! The features that are irrelevant from the initial purpose of this script were removed to minimize the clutter. At this point I want to thank all those people in the community that helped this to become a robust implementation by reporting several bugs to me after an extensive testing and thoroughly checking edge cases in different market conditions!Jul 3, 2022Release NotesUse time_filters libraryJul 9, 2022Release NotesReplace deprecated "when=" with if statements in strategy callsJul 13, 2022Release NotesChange fastMA default color to yellowJul 29, 2022Release NotesIncrease max labels to 150Increase max lines to 300Minor refactoringAug 9, 2022Release NotesUpdate time_filters librarySep 2, 2022Release NotesSome minor label/color changesMinor refactoring of the codeJan 10, 2023Release Notessmall refactoringJan 17, 2023Release NotesUpdate time_filters library versionMar 19, 2023Release Notes Update time_filters library versionNov 24, 2023Release NotesUse the 'chrono_utils' library for the date-time window filterSep 19, 2024Release Notes Add different alert messages per event Update 'chrono_utils' library Use enumsMar 1Release Notes Update to pinescript version 6