Problèmes de fermeture, aidez-nous - page 7

 
Ais wrote >>

Bonjour Cameofx,
Merci pour votre réponse.
Ce système de codage est très simple et facile.
Tout est fait manuellement dans MetaEditor.
En fait, le système est conçu pour développer de grands programmes facilement et à grande vitesse.
Le système devrait également être flexible et fiable.
Meilleures salutations !

Bonjour Ais
C'est un travail incroyable..... Comment le forum pourrait-il vous remercier ? Un merci et un hip, hip, hourra.
Je reconnais également la patience dont tu as fait preuve en expliquant les nombreuses questions que j'ai posées. Je vous remercie
Aujourd'hui, je vais comparer le programme qui n'a pas fonctionné, 1_20[1], avec ce programme, instruction par instruction. Il y a beaucoup à apprendre des deux.
Vous avez mentionné plus tôt dans le développement de ce programme, qu'avec la flexibilité de ce programme, des fonctionnalités peuvent être ajoutées. Il peut s'agir d'indicateurs, de la gestion de l'argent, de l'empilement des positions, de la modification des ordres en attente, etc ? Peut-on ajouter une fonction qui, lorsqu'une transaction a été liquidée, ne permet pas d'exécuter d'autres transactions sur la barre actuelle ? Ce n'est peut-être pas un problème pour certaines personnes sur le forum, mais j'aimerais faire un backtest avec une option où le système n'effectuerait pas de transactions immédiatement sur la barre actuelle après une liquidation. Est-ce possible ?
Merci d'être là.
Au revoir pour le moment.
 

Bonjour Ais
Il y a quelques changements subtils dans la comparaison. J'y suis depuis peu de temps, je n'ai pas terminé le travail. Mais une différence frappante concerne l'iNewBar (). En éliminant iNewBar (), et en remplaçant la variable iFirstRun par iTime_0, cela force le
( ( iNewBar () ==TRUE) || (iFirst == 1 ) ) hors de l'équation du programme. iSignalOpen est simplifié avec une exécution plus rapide.
Bon travail.
Cheers
< edited>
Ce qui précède prouve la même chose pour iSignalClose. Très facile de comprendre le contrôle passant par le programme.
Merci.

 

Bonjour Ais
J'ai trouvé une autre différence subtile dans les iTryOpen et iTryClose. Aucun impact apparent. Mais je vais me documenter sur les opérations 'else-if' pour être plus clair.
Merci encore.
Je reviens demain.
Au revoir

 
////////////////////////////////////////////////////////////////////<         1>
// < Program : Property >                                         //<          >
//   #define   1    " "                                           //<          >
//   #define   2    " "                                           //<          >
// </Program : Property >                                         //<          >
//                                                                //<          >
// < Program : Content >                                          //<          >
//                                                                //<          >
// < Structure             18 elements  in      4 domains       > //<          >
// < 1. Data                9 elements  in      2 domains      /> //<          >
// < 2. Code                9 elements  in      2 domains      /> //<          >
// </Structure             18 elements  in      4 domains       > //<          >
//                                                                //<          >
// < 1. Data                9 =       4 i       3 d       - s   > //<          >
// < 1.1. Input             8 =       5 i       3 d       - s  /> //<          >
// < 1.2. Buffer            1 =       1 i       - d       - s  /> //<          >
// </1. Data                9 =       4 i       3 d       - s   > //<          >
//                                                                //<          >
// < 2. Code                9 /       - i      80 l       3 o   > //<          >
// < 2.1. Interface         6 /       - i      69 l       3 o  /> //<          >
// < 2.2. Special           3 /       - i      11 l       - o  /> //<          >
// </2. Code                9 /       - i      80 l       3 o   > //<          >
//                                                                //<          >
// </Program : Content >                                          //<          >

////////////////////////////////////////////////////////////////////<         2>
// < 1.1. Data : Input >                                          //<          >
//                                                                //<          >
// < 1.1. Input             8 =       5 i       3 d       - s   > //<          >
// <      1. Strategy       4 =       2 i       2 d       - s  /> //<          >
// <      2. Trading        4 =       3 i       1 d       - s  /> //<          >
// </1.1. Input             8 =       5 i       3 d       - s   > //<          >
//                                                                //<          >
// <      1.1.1. Strategy 4 >=====================================//<          >
                    int       iBaseLag          = 20            ; //<          >
                    int       iBaseBar          = 1             ; //<          >
                    double    dFactorTP         = 1.0           ; //<          >
                    double    dFactorSL         = 2.0           ; //<          >
