Eaが複数の同じ保留/制限注文を作成している [Help pls] 。 - ページ 4

 
cashcube:

さらに、ストップした注文のリバーストレードも機能しない。

これは信頼性が低いということはすでに言われていることですが

            if(Volume[0]>1) return(0);

これは何もしません

//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick(){
   static datetime timeCur; datetime timePre = timeCur; timeCur=Time[0];
   bool isNewBar = timeCur != timePre;
   if(isNewBar){ 
     return; // Once per bar
   }
   return; // every tick
}  

新しいバーであれば戻り、そうでなければ戻るので、いつも何もせずに戻ってきます。

新しいバーが見つかったら、値をリセットする必要があります。

void OnTick(){
   datetime timeCur=Time[0]; 
   static datetime timePre = timeCur;
   bool isNewBar = timeCur != timePre;
   if(isNewBar){ 
     timePre=timeCur;
     //Do what you want at each new bar // Once per bar
   }
   //Do other stuff that you may need to do every tick
   return; // every tick
}   

最後の注文をチェック するコードでは、注文履歴の中で最も高いインデックスが最新の決済済み取引であると仮定しています。これが常に正しいかどうかはわかりません。

 

OK 私はコードを適用しました...しかし、私はそれぞれの新しいバーで開始関数を 呼び出そうとしたとき...それはどんな注文も取りません...。

void OnTick(){
   datetime timeCur=Time[0]; 
   static datetime timePre = timeCur;
   bool isNewBar = timeCur != timePre;
   if(isNewBar){ 
     timePre=timeCur;
     //Do what you want at each new bar // Once per bar
start();
   }
   //Do other stuff that you may need to do every tick
   return; // every tick
}   

たとえ私が新しいバーゾーンの中にbuyCallとsellcall関数を追加しても、そしてティックゾーンの中にstart()...その複数の注文を作成します。

 
OnTick()とstart()を持つべきではありません、私はそれが何をするか推測することはできません。
 
以下はEAのフルコードです。
// Init function
int init()
{

int CalcDigits = (int)MarketInfo(Symbol(),MODE_DIGITS);

if(CalcDigits == 2 || CalcDigits == 4) CalcSlippage = SlippagePips;
else if(CalcDigits == 3 || CalcDigits == 5) CalcSlippage = SlippagePips * 10;      


if(CalcDigits == 2 || CalcDigits == 3) CalcPoint1 = 0.01;
else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint1 = 0.0001;
      
UsePoint = CalcPoint;
UseSlippage = (int) CalcSlippage; 
return (0);
}
//+------------------------------------------------------------------+

