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

 
isaev-av:

Thank you. Do Digits need to be changed to 4 or 5 depending on the DC?

You don't have to change it, you just have to take it depending on the currency. MarketInfo
 
isaev-av:

Thank you. Do the Digits need to be changed to 4 or 5, depending on the DC?

Just leave the Digits, it'll just fit itself.
 
Comrades, considering a very simple system... if the MACD is in the zone for no more than 5 minutes, then I open. For some reason trades don't open.... advise please...
//+------------------------------------------------------------------+ 
  //| MACD ^^^.mq4 | 
  //| Copyright © 2011, MetaQuotes Software Corp. | 
  //| http://www.metaquotes.net | 
  //+------------------------------------------------------------------+ 
  #property copyright "Copyright © 2011, MetaQuotes Software Corp." 
  #property link "http://www.metaquotes.net" 

  extern int TP = 100; 
  extern int TS = 100; 
  extern int TF = 1; 
  extern double lots = 0.1; 
  int fast_ema = 5; 
  int slow_ema = 34; 
  int signal_period = 5; 
  int slip = 3; 
  int Magic = 1; 

 int total; 
 int ticket; //объявил тотал и тикет 

 //+------------------------------------------------------------------+ 
  //| expert initialization function | 
  //+------------------------------------------------------------------+ 
  int init() 
    { 
  //---- 

 //---- 
     return(0); 
    } 
  //+------------------------------------------------------------------+ 
  //| expert deinitialization function | 
  //+------------------------------------------------------------------+ 
  int deinit() 
    { 
  //---- 

 //---- 
     return(0); 
    } 
  //+------------------------------------------------------------------+ 
  //| expert start function | 
  //+------------------------------------------------------------------+ 
  int start() 
    { 
  //---- 

 bool signal = signal_MACD(); 
  AnalyzeSignal(signal); 

 //---- 
     return(0); 
    } 
  //+------------------------------------------------------------------+ 

 bool signal_MACD() 
  { 
    bool signal_MACD = false; 
    double tmp = iMACD(Symbol(),TF,fast_ema,slow_ema,signal_period,PRICE_CLOSE,MODE_MAIN,0); 
    for(int i=1;i<=5;i++) 
    { 
       if(NormalizeDouble(iMACD(Symbol(),TF,fast_ema,slow_ema,signal_period,PRICE_CLOSE,MODE_MAIN,i)*tmp,4)<0.0) 
       { 
          signal_MACD = true; 
          break; 
       } 
    } 
  } 

 void AnalyzeSignal(bool signal) 
  { 
     total = OrdersTotal();
     double MACD = iMACD(Symbol(),TF,fast_ema,slow_ema,signal_period,PRICE_CLOSE,MODE_MAIN,0); 
     if(total < 1)
     {
     if(signal == true)
     {
         if(MACD > 0)
         {
            ticket = OrderSend(Symbol(),OP_BUY,lots,Ask,slip,Bid-TS*Point,Bid+TP*Point,"Покупаем",Magic,0,Green); 
            if(ticket>0) 
            { 
            OrderSelect(ticket,SELECT_BY_TICKET); 
            Print("открылись на покупку по цене:", OrderOpenPrice()); 
            } 
            else 
            { 
            Print("открыться не удалось по причине:", GetLastError()); 
            return(0); 
            } 
         }
         if(MACD < 0)
         {
             ticket = OrderSend(Symbol(),OP_SELL,lots,Bid,slip,Ask+TS*Point,Ask-TP*Point,"Продаем",Magic,0,Red); 
             if(ticket>0) 
             { 
             OrderSelect(ticket,SELECT_BY_TICKET); 
             Print("открылись на продажу по цене:", OrderOpenPrice()); 
             } 
             else 
             { 
             Print("открыться не удалось по причине:", GetLastError()); 
             return(0); 
             } 
         }
         else
            return(0);
     }
     }
  }
  
  
  
  
  
 
