閉じる問題、助けてください - ページ 7

 
Ais wrote>>



このコーディングシステムは非常にシンプルで簡単です。 全てMetaEditorで手動で行います。 実際、大きなプログラムを簡単に高速で開発できるように設計されています。 また、柔軟で信頼できるシステムでなければなりません。 よろしくお願いします!




Aisさん、こんにちは。
これはすごい作品ですね......。フォーラムはあなたにどう感謝したらいいのでしょうか?ありがとうございます、そしてありがとうございます。
また、私が投げかけた多くの質問を説明する間、あなたが費やした忍耐力にも感謝します。私はあなたに感謝します
今日は、うまくいかなかったプログラム、1_20[1]とこのプログラムを文ごとに比較します。両方から学ぶことがたくさんあります。
あなたは、このプログラムの開発において、このプログラムの柔軟性で、機能を追加することができることを以前に言及した。機能とは、インジケーター、資金管理、ポジションの積み重ね、保留中の注文の変更などでしょうか?取引が清算されると、現在のバーでそれ以上の取引は実行されないという機能を追加できますか?これはフォーラムの一部の人々には問題ではないかもしれませんが、私はシステムが清算後に現在のバーですぐに取引しないオプションでバックテストをしたいと思います。可能でしょうか?
ここにいてくれてありがとうございました。
では、また。
 

Aisさんこんにちは
比較すると微妙に変化しているところがありますね。短時間の作業なので、完成していません。しかし、印象的な違いは、iNewBar()のところです。iNewBar () をなくし、iFirstRun 変数を iTime_0 に置き換えることで、
( ( iNewBar () ==TRUE) || (iFirst == 1 ) ) をプログラム式から強制的に排除します。iSignalOpen はより高速な実行で簡素化されています。
素晴らしい出来です。
Cheers
<編集>
上記は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 .Input」に追加されました。
2.ドメイン "Data :
3. Data : Buffer が作成されま

した。

グローバル変数「int iTradeBarTime」がドメイン「Data .Buffer」に追加されました。
4.空の関数「iReserved_1()」が追加されました。
5.関数 "iSignalOpen() "を変更しました。
6.


注意事項:

1.グローバル変数 "int iTradeBarOnce" は、同じバーで取引を繰り返すことを許可/禁止します。
2.
3. グローバル変数 "int iTradeBarOnce "は、同じバーで繰り返し取引を行うことを

許可/禁止します。

グローバル変数int iTradeBarTimeはiTryClose()関数から取引されたバーの開始 時間を送信します。
4.iSignalOpen()関数がこの値を受け取り、取引の繰り返しを制御するために使用します。
5.私は「TRUE」「FALSE」の代わりに「1」「0」を使うのが好きです。
6.

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

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

7.


Last edit: 2010.03.18 22:54
State:Ready



ハックルベリーとこんにちは!
もう少ししたら、プログラムを少し拡張して読みやすくしようと思っています。
乾杯!

ファイル:
1_29.mq4  27 kb