// </     1.1.1. Strategy 4 >=====================================//<          >
//                                                                //<          >
// <      1.1.2. Trading 4 >======================================//<          >
                    int       iTradeBarOnce     = 1             ; //<          >
                    int       iSlippage         = 1             ; //<          >
                    int       iMagic            = 1             ; //<          >
                    double    dLots             = 0.1           ; //<          >
// </     1.1.2. Trading 4 >======================================//<          >
//                                                                //<          >
//                                                                //<          >
// </1.1. Data : Input >                                          //<          >
 
////////////////////////////////////////////////////////////////////<         3>
// < 1.2. Data : Buffer >                                         //<          >
//                                                                //<          >
// < 1.2. Buffer            1 =       1 i       - d       - s   > //<          >
// <      1. Flags          1 =       1 i       - d       - s  /> //<          >
// </1.2. Buffer            1 =       1 i       - d       - s   > //<          >
//                                                                //<          >
// <      1.2.1. Flags 1 >========================================//<          >
                    int       iTradeBarTime     = EMPTY         ; //<          >
// </     1.2.1. Flags 1 >========================================//<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
// </1.2. Data : Buffer >                                         //<          >

////////////////////////////////////////////////////////////////////<         4>
// < 2.1. Code : Interface >                                      //<          >
//                                                                //<          >
// < 2.1. Interface         6 /       - i      69 l       3 o   > //<          >
// <      1. iReserved_1              - i       - l       - o  /> //<          >
// <      2. iSignalOpen              - i      17 l       1 o  /> //<          >
// <      3. iSignalClose             - i      15 l       1 o  /> //<          >
// <      4. iGetTicket               - i       7 l       1 o  /> //<          >
// <      5. iTryOpen                 - i      15 l       - o  /> //<          >
// <      6. iTryClose                - i      15 l       - o  /> //<          >
// </2.1. Interface         6 /       - i      69 l       3 o   > //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
// </2.1. Code : Interface >                                      //<          >
 
////////////////////////////////////////////////////////////////////<         5>
// < 2.1.1. Code : Interface : iReserved_1 >                      //<          >
//int     iReserved_1 ()     //       - i       - l       - o     //<          >
//{                                                               //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//}                                                               //<          >
// </2.1.1. Code : Interface : iReserved_1 >                      //<          >

////////////////////////////////////////////////////////////////////<         6>
// < 2.1.2. Code : Interface : iSignalOpen >                      //<          >
int       iSignalOpen ()     //       - i      17 l       1 o     //<          >
{                                                                 //<          >
if      ( iTradeBarTime    == iTime   ( 0 , 0 , 0 ) )             //<          >
if      ( iTradeBarOnce    == 1 )       return    ( EMPTY     ) ; //<          >
//                                                                //<          >
static    int       iTime_0 = EMPTY                             ; //<          >
if      (           iTime_0 < iTime   ( 0 , 0 , 0 ) )             //<          >
        {           iTime_0 = iTime   ( 0 , 0 , 0 )             ; //<          >
          iTradeBarTime     = EMPTY                             ; //<          >
          static    double    dHighest , dLowest                ; //<          >
          dHighest = High   [ iHighest ( 0 , 0    , MODE_HIGH ,   //<          >
                              iBaseLag , iBaseBar           ) ] ; //<          >
          dLowest  = Low    [ iLowest  ( 0 , 0    , MODE_LOW  ,   //<          >
                              iBaseLag , iBaseBar           ) ] ; //<          >
        } // if                                                   //<          >
double    dAsk    = MarketInfo        ( Symbol () , MODE_ASK  ) ; //<          >
double    dBid    = MarketInfo        ( Symbol () , MODE_BID  ) ; //<          >
if      ( dAsk    > dHighest )          return    ( OP_BUY    ) ; //<          >
if      ( dBid    < dLowest  )          return    ( OP_SELL   ) ; //<          >
                                        return    ( EMPTY     ) ; //<          >
}                                                                 //<          >
// </2.1.2. Code : Interface : iSignalOpen >                      //<          >
 
////////////////////////////////////////////////////////////////////<         7>
// < 2.1.3. Code : Interface : iSignalClose >                     //<          >
int       iSignalClose ()    //       - i      15 l       1 o     //<          >
{                                                                 //<          >
static    int       iTime_0 = EMPTY                             ; //<          >
if      (           iTime_0 < iTime   ( 0 , 0 , 0 ) )             //<          >
        {           iTime_0 = iTime   ( 0 , 0 , 0 )             ; //<          >
          static    double    dATR    , dProfit  , dLoss        ; //<          >
          dATR    = iATR    ( 0 , 0   , iBaseLag , iBaseBar   ) ; //<          >
        } // if                                                   //<          >
//                                                                //<          >
double    dDelta  = OrderOpenPrice () - OrderClosePrice ()      ; //<          >
//                                                                //<          >
if      ( OrderType ()     == OP_BUY  )                           //<          >
        { dProfit = -dDelta ; dLoss  =  dDelta                ; } //<          >
else if ( OrderType ()     == OP_SELL )                           //<          >
        { dProfit =  dDelta ; dLoss  = -dDelta                ; } //<          >
else                                    return    ( EMPTY     ) ; //<          >
//                                                                //<          >
if      ( dProfit > dATR * dFactorTP )  return    ( TRUE      ) ; //<          >
if      ( dLoss   > dATR * dFactorSL )  return    ( TRUE      ) ; //<          >
                                        return    ( EMPTY     ) ; //<          >
}                                                                 //<          >
// </2.1.3. Code : Interface : iSignalClose >                     //<          >

