Range Filter ProOrder : entrées non alignées au changement de couleur

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #240942 quote
    finplus
    Participant
    Master

    Bonsoir,

    le problème de mon programme rejoint ma demande dans le forum screener posté sur ce site. je voudrais entrer en position (long ou short) dès que le ruban (bleu ou rouge) change de couleur.

    Sauf que en faisant un back test, les entrés en position affichés ne correspondent pas aux changements de couleur.

    Merci pour votre aide.

     

    /// Définition des paramètres du code
    DEFPARAM CumulateOrders = False // Cumul des positions désactivé
    //////////////////////////////////////////////////////////////////// parameters KAMA

    //////////////////////////////////////////////////////////////////////////
    // Settings for 5min chart, BTCUSDC. For Other coin, change the parameters
    //////////////////////////////////////////////////////////////////////////

    // Source
    src = customclose

    // Sampling Period
    // Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
    per =100

    // Range Multiplier
    mult =3.0

    // Smooth Average Range
    wper = per*2 -1
    avrng = exponentialaverage[per](abs(src-src[1]))
    smrng = mult * exponentialaverage[wper](avrng)

    // Range Filter
    rngfilt = src
    If src > rngfilt[1] then
    If rngfilt[1] > src-smrng then
    rngfilt = rngfilt[1]
    Else
    rngfilt = src-smrng
    endif
    elsif rngfilt[1] < src+smrng then
    rngfilt = rngfilt[1]
    else
    rngfilt = src+smrng
    endif
    filt = rngfilt

    // Filter Direction
    upward = 0
    If filt > filt[1] then
    upward = upward[1]+1
    elsif filt < filt[1] then
    upward = 0
    else
    upward = upward[1]
    endif
    downward = 0
    If filt < filt[1] then
    downward = downward[1]+1
    elsif filt > filt[1] then
    downward = 0
    else
    downward = downward[1]
    endif

     

    //// Zone de couleurs : selon des conditions
    ////////////////////////////////////////////////////////////////////////////

    mbTendance = ( Average[3](filt) + filt)/2

    mbtendanceUP = mbTendance > mbTendance[1]
    mbTendanceDn = mbTendance < mbTendance[1]

     

     

     

    if not mbtendanceUp[1] and mbtendanceUp then
    buy 1 contract at market
    endif

    if not mbtendanceDn[1] and mbtendanceDn then
    sellshort 1 contract at market
    endif

    ///trailing stop function
    trailingstart = 5 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the “stoploss”

    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF

    //manage long positions
    IF LONGONMARKET THEN
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF

    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF

    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF

    // points based STOP LOSS and TRAILING STOP
    // initial STOP LOSS
    SET STOP pLOSS 50

    // trailing stop
    SET STOP pTRAILING 50

    Capture-decran-2024-11-30-a-16.50.14.jpg Capture-decran-2024-11-30-a-16.50.14.jpg
    #241311 quote
    Iván González
    Moderator
    Master

    Bonnes! il a récupéré le code préparé dans le message que vous avez mentionné.

    // Original Script > @DonovanWall
    // Adapted Version > @guikroth
    DEFPARAM CumulateOrders = False // Cumul des positions désactivé
    //////////////////////////////////////////////////////////////////////////
    // Settings for 5min chart, BTCUSDC. For Other coin, change the parameters
    //////////////////////////////////////////////////////////////////////////
    
    // Color variables
    
    downColorR = 255
    downColorG = 69
    downColorB = 0
    
    upColorR = 50
    upColorG = 205
    upColorB = 50
    
    midColorR = 0
    midColorG = 191
    midColorB = 255
    
    // Source
    src = customclose
    
    // Sampling Period
    // Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
    per = 100//defval=100, minval=1, "Sampling Period"
    
    // Range Multiplier
    mult = 3//defval=3.0, minval=0.1, "Range Multiplier"
    
    // Smooth Average Range
    wper = per*2 -1
    avrng = exponentialaverage[per](abs(src-src[1]))
    smrng = mult * exponentialaverage[wper](avrng)
    
    // Range Filter
    rngfilt = src
    If src > rngfilt[1] then
    If rngfilt[1] > src-smrng then
    rngfilt = rngfilt[1]
    Else
    rngfilt = src-smrng
    endif
    elsif rngfilt[1] < src+smrng then
    rngfilt = rngfilt[1]
    else
    rngfilt = src+smrng
    endif
    filt = rngfilt
    
    // Filter Direction
    upward = 0
    If filt > filt[1] then
    upward = upward[1]+1
    elsif filt < filt[1] then
    upward = 0
    else
    upward = upward[1]
    endif
    downward = 0
    If filt < filt[1] then
    downward = downward[1]+1
    elsif filt > filt[1] then
    downward = 0
    else
    downward = downward[1]
    endif
    
    // Target Bands
    hband = filt + smrng
    lband = filt - smrng
    
    // Colors
    If upward > 0 then
    filtcolorR = upColorR
    filtcolorG = upColorG
    filtcolorB = upColorB
    elsif downward > 0 then
    filtcolorR = downColorR
    filtcolorG = downColorG
    filtcolorB = downColorB
    else
    filtcolorR = midColorR
    filtcolorG = midColorG
    filtcolorB = midColorB
    endif
    
    if src > filt and src > src[1] and upward > 0 then
    barcolorR = upColorR
    barcolorG = upColorG
    barcolorB = upColorB
    elsif src > filt and src < src[1] and upward > 0 then
    barcolorR = upColorR
    barcolorG = upColorG
    barcolorB = upColorB
    elsif src < filt and src < src[1] and downward > 0 then
    barcolorR = downColorR
    barcolorG = downColorG
    barcolorB = downColorB
    elsif src < filt and src > src[1] and downward > 0 then
    barcolorR = downColorR
    barcolorG = downColorG
    barcolorB = downColorB
    else
    barcolorR = midColorR
    barcolorG = midColorG
    barcolorB = midColorB
    endif
    
    // Break Outs
    longCond = (src > filt and src > src[1] and upward > 0) or (src > filt and src < src[1] and upward > 0)
    shortCond = (src < filt and src < src[1] and downward > 0) or (src < filt and src > src[1] and downward > 0)
    
    CondIni = 0
    If longCond then
    CondIni = 1
    elsif shortCond then
    CondIni = -1
    else
    CondIni = CondIni[1]
    endif
    
    longCondition = longCond and CondIni[1] = -1
    shortCondition = shortCond and CondIni[1] = 1
    
    //Alerts
    If longCondition then
    buy 1 contract at market
    endif
    If shortCondition then
    sellshort 1 contract at market
    endif
    
    ///trailing stop function
    trailingstart = 5 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the "stoploss"
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    // points based STOP LOSS and TRAILING STOP
    // initial STOP LOSS
    SET STOP pLOSS 50
    
    // trailing stop
    SET STOP pTRAILING 50
    
    //-----------------------------------------//
    graphonprice filt coloured(barcolorR,barcolorG,barcolorB,255)
    graphonprice hband coloured(upColorR,upColorG,upColorB,100)
    graphonprice lband coloured(downColorR,downColorG,downColorB,100)
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Range Filter ProOrder : entrées non alignées au changement de couleur


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
finplus @finplus Participant
Summary

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

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 11/30/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...