编辑精选
OPEN-SOURCE SCRIPT

Recursive Auto-Pitchfork [Trendoscope]

已更新
"Say Hi" to object oriented programming with Pinescript using types and methods. This is the beginning of new era of Pinescript where we are moving from isolated scripts containing indicator and strategies to whole ecosystem of Object Oriented Programming with libraries of highly reusable components. Those who are familiar with programming would have already realised how big these improvements are and what it brings to the table.

With this script, I am not just providing an indicator for traders but also an introduction for programmers on how to design and build object oriented components in Pinescript using types and methods. Big thanks to Tradingview and Pine development team for making this happen. We look forward for many such gifts in the future :)

🎲 Architecture

As mentioned before, we are not just building an indicator here. But, an ecosystem of components. Using Types and Methods we can visualise libraries as Classes. Thus, we can build an ecosystem of libraries in layered approach to enhance effective code reusability.

Generic architecture can be visualised as below

https://www.tradingview.com/x/den84oaX/

Coming to the specific case of Auto Pitchfork indicator, the indicator code is less than 50 lines for logic and around 100 lines of inputs. But, most of the heavy-lifting is done by the libraries underneath. Here is a snapshot of related libraries and how they are connected.

https://www.tradingview.com/x/lmYZslzy/

All libraries are divided into two portions.
  • Types - Contains only type definitions
  • Methods - Contains only method definitions related to the types defined in the Types library


Together, these libraries can be visualised as Class. Methods are defined in such a way all exported methods are related to Types and no other functions or features are defined. If we need further functionality which does not depend on the types, we need to do this via some other library and use them here. Similarly, we should not define any methods related to these types in other libraries.

Reason for splitting the libraries to types and methods is to enable updating methods without disturbing types. Since libraries create interdependencies due to versioning, it is best if we do less updates on the type definitions. Splitting the two enables adding more features while keeping the type definition version intact.

🎲 Base Libraries
Base libraries are those which does not have any dependency. They form basic structures which are later used in other libraries. These libraries need to be crafted carefully so that minimal updates are done later on. Any updates on these libraries will impact all the dependent libraries and scripts.

🎯 Drawing
  • DrawingTypes - Defines basic drawing types Point, Line, Label, Box, Linefill and related property types.
  • DrawingMethods - All the methods or functionality surrounding Basic types are defined here.


🎲 Layer 1 Libraries
These are the libraries which has direct dependency on base libraries.
🎯 Zigzag
  • ZigzagTypes - Types required for defining Zigzag and Divergence
  • ZigzagMethods - Methods associated with Zigzag Type definitions.


🎯Pitchfork


🎲 Indicator and Settings
Indicator draws pitchfork based on recursive zigzag configurations. Recursive zigzag is derived with following logic:
  • Base level zigzag is calculated with regular zigzag algorithm with given length and depth
  • Next level zigzag is calculated based on base zigzag. And we recursively calculate higher level zigzags until we are left with 4 or less pivots or when no further reduction is possible


On every level of zigzag, we then check the last 3 pivots and draw pitchfork based on the retracement ratio.

Indicator settings are summarised in the tooltips and are as below.

https://www.tradingview.com/x/GYpDN9yV/

Finally, big thanks to my partner @CryptoArch_ for bringing up the topic of pitchfork for our next development.
版本注释
Name of the regular pitchfork changed from regular to Andrews to avoid confusion.
版本注释
Minor method reference updates
版本注释
Updated Libraries
版本注释
Update libraries and copyrights
版本注释
Update to V6 and libraries
Chart patternshewhomustnotbenamedtrendoscopezigzagecosystem

开源脚本

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

想在图表上使用此脚本?

免责声明