////////////////////////////////////////////////////////////////////<         8>
// < 2.1.4. Code : Interface : iGetTicket >                       //<          >
int       iGetTicket ()      //       - i       7 l       1 o     //<          >
{                                                                 //<          >
for     ( int i   = OrdersTotal () - 1 ; i >= 0 ; i -- )          //<          >
        {                                                         //<          >
          if      ( OrderSelect ( i , SELECT_BY_POS ) == TRUE   ) //<          >
          if      ( OrderMagicNumber ()               == iMagic ) //<          >
                                      return ( OrderTicket () ) ; //<          >
        } // for                                                  //<          >
                                      return ( EMPTY          ) ; //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
}                                                                 //<          >
// </2.1.4. Code : Interface : iGetTicket >                       //<          >
 
////////////////////////////////////////////////////////////////////<         9>
// < 2.1.5. Code : Interface : iTryOpen >                         //<          >
int       iTryOpen ()        //       - i      15 l       - o     //<          >
{                                                                 //<          >
int       iCommand          = iSignalOpen ()                    ; //<          >
if      ( iCommand         == EMPTY  )                return    ; //<          >
if      ( iCommand         == OP_BUY )                            //<          >
        { string    sType   = "Buy"  ;  int  iColor = Blue    ; } //<          >
else    {           sType   = "Sell" ;       iColor = Red     ; } //<          >
//                                                                //<          >
if      ( iCommand         == OP_BUY )  int  iMode  = MODE_ASK  ; //<          >
                                        else iMode  = MODE_BID  ; //<          >
double    dPrice  = MarketInfo ( Symbol () , iMode            ) ; //<          >
//                                                                //<          >
OrderSend  ( Symbol ()       , iCommand             , dLots   ,   //<          >
             NormalizeDouble ( dPrice , Digits )              ,   //<          >
             iSlippage  , 0  , 0 , "" , iMagic , 0  , iColor  ) ; //<          >
//                                                                //<          >
int       iTrap   = GetLastError ()                             ; //<          >
if      ( iTrap  == 0 )                                           //<          >
        { Alert   ( sType , " Was a Big Success"            ) ; } //<          >
else    { Alert   ( sType , " open exception "      , iTrap ) ; } //<          >
}                                                                 //<          >
// </2.1.5. Code : Interface : iTryOpen >                         //<          >

////////////////////////////////////////////////////////////////////<        10>
// < 2.1.6. Code : Interface : iTryClose >                        //<          >
int       iTryClose ()       //       - i      15 l       - o     //<          >
{                                                                 //<          >
int       iCommand          = iSignalClose ()                   ; //<          >
if      ( iCommand         == EMPTY  )                return    ; //<          >
if      ( OrderType ()     == OP_BUY )                            //<          >
        { string    sType   = "Buy"  ;  int  iColor = Red     ; } //<          >
else    {           sType   = "Sell" ;       iColor = Blue    ; } //<          >
//                                                                //<          >
if      ( OrderProfit ()    > 0      )  string sAct = "Take"    ; //<          >
                                        else   sAct = "Stop"    ; //<          >
double    dPrice  = OrderClosePrice ()                          ; //<          >
//                                                                //<          >
OrderClose ( OrderTicket ()  , OrderLots ()                   ,   //<          >
             NormalizeDouble ( dPrice , Digits )              ,   //<          >
             iSlippage                              , iColor  ) ; //<          >
//                                                                //<          >
int       iTrap   = GetLastError ()                             ; //<          >
if      ( iTrap  == 0 ) iTradeBarTime = iTime ( 0 , 0 , 0 ) ;   //<          >
          Alert   ( sType , " closed with Hard "    , sAct  ) ; } //<          >
else    { Alert   ( sType , " close exception "     , iTrap ) ; } //<          >
}                                                                 //<          >
// </2.1.6. Code : Interface : iTryClose >                        //<          >
 
