LOGISTIC REGRESSION INDICATOR FOR PRT

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #224036 quote
    HugoBoss
    Participant
    New

    Hi all,

    I´m  trying to find a solution to migrate a logistic regression indicator from Tradingview , but not had much success  yet.

    I have the source code from Tradingview.

    It could be possible translate the pinescript code (applied on price)??

    I attach the source code.

    //@version=3
    // Logistic Regression
    study(“LogReg”, overlay=true)
    //
    // Functions
    //
    dot(v, w, p) => sum(v * w, p)
    sigmoid(z) => 1 / (1 + exp(-z))
    logistic_regression(X,Y,p,W,lr,steps)=>
        w = 0.0, loss = 0.0
        for i=0 to steps
            hypothesis = sigmoid(dot(X, W, p))  // prediction
            loss := -1 / p * (dot(dot(Y, log(hypothesis) + (1 – Y), p), log(1 – hypothesis), p))  // loss function, gradient, training
            gradient = 1 / p * (dot(X, hypothesis – Y, p))
            w := w – lr * gradient
        [loss, sigmoid(dot(X, w, p))]  // current loss & prediction
    scaleMinimax(X,p,min,max)=>
        hi = highest(X, p), lo = lowest(X, p)
        (max – min) * (X – lo)/(hi – lo) + min
    //
    // Inputs
    //
    X = input(close)
    p = input(3)
    //
    // Main
    //
    Y = log(abs(pow(X, 2) – 1) + .5)  // generate dataset
    W = 0.0
    [x,y]=logistic_regression(X,Y,p,W,0.001,100)
    x_scaled = scaleMinimax(x, 1000, lowest(X, 1000), highest(X, 1000))
    y_scaled = scaleMinimax(y, 1000, lowest(X, 1000), highest(X, 1000))
    plot(x_scaled, linewidth=3)
    plot(y_scaled, linewidth=3, color=lime)

    Thanks,

    Óscar

    #224038 quote
    HugoBoss
    Participant
    New
    #224042 quote
    JC_Bywan
    Moderator
    Master

    Hello,

    I add it to the waiting list of code translations, however given the code seems fairly short, hopefully one of the forum members fluent in both platforms languages is more than welcome to translate it first

    #224045 quote
    Bateson
    Participant
    New

    Cela ressemble à deux MM de régression linéaire de même période mais avec la première réglée sur les plus hauts et la deuxième alignée sur les plus bas…

    Visuellement, j’arrive au même indicateur en tout cas.

    As tu essayé sur PRT ?

    Edit: with google translate, into English (please use English in English forum as per forum rules in yellow box at bottom of the page just above “submit” button, thanks)

    This looks like two linear regression MAs of the same period but with the first set to the highs and the second aligned to the lows…

    Visually, I arrive at the same indicator in any case.

    Have you tried on PRT?

    #233866 quote
    Iván González
    Moderator
    Master

    Hi! I’m working on it.

    Right now it does work in few assets… I’m looking for a solution.

    Attached you will see the .itf and a EURUSD screenshot.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

LOGISTIC REGRESSION INDICATOR FOR PRT


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
HugoBoss @hugoboss Participant
Summary

This topic contains 4 replies,
has 4 voices, and was last updated by Iván González
1 year, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/21/2023
Status: Active
Attachments: 2 files
Logo Logo
Loading...