compteur sur 3 positions distinctes

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #75045 quote
    Greguigreg
    Participant
    Junior

    Bonjour a tous

    j’essaie de coder une strategie qui short 1 contrat sur chacun des 3 niveaux: SMA200, SMA200+2.5$, SMA200+5$.

    Si le niveau n’est pas atteint, la position n’est pas ouverte, donc le nombre de positions est compris entre 0 et 3.

    Mon souci dans le code est de differencier chaque position. J’ai mis un flag pour qu’il ne puisse y avoir qu’une seule position a chaque niveau.

    En bactest ma premiere position (SMA200) est ouverte mais pas les 2 suivantes. Et pourtant les conditions du “if .. then” semblent etre toutes satisfaites pour les 2 autres niveaux d’ouverture de position.

    J’imagine que le probleme vient de ma gestion de la variable “flag” mais quand je la graph elle semble se comporter normalement.

    defparam cumulateorders = true
    
    MM200 = average[200](close)
    ecart = 2.5 
    
    bandemax = MM200 + 2 * ecart
    bandehaute = MM200 + 1 * ecart
    bandebasse = MM200 - 1 * ecart
    maxlong = countofshortshares
    
    if high[1] < bandemax and high[0]>bandemax and not flag = 3 and maxlong < 3 then 
    flag = 3
    sellshort 1 contract at market
    
    endif
    
    if high[1] < bandehaute and high[0] > bandehaute and not flag = 2 and maxlong < 3 then
    flag = 2
    sellshort 1 contract at market
    
    endif
    
    if high[1] < MM200 and high[0]>MM200 and not flag = 1 and maxlong < 3 then
    flag = 1
    sellshort 1 contract at market
    
    endif
    
    
    if low[0] < bandebasse then 
    exitshort at market
    flag = 0 
    endif
    
    
    set stop ploss 5

    Toute aide sera la bienvenue, merci !

    Greg

    #75068 quote
    Nicolas
    Keymaster
    Master

    Je n’ai pas testé, mais le problème vient peut être de la façon dont tu testes ta variable “flag” justement:

    defparam cumulateorders = true
    
    MM200 = average[200](close)
    ecart = 2.5 
    
    bandemax = MM200 + 2 * ecart
    bandehaute = MM200 + 1 * ecart
    bandebasse = MM200 - 1 * ecart
    maxlong = countofshortshares
    
    if high[1] < bandemax and high[0]>bandemax and flag <> 3 and maxlong < 3 then 
    flag = 3
    sellshort 1 contract at market
    
    endif
    
    if high[1] < bandehaute and high[0] > bandehaute and flag <> 2 and maxlong < 3 then
    flag = 2
    sellshort 1 contract at market
    
    endif
    
    if high[1] < MM200 and high[0]>MM200 and flag <> 1 and maxlong < 3 then
    flag = 1
    sellshort 1 contract at market
    
    endif
    
    
    if low[0] < bandebasse then 
    exitshort at market
    flag = 0 
    endif
    
    
    set stop ploss 5

    NOT test si une variable est fausse ou vrai, hors dés que celle-ci est renseignée (différente de 0), elle est forcément vrai.

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

compteur sur 3 positions distinctes


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
Greguigreg @greguigreg Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Nicolas
7 years, 8 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 07/02/2018
Status: Active
Attachments: No files
Logo Logo
Loading...