jason5480

Template Trailing Strategy

This script is meant to be used as a generic template for new strategies. Take Profit, Stop Loss logic is provided out of the box with (or without) their trailing variations while the trailing for entry and exit orders can also be enabled and be configured!
Custom quantity risk management is provided along with the ability to set custom signal messages that can be send through webhook to your bot platform.
To create a new Strategy copy this script and replace the openLongPosition, closeLongPosition, openShortPosition, closeShortPosition variables under the STRATEGY section with your own logic.
Take some time to check the different options on all sections to have better understanding of the capabilities that script provide you for free!
เอกสารเผยแพร่:
  • Add the option to select different moving average types for fast and slow MA instead of a fixed SMA.
เอกสารเผยแพร่:
  • Make use of math_utils library
เอกสารเผยแพร่:
  • Add an option to ignore close signals from crossover/crossunder so users can play exclusively with stop loss and take profit configuration
  • Fix some typos
เอกสารเผยแพร่: Feature Release:
  • Now Strategy support two types of deal conditions (Internal and External). Internal is the "build-in" two MA cross over/under logic that is standalone. However, as proposed by @EltAlt now simple External deal conditions can also be constructed by this strategy! User can add his favorite indicator in the same chart as this strategy and use the output of this indicator as an External Input for the start and end Deal Conditions to open and close position and enter and exit orders.
  • Add option for different/secondary Stop Loss % and ATR Multipliers after the Take Profit Target is reached. As suggested by @PlusUltraTrading this will give more flexibility to the end user when he wants to apply more loose/strict stop loss rules after the initial take profit target was hit.

    At this point I want to thank all those who contributed with their ideas, comments and their personal time. This motivated me to build this template at its generic enough, but also useful for everyone current state. Use it wisely!
เอกสารเผยแพร่: FETURE RELEASE:
  • Now you can set multiple Take Profit Targets for each entry! The initial target may use different method that the additional step targets (e.g. set initial TP at 3ATR and the next target at +5% on top of the initial TP price)
  • Beatification of the Input tab with emojis and "tabs" when sub-menus are implied.
  • Minor Bug and typo fixes for previously released features.
  • Several refactorings in the code, added descriptions for each module.
เอกสารเผยแพร่: \nFix Release:
  • The minimum number of take profits can be 0
  • Some code cleanup
เอกสารเผยแพร่:
  • Add session time filter
  • Now user can chose between three different ATR trailing methods Static, Dynamic and Ladder
  • Fix a bug that caused entry and exit trailing to not monotonically follow the trend when an external input indicator was triggered a signal second time before the strategy enters or exit the position.
เอกสารเผยแพร่:
  • Add the option to close at market price at the end of a session
  • Some code refactoring
เอกสารเผยแพร่: Feature:
  • New trailing Stop Loss, Entry and Exit method called Local Extrema. This technique allow the user to set his target price in the local maximum/minimum price plus/minus some ticks.
  • New Quantity method that is strictly based on equity percentage (rather than the capital at risk percentage).
เอกสารเผยแพร่:
  • New option for Initial Take Profit target price to set it to the Local Extrema (minimum/maximum) plus/minus some ticks.
  • New implementation of the session filter now it is more versatile and accurate.
เอกสารเผยแพร่: Make Session filter cyclical to capture overnight sessions.
เอกสารเผยแพร่:
  • The convention for overnight session day now is the end day in order to match the build-in session logic
เอกสารเผยแพร่:
  • Fix a bug that causing Risk-Reward Take profit Method (RR) to not work correctly when Stop Loss Method was set to Local max/min (LOC)
เอกสารเผยแพร่:
  • Add ADX trend filter option
  • Add the ability to close early if the first take profit target is not hit within some bars from the entry
  • Add up to 5 TP alert messages that can be used
  • Now the user can use up tp 20 different variables in the alert messages that are passed as input to the strategy. Strategy will replace their current value before trigger the alert. Some of the variables are the TP, the SL prices and the quantities of entries and exits of the positions.
  • Use time_filtes library and string_variables
เอกสารเผยแพร่:
  • Add {%{RISK}} {@{TICKER}} {@{BASE}} {@{QUOTE}} alert message variables
เอกสารเผยแพร่:
  • Make trailing entry to use stop order instead of market
  • Make trailing exit to use stop order instead of market
  • Fix a bug that caused the very first quantity calculation to be wrong when the trailing entry was enabled
  • Fix some typos in the alert messages
  • Some code refactoring and optimizations
เอกสารเผยแพร่:
  • New feature: Cooldown! Now you can wait after the completion for a couple of bars before enter the next trade!
  • Replace deprecated "when=" with if statements in strategy calls
  • Fix some rounding numerical inconsistencies for take profit quantities
เอกสารเผยแพร่:
  • Minor code clean up
เอกสารเผยแพร่:
  • Add support for new signal indicator convention (see for more)
  • Add ticker prefix and post fix variables for the alert messages
  • Rephrase the default alert messages to demonstrate more string variables
  • Use qty_percent after TV team fixed the API taking into account the initial position size
  • Change fastMA default color to yellow
  • Change trailing entry price default color to blue
เอกสารเผยแพร่:
  • Huge refactoring in the Stop Loss section! Now Stop Loss consists of two modes that can be set independently. The Move and the Trailing modes.
  • Added the ability to move the Stop Loss multiple times when a new Take Profit target is reached
  • Added the ability to change the trailing distance parameters in a step like manner every time a new Take Profit target is reached (a more generic version of old "Use Sec %/Mul" feature)
  • Now you can select on which Take Profit target you will start the Stop Loss trailing for the "TP" Trailing Activation Mode.
  • Increased the maximum number of lines and labels that can be drawn to 300 and 200 respectively
  • Added new string variables {${ENTRY}}, {${CLOSE+}}, {${CLOSE+}}, {${OPEN}}, {${HIGH}}, {${LOW}}
  • Other minor fixes and optimizations
เอกสารเผยแพร่:
  • New "update" alerts were introduced. Now user is able to get a message when Stop Loss value is change, the same is try for trailing entry and exit.
  • Changed the way take profit target prices are calculated when they are used with trailing entry. Now the basis of calculations is the entry price (white line) instead of the price when the open position signal was triggered.
  • Add the option to refer to other than the exchange timezone in the "Filter - Time" settings.
  • Fixed a precision bug that caused the sum of all TPs amounts that were reached to not add up to the total percentage.
เอกสารเผยแพร่:
  • Added {${ENTRY+}} {${ENTRY-}} {${EXIT+}} and {${EXIT-}} string variables that can be used with and without trailing for long and shorts.
  • Update time_filters library
  • Some minor performance optimizations
สคริปต์โอเพนซอร์ซ

ด้วยจิตวิญญาณของ TradingView อย่างแท้จริง ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้ผู้ค้าสามารถเข้าใจและตรวจสอบได้ ไชโยให้กับผู้เขียน! คุณสามารถใช้ได้ฟรี แต่การใช้รหัสนี้ซ้ำในสิ่งพิมพ์อยู่ภายใต้กฎของบ้าน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ เงื่อนไขการใช้บริการ

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?