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)
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其他类型的意见或建议。请在使用条款阅读更多信息。

想在图表上使用此脚本?