Création / conversion code MA Bands

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #242423 quote
    Sofitech
    Participant
    Master

    Bonjour à tous, Nicolas, Ivan.
    J’ai essayé de faire une traduction de code mq4 vers probuilder en utilisant ChatGPT… ce n’est pas encore très opérationnel. J’aimerais convertir / créer le code PRT pour cet indicateur ci-dessous MA Bands…
    En attendant que l’IA le permette, j’en appelle donc au forum.
    —————————
    Avertissement
    —————————
    Le fichier ‘MQL4\Indicators\MA_BBands_V4.2.mq4’ existe déjà !
    Voulez-vous l’écraser ?
    —————————
    Oui Non
    —————————

    #242424 quote
    Sofitech
    Participant
    Master

    Le fichier du code mq4 est en pièce jointe

    #242530 quote
    Iván González
    Moderator
    Master
    // PRC_MA BBands
    // Version: 0
    // 13.01.2025
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    //----------------------------------------------------------------//
    // Configurable Parameters
    //----------------------------------------------------------------//
    MAPeriod = 20       // Moving Average period
    BBPeriod = 30       // Bollinger Bands period
    StdDev = 1.0        // Standard deviation for Bollinger Bands
    MoveShift = 22      // SMA shift
    OsMAFastPeriod = 5  // Fast EMA
    OsMASlowPeriod = 9  // Slow EMA
    OsMAPeriod = 4      // OsMA period
    shortMAPeriod = 5   // Short SMA period
    ShowSignals = 1     // Show signals
    //----------------------------------------------------------------//
    // Simple Moving Averages (SMA) Calculation
    //----------------------------------------------------------------//
    MAUp = average[MAPeriod](high)
    MAUpshift = MAUp[MoveShift]  // Value of the SMA high shifted by 22 periods
    
    MADn = average[MAPeriod](low)
    MADnshift = MADn[MoveShift]  // Value of the SMA low shifted by 22 periods
    //----------------------------------------------------------------//
    // Bollinger Bands Calculation with 7-Period Shift
    //----------------------------------------------------------------//
    bbUp = average[BBPeriod](high) + StdDev * std[BBPeriod](high)  // Upper band using highs
    bbDn = average[BBPeriod](low) - StdDev * std[BBPeriod](low)    // Lower band using lows
    bbUpShift = bbUp[7]  // Upper band shifted by 7 periods
    bbDnShift = bbDn[7]  // Lower band shifted by 7 periods
    //----------------------------------------------------------------//
    // OsMA Calculation
    //----------------------------------------------------------------//
    osmaNow = MACD[OsMAFastPeriod, OsMASlowPeriod, OsMAPeriod](close)  // Current OsMA value
    osmaPrev = osmaNow[1]  // Previous OsMA value
    //----------------------------------------------------------------//
    // Upper Band Calculation
    //----------------------------------------------------------------//
    IF MAUpshift > 0 THEN
    IF MAUpshift > bbUpShift THEN
    upperBand = MAUpshift  // Assign SMA to the buffer
    ELSE
    upperBand = bbUpShift  // Assign Bollinger upper band to the buffer
    ENDIF
    ELSE
    upperBand = bbUpShift
    ENDIF
    //----------------------------------------------------------------//
    // Lower Band Calculation
    //----------------------------------------------------------------//
    IF MADnshift > 0 THEN
    IF MADnshift < bbDnShift THEN
    lowerBand = MADnshift  // Assign SMA low to the buffer
    ELSE
    lowerBand = bbDnShift  // Assign Bollinger lower band to the buffer
    ENDIF
    ELSE
    lowerBand = bbDnShift
    ENDIF
    //----------------------------------------------------------------//
    // Midline
    //----------------------------------------------------------------//
    midLine = (upperBand + lowerBand) / 2
    //----------------------------------------------------------------//
    // Short SMA Calculation
    //----------------------------------------------------------------//
    smaHighShort = average[shortMAPeriod](high)[1]  // SMA of highs, shifted by one period
    smaLowShort = average[shortMAPeriod](low)[1]    // SMA of lows, shifted by one period
    //----------------------------------------------------------------//
    // Sell Signals (Red Arrow)
    //----------------------------------------------------------------//
    IF ShowSignals AND smaHighShort > upperBand[1] AND osmaNow < 0 AND osmaPrev > 0 AND high > upperBand THEN
    drawarrowdown(barindex, high + 20 * pointsize) coloured("red")   // Red arrow at the high price
    ENDIF
    //----------------------------------------------------------------//
    // Buy Signals (Green Arrow)
    //----------------------------------------------------------------//
    IF ShowSignals AND smaLowShort < lowerBand[1] AND osmaNow > 0 AND osmaPrev < 0 AND low < lowerBand THEN
    drawarrowup(barindex, low - 20 * pointsize) coloured("green")   // Green arrow at the low price
    ENDIF
    //----------------------------------------------------------------//
    RETURN upperBand coloured("darkblue") style(line, 2), lowerBand coloured("darkred") style(line, 2), midLine coloured("fuchsia") style(dottedline, 2)
    #242587 quote
    Sofitech
    Participant
    Master

    Merci IVan. Excellent travail. Je vois que le code est publié sur le site, si cela peut être utile à certains tant mieux.
    Bonne journée

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

Création / conversion code MA Bands


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
Sofitech @sofitech Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Sofitech
1 year ago.

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