[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 627

 
chief2000:

Replaced "return(0)" with "return", but this did not solve the "problem" - after optimization you still see the same 0-zero results. Is there any solution not to output zeros during optimization?

Thanks!


I don't know if you do or not, I'll tell you just in case, check the "Ignore useless results" checkbox.

The minus results (by balance) will be eliminated, not sure about the zeros, but give it a try.

 
I wonder how to get a 'random' number within, say, 15 +/- 7 on each new tick, so that it is randomly generated within the given limits ...
 

Like this:

int random(){
   MathSrand(TimeLocal());
   while(true){
      int x = MathRand();
      if(x >= 8 && x <= 22)return(x);
   }
}

:)

 
ToLik_SRGV:

Like this:

:)

Thank you!!! ;)
 
ToLik_SRGV:

I don't know if you know this or not, but just in case, check the "Skip useless results" box.

The negative results (by balance) will be filtered out, I'm not sure about the null ones, but you should try it.

The thing is, I want to see null results - in the early stages of optimization I often have to select the best ones among null results (and in later stages it's useful to look through them and compare). Zeros get in the way because these very results don't make any sense and there are too many of them - the size of stored files get bigger and visually impede viewing results. Thanks anyway!

 
granit77:

If you mean the external variables MA_Fast_Period and MA_Slow_Period, there is a solution. If the variables are calculated in the Expert Advisor, then there is nothing to be done.

It's late, my head isn't working anymore... but it sounds like a very good idea! Thank you!

 
artmedia70:
I wonder how to get a "random" number within, say, 15 +/- 7 on each new tick, so that it is randomly generated within the given limits ...
http://prolang.ru/index.php/cpp/cpptheory/3-clang-random.html

To obtain random real numbers with uniform distribution in interval [a,b], use formula

x = rand()*(b-a)/RAND_MAX + a;

For mql, in the description of MathRand() function, it is written: The function returns a pseudorandom integer in the range from 0 to 32767

i.e. for mql RAND_MAX = 32767

 

I started to learn mq4, and immediately encountered some obscure moments.

I tried my hand at it, so to speak. I wrote a simple Expert Advisor on Ma. But it does not want to trade even on history. It produces no errors.

Can you tell me where I screwed up?

int start()
  {
   //---проверим возможность входа в позицию
   bool flagchange = false;
   int Slippage = 3;
   int i = 0;
   double lt = getLots() ; // минимальный лот
   RefreshRates();
   int total = OrdersTotal();   
   int ticket = -1;
   for (;;)
      {
      int flag= GetEma();
       if (flagchange != flag) // проверим, сигнал ема изменился? если да, то можно открыть или закрыть поз.
       flagchange = true;      // изменился!
       else flagchange = false;
        if (flagchange == True)
        {       
           int Total=OrdersTotal(); //проверим есть открытые позиции?
           if(Total>0)
  {
     for(i=Total-1; i>=0; i--) 
     {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) // если а то закрываем
        {
           if(OrderType()==OP_BUY || OrderType()==OP_SELL) // Только Buy и Sell
           {
              if(OrderType()==OP_BUY) 
              bool Result=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE);
              else
              Result=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE);
              if(Result!=true) 
              { 
              Print("LastError = ",GetLastError()); 
              }
           }
        }
        else // если открытых нет, то окрываем.
         if (flag ==1) OrderSend(Symbol(),OP_BUY,lt,Ask,Slippage,Bid - sl * Point,0,"Buy",888,0,Blue);
         else OrderSend(Symbol(),OP_SELL,lt,Bid,Slippage,Ask + sl * Point,0,"Seel",888,0,Red);
        {
        }
     }
  }                                             
      }
 }      
//----
   return(0);
  }
      //////////////////////////////////////////////////////
  int GetEma() {
  //----Получим значение EMA1
      int ma1= iMA(Symbol(),PERIOD_H1,ema1,0,1,6,0);
  //----Получим значение EMA2   
      int ma2= iMA("",PERIOD_H1,ema2,0,1,6,0); 
      if (ma1>ma2) return (1);
      else return (0);}
   /////////////////////////////////////////////////////  
         // посчитаем разтер лота
   double getLots() 
        {
                double minlot = MarketInfo(Symbol(), MODE_MINLOT);
                 int round = MathAbs(MathLog(minlot) / MathLog(10.0)) + 0.5;
                 double lot = minlot;
//---- select lot size
                 lot = NormalizeDouble(AccountFreeMargin() * Risk / 1000.0, round);
                 if (AccountFreeMargin() < lot * MarketInfo(Symbol(), MODE_MARGINREQUIRED)) 
                        {
                                lot = NormalizeDouble(AccountFreeMargin() / MarketInfo(Symbol(), MODE_MARGINREQUIRED), round);
                        }
                 if(lot < minlot) lot = minlot;
                 double maxlot = MarketInfo(Symbol(), MODE_MAXLOT);
                 if(lot > maxlot) lot = maxlot;
//---- return lot size
   return(lot);
        } 
 


bool flagchange = false;
int Slippage = 3;
int i = 0;
double lt = getLots() ; // minimum lot
RefreshRates();
int total = OrdersTotal();
int ticket = -1;
for (;;)
{
int flag= GetEma();
if (flagchange != flag)

the for statement without the parameter? - the point? eternal loops are not written that way, and secondly, there are global variables for the EA - not for the terminal, they are described at the very beginning of the code before all functions and the start() function including, as you have written - at every tick you call the start() function, flagchange = false; and then you try to compare this flag with the previous state, but its state will always be false

If you are just starting to try your forces - take any ready-made Expert Advisor from Kodobase and change the conditions for entering the market to your own - it will be faster.


 
MarkTrade:

I started to learn mq4, and immediately encountered some obscure moments.

I tried my hand at it, so to speak. I wrote a simple Expert Advisor on Ma. But it does not want to trade even on history. It doesn't show any errors.

Can you tell me where I screwed up?


What is the purpose of the EA looping?

for (;;) {


}
Reason: