关闭的问题,请帮助 - 页 7

 
Ais wrote>>

你好,Cameofx,
谢谢你的回复。
这个编码系统非常简单易行。
所有的工作都是在MetaEditor中手动完成的。
事实上,该系统的设计是为了方便和高速地开发大型程序。
该系统也应该是灵活和可靠的。
最好的问候!

你好,艾斯
这是一项令人难以置信的工作.....论坛怎么能不感谢你呢?感谢你,并向你致敬,万岁。
我也感谢你在解释我提出的许多问题时花费的耐心。我感谢你
今天我将把没有成功的程序1_20[1]与这个程序的语句逐一进行比较。两者之间有很多值得学习的地方。
你在这个程序的开发过程中曾提到,由于这个程序的灵活性,可以增加一些功能。功能可以是指标、资金管理、叠加头寸、修改挂单等?能否增加一个功能,即当一个交易被清算后,在当前栏中不再执行任何交易?这对论坛上的一些人来说可能不是问题,但我想用一个选项进行回溯测试,即系统在清算后不会立即在当前栏上进行交易。这可能吗?
谢谢你在这里。
暂时再见。
 

Hi Ais
在比较中,有一些微妙的变化。我只做了很短的时间,我还没有完成这项工作。但一个引人注目的区别是iNewBar()。通过消除iNewBar(),用iTime_0代替iFirstRun变量,这就迫使
( ( iNewBar() ==TRUE) || (iFirst == 1 ) ) 从程序方程中消失。iSignalOpen被简化,执行速度更快。
伟大的工作。
干杯
<编辑>
以上证明了iSignalClose的情况也是如此。非常容易理解通过程序的控制
谢谢你。

 

你好,Ais
在iTryOpen和iTryClose中又发现了一个细微的差别。没有明显的影响。但我将阅读 "else-if "操作程序,以了解情况。
再次感谢。
明天再来吧。
谢谢

 
////////////////////////////////////////////////////////////////////<         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>


完整的变化列表:

1.全局变量 "int iTradeBarOnce = 1; "被添加到域 "Data :输入"。
2.域名 "Data :创建了 "缓冲区 "域。
3.全局变量 "int iTradeBarTime "已经被添加到域 "Data :
4.增加了空函数 "iReserved_1 ()"。
5.函数 "iSignalOpen() "已被修改。
6.函数 "iTryClose() "已被修改。


备注:

1.全局变量 "int iTradeBarOnce "允许/禁止在同一根柱子上重复交易。
2.这个变量的值 "0 "允许,值 "1 "禁止在同一条街上重复交易。
3.全局变量 "intTradeBarTime "从函数 "iTryClose() "中传输交易栏的打开时间
4.函数 "iSignalOpen() "接收到这个值并使用它来控制重复交易。
5.我喜欢使用 "1 "和 "0 "值,而不是 "TRUE "和 "FALSE"。
6.以下语句是等价的,但第一条工作得更快:

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

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

7.增加了空函数 "iReserved_1 "供将来使用。


最后编辑: 2010.03.18 22:54
状态。Ready



Hello Huckleberry and hi!
稍后我将稍微扩展程序,使其更具可读性。
Cheers!

附加的文件:
1_29.mq4  27 kb