2

このエラーが見つかりましたが、理由がわかりません (構文は C に似ています)。

関数は売り注文で買い注文を閉じることになっていますが、私は.
error 3: invalid trade parameters

間違って設定しているパラメータはありますか?

以前に正常に呼び出したことがあるので、正しいOrderClose()と思います。OrderSend()

void closeBuySell(int buyTicket){
   double buyPrice = OrderClosePrice();
   //Print("total ",OrdersTotal()," ",buyTickets," ",sellTickets);
   for(int Counter=0; Counter<OrdersTotal(); Counter++){ //search for a matching sell
      if(OrderSelect(Counter,SELECT_BY_POS) && OrderType()==OP_SELL && OrderOpenPrice()>buyPrice){
         Print("CLOSING BUYSELL ",buyTicket," ",OrderTicket()," ",OrderOpenPrice(),">",buyAsk);
         if(OrderCloseBy(buyTicket,OrderTicket(),Red)){ buyTickets--; sellTickets--; }
         else Print(ErrorDescription(GetLastError()));
         break;
      }
   }
}

int buyTickets=0;
int sellTickets=0;
bool up = false;
void OnTick(){
   double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);
   double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);
   if(FastMA>SlowMA && !up){ up=true;
       if(buyTickets<15 && OrderSend(Symbol(),OP_BUY,.1,Ask,40,0,0))
           buyTickets++;
   }
   if(FastMA<SlowMA && up){ up=false;
       if(sellTickets<15 && OrderSend(Symbol(),OP_SELL,.1,Bid,40,0,0))
           sellTickets++;
   }

   for(int Counter=0; Counter<OrdersTotal(); Counter++) //ordercloseby buy with sell
      if(OrderSelect(Counter,SELECT_BY_POS) && OrderType()==OP_BUY)
          closeBuySell(OrderTicket());
}

出力:

...after
13:42  practice1 EURUSD,M5: invalid trade parameters
13:42  practice1 EURUSD,M5: OrderCloseBy error 3
13:42  practice1 EURUSD,M5: CLOSING BUYSELL 17 8 1.086>1.086
13:40  practice1 EURUSD,M5: invalid trade parameters
13:40  practice1 EURUSD,M5: OrderCloseBy error 3
13:40  practice1 EURUSD,M5: CLOSING BUYSELL 23 1 1.0858>1.0855
13:40  practice1 EURUSD,M5: invalid trade parameters
13:40  practice1 EURUSD,M5: OrderCloseBy error 3
13:40  practice1 EURUSD,M5: CLOSING BUYSELL 22 1 1.0858>1.0855
00:05  practice1 EURUSD,M5: sell orders:12
00:05  practice1 EURUSD,M5: open #12 sell limit 0.10 EURUSD at 1.08598 ok
00:05  practice1 EURUSD,M5: sell orders:11
00:05  practice1 EURUSD,M5: open #11 sell limit 0.10 EURUSD at 1.08599 ok
00:05  practice1 EURUSD,M5: sell orders:10
00:05  practice1 EURUSD,M5: open #10 sell limit 0.10 EURUSD at 1.08600 ok
...before
4

1 に答える 1

1

はい、いくつかの詳細を変更する必要があります。

公正な通知、注意してください、言語でMQL4はありませんC- 要するに -stringは実際には ではありませんstringstruct、コンパイルモードは、代数式の演算子の優先順位を静かに変更します (!!) (「機械的に」括弧によって強制されない場合)ほとんど目に見えない指示によって曖昧に制御され#property strict、同様の危険な違いが適用されます。

マイナーな問題、いわゆる成行注文には有効期限パラメーター設定がありません。これらは「市場で」すぐに実行されるため、有効期限の TimeDOMAIN-horizo​​n はこれらには意味がありません。

関数にアクセスする前に必須の手順を忘れているようですdb.POOL-OrderSelect()呼び出し:

int buyTickets  = 0;
int sellTickets = 0;
int mn          = 0;

void OnTick(){

     double FastMA = iMA( NULL, 0, FastMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 0 );
     double SlowMA = iMA( NULL, 0, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 0 );

     if (  FastMA >  SlowMA &&  buyTickets <  15 ){  buy( .1 ); Print(  "buy orders:",  buyTickets ); }
     if (  FastMA <  SlowMA && sellTickets <  15 ){ sell( .1 ); Print( "sell orders:", sellTickets ); }

     for ( int Counter = 0; Counter <  OrdersTotal(); Counter++ )
     {   OrderSelect( Counter, SELECT_BY_POS );   // *MUST* .SELECT() 1st
         if (  OrderType()      == OP_BUY         //         to access Order*() funcs
            && OrderCloseTime() == 0              // *!CLOSED* only
            && FastMA           <  SlowMA         // aPriceDOMAIN condition holds
            )  closeBuySell( OrderTicket() );     // closeBuySell()
     }
}

void buy( const double LotSize ){
     int    Slippage       = GetSlippage( Symbol(), 4 ); // ~ 40
     double StopLoss       = 0;
     double TakeProfit     = 0;
     int    MagicNumber    = mn++;
     int    ExpirationDate = TimeCurrent() + PERIOD_M1 * 60 * 24;
     int    buyTicket      = OrderSend( Symbol(),
                                        OP_BUY,
                                        LotSize,
                                        Ask,
                                        Slippage,
                                        StopLoss,
                                        TakeProfit,
                                        "Buy Order",
                                        MagicNumber,
                                        ExpirationDate, // --------------
                                        Green
                                        );
     if (  buyTicket == -1 ) Print( "OrderSend Error:", ErrorDescription( GetLastError() ) );
     else  buyTickets++;
}

void sell( const double LotSize ){
     int    Slippage       = GetSlippage( Symbol(), 4 );
     double StopLoss       = 0;
     double TakeProfit     = 0;
     int    MagicNumber    = mn++;
     int    ExpirationDate = TimeCurrent() + PERIOD_M1 * 60 * 24;
     int    sellTicket     = OrderSend( Symbol(),
                                        OP_SELL,
                                        LotSize,
                                        Bid,
                                        Slippage,
                                        StopLoss,
                                        TakeProfit,
                                        "Sell Order",
                                        MagicNumber,
                                        ExpirationDate, // --------------
                                        Green
                                        );
     if (  sellTicket == -1 ) Print( "OrderSend Error:", ErrorDescription( GetLastError() ) );
     else  sellTickets++;
}

void closeBuySell( const int buyTicket ){
     OrderSelect( buyTicket, SELECT_BY_TICKET );
     double buyAsk = OrderClosePrice();
  // Print( "total ", OrdersTotal(), " ", buyTickets, " ", sellTickets );
     for ( int Counter = 0; Counter < OrdersTotal(); Counter++ ){ // search for a matching sell
           OrderSelect( Counter, SELECT_BY_POS );
           if (  OrderType()      == OP_SELL
              && OrderCloseTime() == 0            // *!CLOSED" only
              && OrderOpenPrice() >  buyAsk
              ){
              Print( "CLOSING BUYSELL ", buyTicket, " ", OrderTicket(), " ", OrderOpenPrice(), ">", buyAsk );
              if (  OrderCloseBy( buyTicket, OrderTicket(), Red ) ){
                     buyTickets--;
                    sellTickets--;
              }
              else  Print( ErrorDescription( GetLastError() ) );
              break;
           }
     }
}
于 2016-06-05T16:02:58.760 に答える