Help! Everyone has a MACD Sample EA I'm trying to add lot calculation to. After my changes it doesn't compile :( Help!
double Lots()
  {
   double Lots;
   Lots=AccountFreeMargin()/10000*5;
   Lots=MathMin(15,MathMax(0.1,Lots));
   if(Lots<0.1) 
     Lots=NormalizeDouble(Lots,2);
   else
     {
     if(Lots<1) Lots=NormalizeDouble(Lots,1);
     else       Lots=NormalizeDouble(Lots,0);
     }
     return(Lots);
  }
 

Hi

EA gives an error, if ((Bid-OrderOpenPrice(),Digits) >= -60) code 130, gives every new tick and really loads server...

if I change it to if ((pBid-NormalizeDouble(OrderOpenPrice(),Digits)) == -60) - doesn't work...

I need exactly >= and how to proceed?

Please help me figure it out.

Thanks in advance!!!

 

How can I programmatically calculate how many currency pairs are involved in a trade?

I tried to search for open orders. I ran the Expert Advisor on 3 currency pairs. I got different results on each one:

on one - 3 (correct), on the second - 2, on the third - 1.

I tried it on 2 currency pairs:

on one - 2 (correct), on the second - 1. If it wasn't for the pattern of decline, I would have thought I had made a mistake

int val() 
{
   int kp=1;
   string x1="0",x2="0", x3="0", x4="0", x5="0", x6="0", x7="0", x8="0", x9="0", x10="0", x11="0", x12="0", x13="0", x14="0",       x15="0",
          x16="0", x17="0", x18="0",  x19="0",  x20="0",  x21="0",  x22="0", x23="0",  x24="0";
   for (int i=OrdersTotal()-1; i>=0; i--)
   {
     if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
     if(OrderSymbol()==Symbol())   break;
      if(x9!="0" &&  x1!=OrderSymbol() && x2!=OrderSymbol() &&  x3!=OrderSymbol()  &&  x4!=OrderSymbol() &&  x5!=OrderSymbol()  &&  x6!=OrderSymbol()   &&  x7!=OrderSymbol()  &&  x8!=OrderSymbol()   &&  x9!=OrderSymbol() && x10=="0") {x10=OrderSymbol(); kp=11;}      
      if(x8!="0" &&  x1!=OrderSymbol() && x2!=OrderSymbol() &&  x3!=OrderSymbol()  &&  x4!=OrderSymbol() &&  x5!=OrderSymbol()  &&  x6!=OrderSymbol()   &&  x7!=OrderSymbol()  &&  x8!=OrderSymbol() && x9=="0") {x9=OrderSymbol(); kp=10;}      
      if(x7!="0" &&  x1!=OrderSymbol() && x2!=OrderSymbol() &&  x3!=OrderSymbol()  &&  x4!=OrderSymbol() &&  x5!=OrderSymbol()  &&  x6!=OrderSymbol()   &&  x7!=OrderSymbol() && x8=="0") {x8=OrderSymbol(); kp=9;}      
      if(x6!="0" &&  x1!=OrderSymbol() && x2!=OrderSymbol() &&  x3!=OrderSymbol()  &&  x4!=OrderSymbol() &&  x5!=OrderSymbol()  &&  x6!=OrderSymbol() && x7=="0") {x7=OrderSymbol(); kp=8;}      
      if(x5!="0" &&  x1!=OrderSymbol() && x2!=OrderSymbol() &&  x3!=OrderSymbol()  &&  x4!=OrderSymbol() &&  x5!=OrderSymbol() && x6=="0") {x6=OrderSymbol(); kp=7;}      
      if(x4!="0" &&  x1!=OrderSymbol() && x2!=OrderSymbol() &&  x3!=OrderSymbol()  &&  x4!=OrderSymbol() && x5=="0") {x5=OrderSymbol(); kp=6;}      
      if(x3!="0" &&  x1!=OrderSymbol() && x2!=OrderSymbol() &&  x3!=OrderSymbol() && x4=="0") {x4=OrderSymbol(); kp=5;}      
      if(x2!="0" &&  x1!=OrderSymbol() && x2!=OrderSymbol() && x3=="0") {x3=OrderSymbol(); kp=4;}      
      if(x1!="0" &&  x1!=OrderSymbol() && x2=="0") {x2=OrderSymbol(); kp=3;}      
      if(x1=="0") {x1=OrderSymbol(); kp=2;}
   }
  return(kp);
}
 
skyjet:
After my changes it won't compile :(

What does it say?
 
Figar0:

Well, what does it say?
12 errors, 12 warnings. I must be entering the lot calculation wrong?
 
forexnew:

How can I programmatically calculate how many currency pairs are involved in a trade?

I tried to search for open orders. I ran the Expert Advisor on 3 currency pairs. I got different results on each one:

on one - 3 (correct), on the second - 2, on the third - 1.

I tried it on 2 currency pairs:

on one - 2 (correct), on the second - 1. If it wasn't for the pattern of decline, I would have thought I had made a mistake


Or maybe just make a list of active instruments with the help of an EA. The approach is kind of complicated. There are simpler ways of doing things, aren't there?
 
skyjet:
12 errors, 12 warnings. I must be entering the lot calculation wrong?

There are no errors in the function itself, probably errors occur when trying to use it, but you don't show us that. Please post something that doesn't compile directly in a file and you won't need to guess.
Reason: