Machine Learning: Logistic Regression

Multi-timeframe Strategy based on Logistic Regression algorithm


This strategy uses a classic machine learning algorithm that came from statistics - Logistic Regression ( LR ).

The first and most important thing about logistic regression is that it is not a 'Regression' but a 'Classification' algorithm. The name itself is somewhat misleading. Regression gives a continuous numeric output but most of the time we need the output in classes (i.e. categorical, discrete). For example, we want to classify emails into “spam” or 'not spam', classify treatment into “success” or 'failure', classify statement into “right” or 'wrong', classify election data into 'fraudulent vote' or 'non-fraudulent vote', classify market move into 'long' or 'short' and so on. These are the examples of logistic regression having a binary output (also called dichotomous).

You can also think of logistic regression as a special case of linear regression when the outcome variable is categorical, where we are using log of odds as dependent variable. In simple words, it predicts the probability of occurrence of an event by fitting data to a logit function.

Basically, the theory behind Logistic Regression is very similar to the one from Linear Regression , where we seek to draw a best-fitting line over data points, but in Logistic Regression, we don’t directly fit a straight line to our data like in linear regression . Instead, we fit a S shaped curve, called Sigmoid, to our observations, that best SEPARATES data points. Technically speaking, the main goal of building the model is to find the parameters (weights) using gradient descent.

In this script the LR algorithm is retrained on each new bar trying to classify it into one of the two categories. This is done via the logistic_regression function by updating the weights w in the loop that continues for iterations number of times. In the end the weights are passed through the sigmoid function, yielding a prediction.

Mind that some assets require to modify the script's input parameters. For instance, when used with BTCUSD and USDJPY , the 'Normalization Lookback' parameter should be set down to 4 (2,...,5..), and optionally the 'Use Price Data for Signal Generation?' parameter should be checked. The defaults were tested with EURUSD .

Note: TradingViews's playback feature helps to see this strategy in action.
Warning: Signals ARE repainting.

Style tags: Trend Following, Trend Analysis
Asset class: Equities, Futures , ETFs, Currencies and Commodities
Dataset: FX Minutes/Hours/Days
Phát hành các Ghi chú: Minor fix.
Phát hành các Ghi chú: Price fix in the custom performance testing module.
Mã nguồn mở

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 đồ.

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

Bình luận

500 xu
+10 Phản hồi
Hi @capissimo,
This looks awesome. I'd put into my favorite, but only now been able to backtest a bit, and the result is very much promising. Thank you very much.
350 xu
+2 Phản hồi
I'm a bit new to trading view, but I have been observing your strategies. The kNN strategy works really too, I also back tested it !
I'm looking at automating this, but I don't understand what repainting means.
Could you please throw me some light on that ?

My idea of automating was - On the 1hr time frame chart , check a candle after it's been completed (when the next candle has just started). If there is a change in signal, take the trade accordingly.
Would this work ?
+8 Phản hồi
capissimo iambobo
@iambobo, if you check a candle after it's been completed, it'll work
Phản hồi
iambobo capissimo
@capissimo, Okay, thanks for the quick reply ! :)
Anything else I need to keep in mind while trying to automate ?
+1 Phản hồi
navyreal7 iambobo
@iambobo, repainting is the nastiest thing in the backtest ... these are false indicators on history, which in real trading have the worst indicators at times
+2 Phản hồi
iambobo navyreal7
@navyreal7, I get your point. In my back test, I have considered the close of the candles.
Phản hồi
This publication is now featured in our Editors' Picks: .
In the name of all TradingView traders, thank you for your valuable contribution to the TradingView community, and congrats!
+7 Phản hồi
capissimo PineCoders
@PineCoders, thx)
+1 Phản hồi
This is an amazing and concise example of logistic regression implemented in Pine.
You utter wizard.
+5 Phản hồi
Trang chủ Bộ lọc cổ phiếu Bộ lọc Forex Bộ lọc Tiền điện tử Lịch kinh tế Giới thiệu Tính năng Biểu đồ Trả phí Giới thiệu bạn Quy tắc Áp dụng Trung tâm Trợ giúp Giải pháp cho Website & Nhà môi giới Widget Giải pháp biểu đồ Thư viện Biểu đồ Lightweight Blog & Tin tức Twitter
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Giới thiệu bạn Xu Ticket Hỗ trợ của tôi Trung tâm Trợ giúp Tin nhắn riêng Trò chuyện Đăng xuất