int start()
{

double open = iOpen(NULL,PERIOD_H1,0);        // current candles Open
int CH = TimeHour(TimeCurrent()); // current hour    
double LO = iOpen(NULL,PERIOD_H1,1);
double LC = iClose(NULL,PERIOD_H1,1);
  
//----------------------------  Calculation
double CalcDigits = MarketInfo(Symbol(),MODE_DIGITS);
      {
      if(CalcDigits == 2 || CalcDigits == 3) CalcPoint = 100;
      else if (CalcDigits == 4 || CalcDigits == 5) CalcPoint = 10000;
      }
           
///----------------------------------------------

FS = Split(open);

//-------- 2nd part of Calculation----------------//

S0 = open - (double(FS)* CalcPoint1);
S1 = open - (double((FS*2))* CalcPoint1);
S2 = open - (double((FS*4))* CalcPoint1);
S3 = open - (double((FS*8))* CalcPoint1); 
S4 = open - (double((FS*16))* CalcPoint1);
S5 = open - (double((FS*32))* CalcPoint1);
 
R0 = open + (double(FS)* CalcPoint1);
R1 = open + (double((FS*2))* CalcPoint1);
R2 = open + (double((FS*4))* CalcPoint1);
R3 = open + (double((FS*8))* CalcPoint1); 
R4 = open + (double((FS*16))* CalcPoint1); 
R5 = open + (double((FS*32))* CalcPoint1);  


//---------2nd part-------------------//
   P1 = Split(S0);
   P2 = Split(S1);
   P3 = Split(S2);
   P4 = Split(S3);
   P5 = Split(S4);
   P6 = Split(S5);
   P7 = Split(R0);
   P8 = Split(R1);
   P9 = Split(R2);
   P10 = Split(R3);
   P11 = Split(R4);
   P12 = Split(R5);

 //--------------------
   if(FS == P1 && LC > LO)  BuyCall(S0);
   if(FS == P2 && LC > LO)  BuyCall(S1);
   if(FS == P3 && LC > LO)  BuyCall(S2);
   if( FS == P4 && LC > LO) BuyCall(S3);   
   if( FS == P5 && LC > LO) BuyCall(S4);
   if( FS == P6 && LC > LO) BuyCall(S5);
   if( FS == P7 && LC < LO) SellCall(R0);
   if( FS == P8 && LC < LO) SellCall(R1);
   if( FS == P9 && LC < LO) SellCall(R2);
   if( FS == P10 && LC < LO) SellCall(R3);
   if( FS == P11 && LC < LO) SellCall(R4);                    
   if( FS == P12 && LC < LO) SellCall(R5);     
 
   //-----------------End of experiment----------

//-------------------Reverse trade for Sell
     for(xxx =OrdersHistoryTotal()-1;xxx >=0;xxx --)
     {
         if(OrderSelect(xxx, SELECT_BY_POS,MODE_HISTORY))
         {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()== MagicNumber)
          
          //for sell order reverse
          if(OrderType()==OP_SELL && OrderProfit()<0)    
          { 
             if (OrderOpenPrice()== R0 || OrderOpenPrice()== R1 ||OrderOpenPrice()== R2 ||OrderOpenPrice()== R3 ||OrderOpenPrice()== R4 ||OrderOpenPrice()== R5 )
               {
      
            BuyStopLoss = Ask - (StopLoss * CalcPoint1);
            BuyTakeProfit = Ask + (TakeProfit * CalcPoint1);
            BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,UseSlippage,BuyStopLoss,BuyTakeProfit,"Buy Reverse Order",MagicNumber,0,Green);
          }
          break; 
          }
          }
          } 
   
  //-------------Reverse trade for buy
     for(xx =OrdersHistoryTotal()-1;xx >=0;xx --)
     {
         if(OrderSelect(xx, SELECT_BY_POS,MODE_HISTORY))
         {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()== MagicNumber)
           {
          //for buy order reverse
          if(OrderType()==OP_BUY && OrderProfit()<0)
          { 
           if (OrderOpenPrice()== S0 || OrderOpenPrice()== S1 ||OrderOpenPrice()== S2 ||OrderOpenPrice()== S3 ||OrderOpenPrice()== S4 ||OrderOpenPrice()== S5 )
               {         
    
            SellStopLoss = Bid + (StopLoss * CalcPoint1);
            SellTakeProfit = Bid - (TakeProfit * CalcPoint1);
            SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,UseSlippage,SellStopLoss,SellTakeProfit,"Sell Reverse Order",MagicNumber,0,Red); 
          
          }
         break; 
          }
          }
          }
     } 

//------WHODER CODE for Order Close/Delete in every hour -------

for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) 
if (OrderSelect(pos, SELECT_BY_POS)  &&  OrderMagicNumber() == MagicNumber &&  OrderSymbol() == Symbol() )
{   
     if(OrderType()==OP_SELL && OrderMagicNumber() == MagicNumber &&  OrderSymbol() == Symbol())
     {
     int k = (TimeHour((int)OrderOpenTime())*60) + TimeMinute((int)OrderOpenTime()); 
     int m = (TimeHour((int)TimeCurrent())*60) +  TimeMinute((int)TimeCurrent());    
     if (m >= k+59)
      bool closed = OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(),UseSlippage,Blue);
     }
     //--------------
      if(OrderType()==OP_BUY && OrderMagicNumber() == MagicNumber &&  OrderSymbol() == Symbol())
     {
     int k1 = (TimeHour((int)OrderOpenTime())*60) + TimeMinute((int)OrderOpenTime()); 
    int m1 = (TimeHour((int)TimeCurrent())*60) +  TimeMinute((int)TimeCurrent());    
     if (m1 >= k1+59)
     bool closed = OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(),UseSlippage,Blue);
    }        
}   

   
return(0);
}

このstart関数と一緒に、main関数で呼ばれる以下のような追加関数があります。

int split(double x)

void BuyCall(double BC)

void SellCall(double SC)

そして最後に void onTick 関数ですが、これはどう設定すればよいのでしょうか。

...各時間に保留中の注文のシーケンスを1つだけ...さらに、保留中の注文が停止された場合、それをチェックします。

...そして、それは反対方向に別の取引を開始します...しかし、1時間に1つのシーケンスだけ。

何度も何度も同じところで立ち往生しているのですが、明らかに学びたいのです。

...私のコンセプトをクリアしたいのですが...:(

お時間をいただきありがとうございました。

 
この場合、tick 毎に 値が割り当てられるのではなく、ロード時に一度だけ値が割り当てられます。
static datetime timePre = timeCur;
簡略化
void OnTick(){
   static datetime timeCur;
   datetime timePre = timeCur; timeCur=Time[0]; 
   bool isNewBar = timeCur != timePre;