////////////////////////////////////////////////////////////////////<        11>
// < 2.2. Code : Special >                                        //<          >
//                                                                //<          >
// < 2.2. Special           3 /       - i      11 l       - o   > //<          >
// <      1. init                     - i       1 l       - o  /> //<          >
// <      2. deinit                   - i       1 l       - o  /> //<          >
// <      3. start                    - i       9 l       - o  /> //<          >
// </2.2. Special           3 /       - i      11 l       - o   > //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
// </2.2. Code : Special >                                        //<          >

////////////////////////////////////////////////////////////////////<        12>
// < 2.2.1. Code : Special : Init >                               //<          >
int       init    ()         //       - i       1 l       - o     //<          >
{                                                                 //<          >
Alert   ( ""               , "Start " , UninitializeReason () ) ; //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
}                                                                 //<          >
// </2.2.1. Code : Special : Init >                               //<          >
 
////////////////////////////////////////////////////////////////////<        13>
// < 2.2.2. Code : Special : Deinit >                             //<          >
int       deinit  ()         //       - i       1 l       - o     //<          >
{                                                                 //<          >
Alert   ( ""               , "Stop "  , UninitializeReason () ) ; //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
}                                                                 //<          >
// </2.2.2. Code : Special : Deinit >                             //<          >

////////////////////////////////////////////////////////////////////<        14>
// < 2.2.3. Code : Special : Start >                              //<          >
int       start   ()         //       - i       9 l       - o     //<          >
{                                                                 //<          >
// < 2.2.3.1. History data inspection 4 >`````````````````````````//<          >
static    int       iTrigger   = 0       ; if ( iTrigger == 0 ) { //<          >
  if  ( ( iTime ( 0 , 0 , 0 ) == 0                          )     //<          >
  ||    ( iBars ( 0 , 0     )  < iBaseLag     + iBaseBar    ) )   //<          >
          return                         ; else iTrigger  = 1 ; } //<          >
// </2.2.3.1. History data inspection 4 >`````````````````````````//<          >
//                                                                //<          >
// < 2.2.3.2. Main routine 3 >````````````````````````````````````//<          >
int       iTicket           = iGetTicket ()                     ; //<          >
//                                                                //<          >
if      ( iTicket < 0 )       iTryOpen   ()                     ; //<          >
else                          iTryClose  ()                     ; //<          >
// </2.2.3.2. Main routine 3 >````````````````````````````````````//<          >
//                                                                //<          >
// < 2.2.3.3. Exception handler 2 >```````````````````````````````//<          >
int       iTrap   =           GetLastError ()                   ; //<          >
if      ( iTrap   > 0 )       Alert  ( "Exception " , iTrap   ) ; //<          >
// </2.2.3.3. Exception handler 2 >```````````````````````````````//<          >
}                                                                 //<          >
// </2.2.3. Code : Special : Start >                              //<          >
////////////////////////////////////////////////////////////////////<         0>


Liste complète des modifications :

1. La variable globale "int iTradeBarOnce = 1 ;" a été ajoutée au domaine "Data : Input".
2. Le domaine "Data : Buffer" a été créé.
3. La variable globale "int iTradeBarTime" a été ajoutée au domaine "Data : Buffer".
4. La fonction vide "iReserved_1 ()" a été ajoutée.
5. La fonction "iSignalOpen ()" a été modifiée.
6. La fonction "iTryClose ()" a été modifiée.


Notes :

1. La variable globale "int iTradeBarOnce" permet / interdit la répétition des transactions sur la même barre.
2. La valeur de cette variable "0" autorise et la valeur "1" interdit la répétition des transactions sur la même barre.
3. La variable globale "int iTradeBarTime" transmet l'heure d'ouverture de la barre négociée par la fonction "iTryClose ()".
4. La fonction "iSignalOpen ()" reçoit cette valeur et l'utilise pour contrôler la répétition de la transaction.
5. J'aime utiliser les valeurs "1" et "0" au lieu de "VRAI" et "FAUX".
6.

Les instructions suivantes sont équivalentes, mais la première fonctionne plus rapidement :

if      ( iTradeBarTime    == iTime   ( 0 , 0 , 0 ) )             //<          >
if      ( iTradeBarOnce    == 1 )       return    ( EMPTY     ) ; //<          >

if    ( ( iTradeBarTime    == iTime   ( 0 , 0 , 0 ) )             //<          >
     && ( iTradeBarOnce    == 1 ) )     return    ( EMPTY     ) ; //<          >

7. La fonction vide "iReserved_1" a été ajoutée pour une utilisation future.


Dernière modification : 2010.03.18 22:54
Etat : Prêt



Bonjour Huckleberry et salut !
Un peu plus tard, je vais légèrement étendre le programme pour le rendre plus lisible.
Santé !

Dossiers :
1_29.mq4  27 kb