Demande de conversion système MAMA Amibroker

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #84687 quote
    carlvan
    Participant
    Average

    Bonjour, et merci d’avance pour toute aide! Le but ici est de convertir
    1: la formule AFL (Amibroker) de l’indicateur MAMA/FAMA, qui est plus réactive, mais très proche, de la version ProRealCode
    2: les signaux d’achats compris dans la formule, qui génèrent les flèches achat-vente sur le graphique
    Demande additionnelle: j’aimerais automatiser le système pour du trading automatique, ce serait formidable d’avoir ça en plus
    Note: le système est “stop and reverse”, ce qui signifie tout le temps dans le marché: un signal “sell” signifie une sortie de la position longue et une entrée short.
    Voici la formule AFL:

    _SECTION_BEGIN("MAMA");
    SetPositionSize(500, spsShares);
    
    prc = ( High + Low ) / 2;
    fastlimit = 0.5;
    slowlimit = 0.05;
    pi=4*atan(1);
    RTD=180/pi;
    DTR=pi/180;
    
    Cyclepart=Param("Alpha",0.5,0.1,1,0.1);
    
    Smooth[0] = Period = Detrender[0] = I1[0] = Q1[0] = 0;
    phase[0]=deltaphase[0]=MAMA[0]=FAMA[0]=0;
    for ( i = 6; i < BarCount; i++ )
    {
    Smooth[i] = ( 4 * prc[i] + 3 * prc[i-1] + 2 * prc[i-2] + prc[i-3] ) / 10;
    AmpCorr[i] = 0.075 * Period[i-1] + 0.54;
    Detrender[i] = ( 0.0962 * Smooth[i] + 0.5769 * Smooth[i-2] - 0.5769 * Smooth[i-4] - 0.0962 * Smooth[i-6] ) * AmpCorr[i];
    Q1[i] = ( 0.0962 * Detrender[i] + 0.5769 * Detrender[i-2] - 0.5769 * Detrender[i-4] - 0.0962 * Detrender[i-6] ) * AmpCorr[i];
    I1[i] = Detrender[i-3];
    if (I1[i] != 0) phase[i] = DTR*360/atan(q1[i]/I1[i]);
    deltaphase[i]=phase[i-1]-phase[i];
    if (deltaphase[i] <1) deltaphase[i]=1;
    alpha[i]=fastlimit[i]/deltaphase[i];
    if (alpha[i] < slowlimit[i]) alpha[i]=slowlimit[i]; MAMA[i]=alpha[i] * prc [i] +(1-alpha[i])*MAMA[i-1]; FAMA[i]=Cyclepart*alpha[i] * prc [i] +(1-Cyclepart*alpha[i])*FAMA[i-1]; } Plot( MAMA, "MAMA", colorTurquoise, styleLine|styleThick ); Plot( FAMA, "FAMA", colorYellow, styleLine|styleThick ); PlotOHLC(O,H,L,C,"MAMA",IIf(MAma>fama,colorblue,colorRed),styleBar|styleThick,0,0,0,0,2);
    _SECTION_END();
    
    _SECTION_BEGIN("SYSTEM");
    BuySetupValue=ValueWhen(Cross(MAMA,FAMA),H,1);
    SellsetupValue=ValueWhen(Cross(FAMA,MAMA),L,1);
    Buysetup =Cross(MAMA,FAMA) ;
    Sellsetup = Cross(FAMA,MAMA);
    Longa = Flip(Buysetup,Sellsetup);
    shrta = Flip(Sellsetup,Buysetup);
    Buy=Longa AND Cross(C,BuySetupValue);
    Sell=shrta AND Cross(SellsetupValue,C);
    Buy = ExRem(Buy,Sell);
    Sell = ExRem(Sell,Buy);
    Short=Sell;
    Cover=Buy;
    t1= Flip(Buy,Sell);
    t2= Flip(Sell,Buy);
    BPrice=ValueWhen(t1 AND Ref(t1,-1)==0,C,1);
    SPrice=ValueWhen(t2 AND Ref(t2,-1)==0,C,1);
    GraphXSpace = 5;
    dist = 1.5*ATR(20);
    for( i = 0; i < BarCount; i++ )
    {
    if( Buy[i] ) PlotText( "" + C[ i ], i, L[ i ]-dist[i], colorLime );
    if( Sell[i] ) PlotText( "" + C[ i ], i, H[ i ]+dist[i], colorYellow );
    }
    _SECTION_END();
    
    AlertIf(Buy,"SOUND H:\\Users\\Carl\\Documents\\Enregistrements audio\\Buy NQ.m4a","BUY NQ",1 );
    AlertIf(Sell,"SOUND H:\\Users\\Carl\\Documents\\Enregistrements audio\\Sell NQ.m4a","SELL NQ",2 );
    
    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
    PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
    PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
    PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
    PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
    _SECTION_END();

     

    Merci encore pour toute aide,

    Carl V.

    MAMAFAMA.jpg MAMAFAMA.jpg
    #84697 quote
    Nicolas
    Keymaster
    Master

    Voilà déjà l’indicateur des 2 moyennes mobiles, y compris coloration des chandeliers telle que dans le code Amibroker:

    Period=20
    
    prc = ( High + Low ) / 2
    fastlimit = 0.5
    slowlimit = 0.05
    pi=4*atan(1)
    //RTD=180/pi
    DTR=pi/180
     
    Cyclepart=0.1
    
    if barindex>6 then 
    Smooth = ( 4 * prc + 3 * prc[1] + 2 * prc[2] + prc[3] ) / 10
    AmpCorr = 0.075 * Period[1] + 0.54
    Detrender = ( 0.0962 * Smooth + 0.5769 * Smooth[2] - 0.5769 * Smooth[4] - 0.0962 * Smooth[6] ) * AmpCorr
    Q1 = ( 0.0962 * Detrender + 0.5769 * Detrender[2] - 0.5769 * Detrender[4] - 0.0962 * Detrender[6] ) * AmpCorr
    I1 = Detrender[3]
    if (I1 <> 0) then 
    phase = DTR*360/atan(q1/I1)
    endif
    deltaphase=phase[1]-phase
    if (deltaphase <1) then 
    deltaphase=1
    endif
    alpha=fastlimit/deltaphase
    if (alpha < slowlimit) then 
    alpha=slowlimit 
    endif
    MAMA=alpha * prc  +(1-alpha)*MAMA[1] 
    FAMA=Cyclepart*alpha * prc  +(1-Cyclepart*alpha)*FAMA[1] 
    endif
    
    if MAMA>FAMA then 
    r=0
    g=0
    b=255
    else
    r=255
    g=0
    b=0
    endif
    drawcandle(open,high,low,close) coloured(r,g,b)
    
    return MAMA coloured(0,245,255) as "MAMA", FAMA coloured(255,255,0) as "FAMA"
    carlvan thanked this post
    MAMA-FAMA-PROREALTIME.png MAMA-FAMA-PROREALTIME.png
    #84707 quote
    carlvan
    Participant
    Average

    Merci beaucoup, cet indicateur est excellent et je suis heureux de pouvoir maintenant l’utiliser sur PRT.

    J’espère que vous aurez le temps de convertir aussi les signaux d’achat/vente, ce serait super!

    #84711 quote
    carlvan
    Participant
    Average

    Cher Nicolas, ce qui est curieux c’est que lorsque je mets côte à côte les 2 graphes (amibroker et PRT, avec votre code)  avec Nasdaq 2′, les courbes MAMA sont similaires, mais pas du tout la FAMA, qui ne colle pas au MAMA contrairement à la version Amibroker (voir graphe). Pourtant, j’ai relu votre code et il semble effectivement parfaitement calqué sur l’AFL. Bizarre.

    prt_amb.jpg prt_amb.jpg
    #84741 quote
    Nicolas
    Keymaster
    Master

    Il faut modifier le paramètre “cyclepart” de mémoire. Je ne sais pas à combien il est réglé sur ton screenshot.

    Je m’occupe de la stratégie dès que possible.

    #84757 quote
    carlvan
    Participant
    Average

    Exact, j’avais oublié ce paramètre important: maintenant les courbes sont identiques sur le graphique – merci!

    #84910 quote
    carlvan
    Participant
    Average

    Cher Nicolas, as-tu réussi à convertir les signaux achat/vente pour le MAMA/FAMA indicator? Entre temps, j’ai découvert ton code pour ALMA hi-lo: excellent pour l’intraday, très réactif. Merci de partager ce travail intensif et créatif.

    #84914 quote
    Nicolas
    Keymaster
    Master

    et voilà ! ci-dessous le code de la stratégie, achat/vente selon les croisements de ces 2 moyennes mobiles :

    defparam cumulateorders=false
    
    Period=20
    
    prc = ( High + Low ) / 2
    fastlimit = 0.5
    slowlimit = 0.05
    pi=4*atan(1)
    //RTD=180/pi
    DTR=pi/180
     
    Cyclepart=0.1
    
    if barindex>6 then
    Smooth = ( 4 * prc + 3 * prc[1] + 2 * prc[2] + prc[3] ) / 10
    AmpCorr = 0.075 * Period[1] + 0.54
    Detrender = ( 0.0962 * Smooth + 0.5769 * Smooth[2] - 0.5769 * Smooth[4] - 0.0962 * Smooth[6] ) * AmpCorr
    Q1 = ( 0.0962 * Detrender + 0.5769 * Detrender[2] - 0.5769 * Detrender[4] - 0.0962 * Detrender[6] ) * AmpCorr
    I1 = Detrender[3]
    if (I1 <> 0) then
    phase = DTR*360/atan(q1/I1)
    endif
    deltaphase=phase[1]-phase
    if (deltaphase <1) then
    deltaphase=1
    endif
    alpha=fastlimit/deltaphase
    if (alpha < slowlimit) then
    alpha=slowlimit
    endif
    MAMA=alpha * prc  +(1-alpha)*MAMA[1]
    FAMA=Cyclepart*alpha * prc  +(1-Cyclepart*alpha)*FAMA[1]
    endif
    
    if not longonmarket and MAMA crosses over FAMA then 
    buy at market 
    endif 
    if not shortonmarket and MAMA crosses under FAMA then
    sellshort at market 
    endif

    il n’y pas de stoploss / takeprofit.

    #84915 quote
    carlvan
    Participant
    Average

    Merci infiniment, Nicolas!

    #84927 quote
    carlvan
    Participant
    Average

    Bonjour à nouveau nicolas. Je me permets de revenir vers toi concernant le code car il y a encore une petite différence avec le code original AFL: dans ce code, il faut effectivement que MAMA crosses over FAMA, ET qu’il y ait ensuite un close > que le high de cette bar “MAMA cross FAMA”.

    En fait, la bar “MAMA cross FAMA” est la bar de setup et il faut ensuite qu’elle soit cassée en clôture. Je ne maîtrise pas assez (c’est peu dire!) le language Prorealcode que pour ajouter cette condition. Merci pour toute aide complémentaire.

    #84935 quote
    Nicolas
    Keymaster
    Master

    On peut essayer comme ceci:

    if not longonmarket and MAMA[1] crosses over FAMA[1] and Close>High[1] then 
    buy at market 
    endif 
    if not shortonmarket and MAMA[1] crosses under FAMA[1] and close<Low[1] then
    sellshort at market 
    endif
    #84936 quote
    carlvan
    Participant
    Average

    Makes sense, et ok si close dépasse high[1] juste après MAMA cross FAMA. Merci encore Nicolas.

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

Demande de conversion système MAMA Amibroker


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
carlvan @carlvan Participant
Summary

This topic contains 11 replies,
has 2 voices, and was last updated by carlvan
7 years, 3 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 11/12/2018
Status: Active
Attachments: 3 files
Logo Logo
Loading...