eugene71

Turtle System

eugene71 Cập nhật   
First pinescript strategy I've ever written so still learning what is possible.

This strategy is based on the famous turtle system and tried to stay true
to the rules within the confines of what pinescript will allow me to do.

Features:
Green lines represents the 20/55 day highs (configurable)
Red lines represent the 10/20 day lows (configurable)
Purple line represents stop (defaults to 2N away configurable)
Pyramids up to 5 long positions (each 1N away configurable).
Arrows:
Up Arrow Green - 20 day long position entered
Up Arrow Purple - 55 day long position entered
Down Arrow Green - Winning trade exited out.
Down Arrow Red - Losing Trade either stopped out or exited out.
Code tracks successful wins as it is only allowed to enter positions if the last trade was not a wining trade.
One limitation, only supports Long trades although wouldn't be a lot of work to also make it support Short. AAPL

Love to hear feedback on improvements, particularly to make it more robust.



Phát hành các Ghi chú:
Small change to update the way the labels present for each trade.
Phát hành các Ghi chú:
Removed some unnecessary code.
Phát hành các Ghi chú:
Documented the system and added comments to the logic.
Phát hành các Ghi chú:
Fixed one minor logic bug.
Phát hành các Ghi chú:
Updated the chart.
Phát hành các Ghi chú:
Fixed a couple more logic issues.
Phát hành các Ghi chú:
Fixed bug was adding 6 units max, should only add 5.
Phát hành các Ghi chú:
Rewrite to consolidate rules and improved the aesthetics to make it easier to visually see breakouts.
Phát hành các Ghi chú:
Breakouts now occur when the bar moves into the green. One of the rules of turtle system is to not take trades where the last trade was a winning trade, rather skip the next trade. Logic is implemented and you can visually see the trades skipped because the labels are greyed out (L1 labels). If the trade keeps going, it will take the L2 trade as according to the rules.
Phát hành các Ghi chú:
Fixed issue of code not adhering to the dates used.
Phát hành các Ghi chú:
More cleanup and now uses next day market order to close position rather that an exit order. exit orders were somewhat unpredictable in terms of when they were filled.
Phát hành các Ghi chú:
little more cleanup.
Phát hành các Ghi chú:
Fixed bug in calculating avg price.
Phát hành các Ghi chú:
1) Fixed bug not always taking L2 trades in strategy tester (visually could see them but strategy entry would not always take it)
2) Added lines to show next buy price as well as the stop price (these are the dashed lines).

Couple things to note about this script so far, which vary slightly from the original turtle rules.
a) All entries to positions are triggered if the close > L1 or L2, NOT the high. This has an interesting side effect. If high crosses over the L1 or L2, but doesn't close above it, this extreme point (high of day) must be crossed in subsequent days to generate a trade. Backtesting, I like this as it forces the trade to really stretch and be bullish, also helps reduce some of the noise in this day to day trading.
b) The actually buy in trading view occurs at the open the next day.
Phát hành các Ghi chú:
Fixed issue that L2 trades take precedence.
Phát hành các Ghi chú:
Minor changes.
Phát hành các Ghi chú:
Fixed issue where L2 trades where using L1 stop.
Phát hành các Ghi chú:
The latest version handles position sizing based on N. It computes position size as follows
# of shares=(risk/n), where risk=capital*riskPercent and n=ATR14.
Phát hành các Ghi chú:
Improvements to calculating position size.
Phát hành các Ghi chú:
Figured out a way to have pine script tell me capital left for determining position sizing.
Phát hành các Ghi chú:
Entry points are taken on close instead of next day's open. Strategy takes entry based on high/lows > L1 or L2 rather than close.
Phát hành các Ghi chú:
More updates. Added max units configuration. Cleaned up code a bit. Added alerts. Uses new functionality in strategy to determine cost basis, position sizing based on turtle rules, etc.
Phát hành các Ghi chú:
More improvements.
Phát hành các Ghi chú:
Updated version
Phát hành các Ghi chú:
Make ATR period configurable (defaults to 14)
Phát hành các Ghi chú:
Someone reported the last version had a bug and wouldn't load, so hopefully this fixes it.
Phát hành các Ghi chú:
Bug fix.
Phát hành các Ghi chú:
Fixed issue with position sizing. Fixed crash in 5 minute time frame. Fixed crash in some futures charts.
Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?