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
}   

마지막 주문을 확인 하는 코드는 주문 내역에서 가장 높은 지수가 가장 최근에 마감된 거래라고 가정합니다. 이것이 항상 사실인지 확실하지 않습니다.

 

좋아, 나는 코드를 적용했지만 ... 각 새로운 막대에서 시작 기능 을 호출하려고 할 때 ... 주문을받지 않습니다 ...

 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
}   

new bar zone..& start() 내부에 buyCall 및 Sellcall 기능을 추가하더라도 틱 영역 내부에... 여러 주문을 생성합니다.

 
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 );
}

이 시작 기능과 함께 ... 다음과 같은 추가 기능이 있습니다.이 기능은 기본 기능에서 호출됩니다.

정수 분할(이중 x)

무효 BuyCall(이중 BC)

무효 SellCall(더블 SC)

& 마지막으로 내가 혼란스러워하는 onTick 기능을 무효화합니다 ... 어떻게 설정해야합니까 .. 틱 단위로 보류중인 주문 을 반복하지 않습니다

..각 시간에 하나의 보류 중인 주문 시퀀스만 ... 또한 보류 중인 주문이 중단되었는지 확인합니다.

..그러면 반대 방향으로 또 다른 거래가 열릴 것입니다. 그러나 시간당 하나의 시퀀스만 가능합니다.

계속해서 같은 영역에 갇혀 있는 것을 도와주세요...하지만 분명히 배우고 싶습니다... 그래서 앞으로는 어리석은 질문을 할 필요가 없습니다.

...내 컨셉을 지우고싶다..:(

시간 내 주셔서 감사합니다.

 
이것은 매 틱마다 값을 할당하지 않고 로드 시 한 번만 할당합니다.
 static datetime timePre = timeCur;
단순화
 void OnTick (){
   static datetime timeCur;
   datetime timePre = timeCur; timeCur=Time[ 0 ]; 
   bool isNewBar = timeCur != timePre;
사유: