INDICATOR COGSTOCH OSCILLATOR

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #244514 quote
    ARLEQUIN49
    Participant
    Veteran

    Bonjour Ivan,
    Celui que tu as retranscrit ne correspond pas ou est différent de celui de Métatrader. Il n’agit pas en centre de gravité. Il doit y avoir une petite modification nécessaire.
    Je te joins un autre en stochastique avec le code et l’illustration

    //| COGSTOCH.mq4 |
    //| Original Code from NG3110@latchess.com |
    //| Linuxser 2007 for TSD http://www.forex-tsd.com/ |
    //| Stoch Modified Brooky http://www.brooky-indicators.com |
    //+——————————————————————+
    #property copyright “ANG3110@latchess.com”
    //———ang_pr (Din)——————–
    #property indicator_separate_window
    #property indicator_buffers 7
    #property indicator_color1 Gray
    #property indicator_color2 IndianRed
    #property indicator_color3 CadetBlue
    #property indicator_color4 Pink
    #property indicator_color5 PowderBlue
    #property indicator_color6 Blue
    #property indicator_color7 Red

    #property indicator_level1 80
    #property indicator_level2 50
    #property indicator_level3 20
    #property indicator_level4 100
    #property indicator_level5 00

    #property indicator_style1 1
    #property indicator_style7 2

    #property indicator_width2 2
    #property indicator_width3 2

    //———————————–
    extern int bars_back = 192;
    extern int stoch_k = 14;
    extern int stoch_d = 5;
    extern int stoch_s = 3;

    extern int m = 5;
    extern int i = 1;
    extern double kstd = 1.618;
    extern double kstd.internal = 0.8;
    extern int sName = 2;
    //———————–
    double fx[], sqh[], sql[], stdh[], stdl[], stochdata[], stochsdata[];
    double ai[10,10], b[10], x[10], sx[20];
    double sum;
    int ip, p, n, f;
    double qq, mm, tt;
    int ii, jj, kk, ll, nn;
    double sq, std;
    //*******************************************
    int init()
    {
    IndicatorShortName(“COGSTOCH: Mod by Brooky-Indicators.com”);

    SetIndexBuffer(0, fx);SetIndexStyle(0, DRAW_LINE);
    SetIndexBuffer(1, sqh);
    SetIndexBuffer(2, sql);
    SetIndexBuffer(3, stdh);
    SetIndexBuffer(4, stdl);
    SetIndexBuffer(5, stochdata);SetIndexStyle(5, DRAW_LINE);
    SetIndexBuffer(6, stochsdata);SetIndexStyle(6, DRAW_LINE);
    p = MathRound(bars_back);

    nn = m + 1;
    ObjectCreate(“sstart” + sName, 22, 0, Time[p], fx[p]);
    ObjectSet(“sstart” + sName, 14, 159);
    return(0);
    }
    //———————————————————-
    int deinit()
    {
    ObjectDelete(“sstart” + sName);
    }
    //**********************************************************************************************
    int start()
    {
    int mi;
    //——————————————————————————————-
    ip = iBarShift(Symbol(), Period(), ObjectGet(“sstart” + sName, OBJPROP_TIME1));
    p = bars_back;
    sx[1] = p + 1;
    SetIndexDrawBegin(0, Bars – p – 1);
    SetIndexDrawBegin(1, Bars – p – 1);
    SetIndexDrawBegin(2, Bars – p – 1);
    SetIndexDrawBegin(3, Bars – p – 1);
    SetIndexDrawBegin(4, Bars – p – 1);
    //———————-sx——————————————————————-

    int rlimit;
    int rcounted_bars=IndicatorCounted();
    //—- check for possible errors
    if(rcounted_bars<0) return(-1);
    //—- the last counted bar will be recounted
    if(rcounted_bars>0) rcounted_bars–;
    rlimit=Bars-rcounted_bars;
    //—- main loop
    for(int ri=0; ri<rlimit; ri++)
    {

    stochdata[ri]= iStochastic(NULL,0,stoch_k,stoch_d,stoch_s,MODE_SMA,0,MODE_MAIN,ri);
    stochsdata[ri]= iStochastic(NULL,0,stoch_k,stoch_d,stoch_s,MODE_SMA,0,MODE_SIGNAL,ri);
    }

    for(mi = 1; mi <= nn * 2 – 2; mi++)
    {
    sum = 0;
    for(n = i; n <= i + p; n++)
    {
    sum += MathPow(n, mi);
    }
    sx[mi + 1] = sum;
    }
    //———————-syx———–
    for(mi = 1; mi <= nn; mi++)
    {

    sum = 0.00000;
    for(n = i; n <= i + p; n++)
    {
    if(mi == 1)
    sum += iStochastic(NULL,0,stoch_k,stoch_d,stoch_s,MODE_SMA,0,MODE_MAIN,n);//rsi_period iRSI(NULL,0,rsi_period,prICE_CLOSE,n)
    else
    sum += iStochastic(NULL,0,stoch_k,stoch_d,stoch_s,MODE_SMA,0,MODE_MAIN,n) * MathPow(n, mi – 1);
    }
    b[mi] = sum;
    }
    //===============Matrix=======================================================================================================
    for(jj = 1; jj <= nn; jj++)
    {
    for(ii = 1; ii <= nn; ii++)
    {
    kk = ii + jj – 1;
    ai[ii, jj] = sx[kk];
    }
    }
    //===============Gauss========================================================================================================
    for(kk = 1; kk <= nn – 1; kk++)
    {
    ll = 0; mm = 0;
    for(ii = kk; ii <= nn; ii++)
    {
    if(MathAbs(ai[ii, kk]) > mm)
    {
    mm = MathAbs(ai[ii, kk]);
    ll = ii;
    }
    }
    if(ll == 0)
    return(0);

    if(ll != kk)
    {
    for(jj = 1; jj <= nn; jj++)
    {
    tt = ai[kk, jj];
    ai[kk, jj] = ai[ll, jj];
    ai[ll, jj] = tt;
    }
    tt = b[kk]; b[kk] = b[ll]; b[ll] = tt;
    }
    for(ii = kk + 1; ii <= nn; ii++)
    {
    qq = ai[ii, kk] / ai[kk, kk];
    for(jj = 1; jj <= nn; jj++)
    {
    if(jj == kk)
    ai[ii, jj] = 0;
    else
    ai[ii, jj] = ai[ii, jj] – qq * ai[kk, jj];
    }
    b[ii] = b[ii] – qq * b[kk];
    }
    }
    x[nn] = b[nn] / ai[nn, nn];
    for(ii = nn – 1; ii >= 1; ii–)
    {
    tt = 0;
    for(jj = 1; jj <= nn – ii; jj++)
    {
    tt = tt + ai[ii, ii + jj] * x[ii + jj];
    x[ii] = (1 / ai[ii, ii]) * (b[ii] – tt);
    }
    }
    //===========================================================================================================================
    for(n = i; n <= i + p; n++)
    {
    sum = 0;
    for(kk = 1; kk <= m; kk++)
    {
    sum += x[kk + 1] * MathPow(n, kk);
    }
    fx[n] = x[1] + sum;
    }
    //———————————–Std———————————————————————————–
    sq = 0.0;
    for(n = i; n <= i + p; n++)
    {
    sq += MathPow(iStochastic(NULL,0,stoch_k,stoch_d,stoch_s,MODE_SMA,0,MODE_MAIN,n) – fx[n], 2);
    }
    sq = MathSqrt(sq / (p + 1)) * kstd;
    std = iStdDevOnArray(stochdata,0,p,0,MODE_SMA,i) *kstd.internal;
    for(n = i; n <= i + p; n++)
    {
    sqh[n] = fx[n] + sq;
    sql[n] = fx[n] – sq;
    stdh[n] = fx[n] + std;
    stdl[n] = fx[n] – std;
    }
    //——————————————————————————-
    ObjectMove(“sstart” + sName, 0, Time[p], fx[p]);
    //—————————————————————————————————————————-
    return(0);

    #245096 quote
    Iván González
    Moderator
    Master

    Bonjour. Je n'arrive pas à obtenir des résultats corrects. Je vais laisser le code ici pour vous. Je n'ai pas beaucoup de connaissances sur MetaTrader, donc je ne peux pas vous aider beaucoup plus.

    //----------------------------------------------------------------//
    // PRC COGSTOCH
    //version = 0
    //03.03.2025
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //----------------------------------------------------------------//
    //-----INPUT PARAMETERS-------------------------------------------//
    barsback = 192  // Lookback period
    stochk = 14     // Stochastic K period
    stochd = 5      // Stochastic D period
    stochs = 3      // Stochastic smoothing period
    
    m = 5
    kstd = 1.618
    kstdinternal = 0.8
    //----------------------------------------------------------------//
    
    //-----STOCHASTIC CALCULATION--------------------------------------//
    // Compute Stochastic Indicator
    stochasticMain = Stochastic[stochk, stochd](close)
    stochasticSignal = Stochasticd[stochk,stochd,stochs](close)
    
    // Center of Gravity using Polynomial Regression
    p = barsback
    nn = m + 1
    
    // Compute SX array (sum of powers of n)
    for mi = 1 to nn * 2 - 2 do
    sum = 0
    for n = 0 to p do
    sum = sum + pow(n, mi)
    next
    $sx[mi + 1] = sum
    next
    //----------------------------------------------------------------//
    
    // Compute the B array using Stochastic values
    for mi = 1 to nn do
    sum = 0
    for n = 0 to p do
    if mi = 1 then
    sum = sum + stochasticMain[n]
    else
    sum = sum + stochasticMain[n] * pow(n, mi - 1)
    endif
    next
    $b[mi] = sum
    next
    //----------------------------------------------------------------//
    
    // Construct AI matrix from SX values
    for jj = 1 to nn do
    for ii = 1 to nn do
    kk = ii + jj - 1
    $ai[(ii - 1) * nn + jj] = $sx[kk]
    next
    next
    //----------------------------------------------------------------//
    
    // Apply Gaussian Elimination to solve the system
    for kk = 1 to nn - 1 do
    ll = 0
    mm = 0
    qq = 0
    tt = 0
    for ii = kk to nn do
    if abs($ai[(ii - 1) * nn + kk]) > mm then
    mm = abs($ai[(ii - 1) * nn + kk])
    ll = ii
    endif
    next
    if ll <> kk then
    for jj = 1 to nn do
    tt = $ai[(kk - 1) * nn + jj]
    $ai[(kk - 1) * nn + jj] = $ai[(ll - 1) * nn + jj]
    $ai[(ll - 1) * nn + jj] = tt
    next
    tt = $b[kk]
    $b[kk] = $b[ll]
    $b[ll] = tt
    endif
    for ii = kk + 1 to nn do
    qq = $ai[(ii - 1) * nn + kk] / $ai[(kk - 1) * nn + kk]
    for jj = 1 to nn do
    if jj = kk then
    $ai[(ii - 1) * nn + jj] = 0
    else
    $ai[(ii - 1) * nn + jj] = $ai[(ii - 1) * nn + jj] - qq * $ai[(kk - 1) * nn + jj]
    endif
    next
    $b[ii] = $b[ii] - qq * $b[kk]
    next
    next
    //----------------------------------------------------------------//
    
    // Compute polynomial regression coefficients
    $x[nn] = $b[nn] / $ai[(nn - 1) * nn + nn]
    
    for ii = nn - 1 downto 1 do
    tt = 0
    for jj = 1 to nn - ii do
    tt = tt + $ai[(ii - 1) * nn + (ii + jj)] * $x[ii + jj]
    next
    $x[ii] = (1 / $ai[(ii - 1) * nn + ii]) * ($b[ii] - tt)
    next
    //----------------------------------------------------------------//
    
    // Calculate Center of Gravity (COG) and standard deviation bands
    sq = 0.0
    
    for n = 0 to p do
    sum = 0
    for kk = 1 to m do
    sum = sum + $x[kk + 1] * pow(n, kk)
    next
    
    // Center of Gravity calculation
    $fx[n] = $x[1] + sum
    
    // Compute standard deviation
    sq = sq + pow(stochasticMain[n] - $fx[n], 2)
    
    // Compute standard deviation bands
    st = sqrt(sq / (p + 1)) * kstd
    stinternal = sqrt(sq / (p + 1)) * kstdinternal
    
    // Compute upper & lower bands
    $sqh[n] = $fx[n] + st
    $sql[n] = $fx[n] - st
    $stdh[n] = $fx[n] + stinternal
    $stdl[n] = $fx[n] - stinternal
    next
    //----------------------------------------------------------------//
    
    // RETURN OUTPUTS
    return $fx[p] as "Center of Gravity" coloured("blue") style(line,2),$sqh[p] as "Upper Band" coloured("red") style(line,2),$sql[p] as "Lower Band" coloured("green") style(line,2),$stdh[p] as "Upper Internal Band" coloured("pink") style(dottedline,1),$stdl[p] as "Lower Internal Band" coloured("pink") style(dottedline,1),stochasticMain as "Stochastic Main" coloured("gray") style(line,1),stochasticSignal as "Stochastic Signal" coloured("cadetblue") style(line,1)
    
    #245120 quote
    ARLEQUIN49
    Participant
    Veteran

    Bonjour, Ivan,

    Un grand merci, cela me paraît plus vrai que celui de Métatrader

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

INDICATOR COGSTOCH OSCILLATOR


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
ARLEQUIN49 @arlequin49 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by ARLEQUIN49
10 months, 2 weeks ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 03/01/2025
Status: Active
Attachments: 1 files
Logo Logo
Loading...