[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 212

 

Now it's not clear what is returned from the function

return(OrdOpenTimeBuy);

 
Roger:

Now it's not clear what is returned from the function

return(OrdOpenTimeBuy);

Is it better?

//=========== OrdTimeBuy_b(int MAGIC) ===============================================================
//  Функция возвращает время открытия последнего рыночного Buy-ордера, принадлежащего MAGIC или 777 
//---------------------------------------------------------------------------------------------------
datetime OrdTimeBuy_b(int MAGIC)
 {
  string SMB=Symbol();
  datetime OrdOpenTimeBuy=0;
  int i;
  for(i=0;i<OrdersTotal();i++)
   {
    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)
     {
      if(OrderSymbol()==SMB)
       {
        if(OrderMagicNumber()==MAGIC || OrderMagicNumber()==777)
         {
          if(OrderType()==OP_BUY)
           {
            if(OrdOpenTimeBuy<OrderOpenTime())
             {
              OrdOpenTimeBuy=OrderOpenTime();
             }  
           }  
         }  
       }          
     }
   }
   if(OrdOpenTimeBuy==0) return(0);
   return(OrdOpenTimeBuy);
 }
//=====================================================================================================


//===========  Локальная низинка  =================================================================
  double LowestPoint_b(int MAGIC)
   {  
    datetime OrdOpenTimeBuy=OrdTimeBuy_b(MAGIC);  
    int ShiftBuy=0;
    double LowestPoint=0;
    if (OrdOpenTimeBuy!=0)
     {  
      ShiftBuy=iBarShift(NULL,PERIOD_M1,OrdOpenTimeBuy,true);
      LowestPoint=iLow(NULL,PERIOD_M1,iLowest(NULL,PERIOD_M1,MODE_LOW,ShiftBuy,0));
     } 
    return(LowestPoint);
   }  
//=================================================================================================
 
nemo811:

Is that better?


Yeah, that'll do.
 
Roger:
sergeev:

Thank you.

I've fixed these errors, but the EA is still glitchy. Let's continue digging :)

 
nemo811:

Thank you.

I fixed those errors, but the EA is still glitchy. We'll keep digging :)


I thought your metaeditor.exe file was deleted and you're checking for errors manually.

If it's an EA, it definitely won't work. you don't have a start function in your code.

 

I've got my head all messed up.

I wrote this code:

  RefreshRates();
  bool ticket2=false;
  if(st_TrStop>0 && SchSellStop777_b()>0) {
   double LowestPoint=LowestPoint_b(MAGIC);
   double ee=0;
   for (i=OrdersTotal()-1;i>=0;i--) {//Начало цикла
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {WriteError(i);}
    else{//начало работы с выбранным ордером
     if(OrderSymbol()==SMB && OrderMagicNumber()==MAGIC) {
     if(OrderType()==OP_BUY) {//находится вверху, едет вниз  
     Last_OrderOpBuy(MAGIC);
     if(((Ask-(st_BU+ad.Spred+1)*Point)>=OrderOpenPrice()) ||
        ((Ask-(st_TrStop-1-ad.Spred)*Point)>=LowestPoint)) {

     if((Ask-(st_BU+ad.Spred+1)*Point)>=OrderOpenPrice())
      {
       Price_SS=NormalizeDouble(OrderOpenPrice()+(ad.Spred+1)*Point,Digits);
      }
     else
      { 
       Price_SS=NormalizeDouble(LowestPoint-1*Point,Digits);     
      }  

     if(ChastZakr)
      {
       if(SchBuy>1)
        {  
         OrderClose(OrdTicketBuy,OrderLots(),MarketInfo(OrderSymbol(), MODE_BID),Proskalz,CLR_NONE);
         Alert(SMB,": произведено частичное закрытие Buy-позиции, тикет: ",OrdTicketBuy,".");
         ee=SchBuyLots-OrderLots();
        }   
       else
        {  
         if(SchBuyLots+SchBuyLots777>MinLot)
          { 
           OrderClose(OrdTicketBuy,NormalizeDouble(OrderLots()/2,2),MarketInfo(OrderSymbol(), MODE_BID),Proskalz,CLR_NONE);
           Alert(SMB,": произведено частичное закрытие Buy-ордера, тикет: ",OrdTicketBuy,".");
           ee=SchBuyLots-NormalizeDouble(OrderLots()/2,2);
          }  
        }  
      }
     else
      {   
       ee=SchBuyLots;
      }

      DeleteOtlozhMAGIC(MAGIC);
      DeleteOtlozh777();
      ticket2=OrderSend(Symbol(),OP_SELLSTOP,ee,Price_SS,Proskalz,0,0,"MAGIC_" + MAGIC,MAGIC,0);
        if(ticket2!=0 && ticket2!=-1) {
          Alert (SMB,": установлен траловый SellStop.");
          Print(SMB,": установлен траловый SellStop.");
         }
        if(ticket2==0 || ticket2==-1) {
          GLE=GetLastError();
          ED=ErrorDescription(GLE);
          Alert (SMB,": ошибка №",GLE," установки тралового SellStop.");
          Alert (SMB,": описание ошибки - ",ED);
          Print (SMB,": ошибка №",GLE," установки тралового SellStop."); 
          Print (SMB,": описание ошибки - ",ED);
         }
       }       
      }       
     }  
    }  
   }  
  }
 

It's glitchy. But if you put a specific number in the condition..:

     if(((Ask-(st_BU+ad.Spred+1)*Point)>=OrderOpenPrice()) ||
        ((Ask-(st_TrStop-1-ad.Spred)*Point)>=LowestPoint)) {

...instead of LowestPoint, everything works like clockwork.

Looking for LowestPoint is given in the post above.

Please help me, it's the second day of digging.

Thanks in advance.

 
sergeev:

I thought your metaeditor.exe file was deleted and you were checking for errors manually.

If this is an EA, it definitely will not work. You don't have the start function in your code.

You are very meticulous, but I thank you for that too.

I'm only showing the part of the code I'm interested in. If you post the whole EA, the question may get lost :)

Thank you.

 
you do not check the value by -1
ShiftBuy
 
MESSAGE, IS there a function, like ihighest only for MACD
 
CLAIN:
MESSAGE, IS there a fUNCTION like ihighest only for MACD

I haven't come across it, but it is possible to write... This would be about the maximum value of the main line for the last 10 bars, not counting the current one:

double Hi ()
{ int i,j; H=0;
while (i<=10)
{if (H<iMACD (NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i+1)) 
H=iMACD (NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i+1);
i++;}
return(H);
}