Problème de code de Martingale

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8243 quote
    DoctradingDoctrading
    Participant
    Master

    Bonjour,

    J’essaie de tester un code de martingale classique (doublement des lots à chaque perte).
    Avec une mise constante (n = 1), le code fonctionne (même si la stratégie est mauvaise, c’est juste un test).

    Mais mon code de martingale ne fonctionne pas, après seulement 18 trades (dont certains gagnants) il m’envoie rapidement plus de 4000 lots !

    Où y voyez-vous une erreur ?
    Merci par avance.

     

    // CODE HARAMI MARTINGALE
    
    Defparam cumulateorders = false
    
    // MARGTINGALE
    Once n = 1
    
    IF PositionPerf(1) <0 THEN
    n = n*2
    ELSIF PositionPerf(1)>=0THEN
    n =1
    ENDIF
    
    
    // Déinition du HARAMI (ou INSIDE BAR)
    c1= high[0] < high[1]
    c2= low[0] > low[1]
    harami = c1 and c2
    
    IF harami THEN
    buy n shares at high stop
    sellshort n shares at low stop
    amplitude = high - low
    ENDIF
    
    
    set stop loss amplitude
    set target profit amplitude
    
    #8244 quote
    NicolasNicolas
    Keymaster
    Legend

    Parce que tu refais le calcul à chaque bar et non pas au moment ou tu dois passer l’ordre, ta variable n s’incrémente sans cesse si le dernier trade était perdant.

    Voici la correction:

    
    Defparam cumulateorders = false
    
    // MARGTINGALE
    Once n = 1
    
    // Déinition du HARAMI (ou INSIDE BAR)
    c1= high[0] < high[1]
    c2= low[0] > low[1]
    harami = c1 and c2
    
    IF harami THEN
    IF PositionPerf(1) <0 THEN
    n = n*2
    ELSIF PositionPerf(1)>=0THEN
    n =1
    ENDIF
    buy n shares at high stop
    sellshort n shares at low stop
    amplitude = high - low
    ENDIF
    
    set stop loss amplitude
    set target profit amplitude
    
    GRAPH n

    Attention ça pique.

    martingale.png martingale.png
    #8255 quote
    DoctradingDoctrading
    Participant
    Master

    Grand merci à toi.
    Effectivement c’est jouer avec le feu, mais c’est bien rigolo.

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Problème de code de Martingale


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
Doctrading @doctrading Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by DoctradingDoctrading
10 years, 5 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 05/27/2016
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...