Với tinh thần của TradingView, tác giả đã xuất bản tập lệnh theo mã nguồn mở, vì thế trader có thể dễ dàng hiểu và tùy chỉnh được. Bạn có thể sử dụng miễn phí, hoặc tùy chỉnh lại mã đã được cấp phép bởi Quy tắc Chung. Bạn có thể sử dụng nó trên biểu đồ.
I applaud inclusion of the option to filter out buy signals with the configurable MA. Again, great work.
1) Studies - these are indicators of anything you want them to be.
2) Strategies - these are scripts that have buy/sell rules that you can use to backtest trading ideas. The strategies have built-in logic that gives you those "long" and "exit long" labels by default (just part of how Strategies work).
What I did was built a Study I can use for live trading based on the Strategy I made. Studies give you the ability to set alerts (can't do that with a Strategy) and you can make them look a bit cleaner, so I typically like to have Studies on my charts during day to day use and only use Strategies when backtesting something. So for the Study, I had to try to mimic the buy/sell rules that are just built into the Strategy by default. Looks like this is one area that my Study it didn't quite match up with the Strategy's logic.
So essentially I have two scripts that I published - one for use during live trading and that you can add alerts to if you want (the study) and one you can use to backtest and figure out what parameters you like (the strategy). But they are both essentially the same thing.
Add this under Inputs:
tradeType = input(defval="Using Stops", options = , title = "Execute Trades")
That puts a selector the user can select for whether you want to use stops to execute trades or wait for the candle to close.
Then change the entry/exit criteria from what was there to this:
strategy.entry("StopLong", strategy.long, stop = buyLevel2, when = time > Start and time < Finish and buyLevel2 > maFilterCheck and tradeType == "Using Stops")
strategy.exit("Exit StopLong", from_entry = "StopLong", stop=stopLevel2)
strategy.entry("CloseLong", strategy.long, when = close > buyLevel2 and time > Start and time < Finish and buyLevel2 > maFilterCheck and tradeType == "On Candle Close")
strategy.close("CloseLong", when = close < stopLevel2)
As an example of how horrible this is, on BTC 2-hr chart from 2019, using close values gives you a 134% return but using stops gets you a 525% return.
Just I'm thinking if there's a stock that I wanted to buy but already missed out the 1st Breakout buy.
The next breakout seems won't be triggered as it haven't complete a sell.
Any ways that I can code it as such every breakout I can get alerted?
Thanks in advance!
Actually, that reminds me...this strategy doesn't work well using alerts at all. Breakouts can happen rather violently and by the time you are alerted you've missed the ideal entry spot. The way I actually play this strategy is to use stop orders at these breakout levels and let them sit there. I then use a horizontal line with an alert attached to it that I drag around the screen based on where my stop is. When the alert goes off, I know my stop-buy order was hit, I then submit a stop-loss order, and move that line down to where my stop loss is. So the line is always where my orders are placed (since that is manually). If i notice my line isn't where a new swing high/swing low is according to the strategy, that lets me know to go into my brokerage or crypto account and update my stop levels, then I drag the line to my new stop levels. So my alerts are manual (by dragging an alert line around) but I know they are always in sync with the orders on any exchanges.