Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 542

 
Artyom Trishkin:

From this time[i] an hour should be extracted.

Still prints the time 10:05:00 and 22:10:00 and other outside the permitted time.

It should not print from 17:00 to 11:00, but it does.

 for(int i=limit-2; i>0; i--) 
     {
    if(TimeHour(time[i])>=17&&TimeHour(time[i])<=11)continue;
      if(i%2==0) 
        {
         if(open[i]<close[i] && open[i+1]>close[i+1]) 
           {
            k1++;
            if(k1>max) {max=k1; dat_max=time[i];}
            if(k1>=4)Print("Num: ",k1,"dat_max ",time[i]);
            SetText("Obj_"+(string)time[i],(string)k1,time[i],high[i],Arr);
           }
         else k1=0;
         
           } else {
         if(open[i]<close[i] && open[i+1]>close[i+1]) 
           {
            k2++;
            if(k2>max){ max=k2; dat_max=time[i];}
            if(k2>=4)Print("Num: ",k2,"dat_max ",time[i]);
            SetText("Obj_"+(string)time[i],(string)k2,time[i],high[i],Arr);
           }
         else k2=0;
         
        }
      
     }

   Comment("Max: ",max,"dat_max ",dat_max," rates_total ",rates_total);

 
if(TimeHour(time[i])>=17 || TimeHour(time[i])<=11)continue;
 
Taras Slobodyanik:

Thank you.

 
k_chens:

Good afternoon! Please help! I'm trying to write a lot count control. If my account makes +10% profit, then the lot is doubled. If +20%, then lot*4. If in my account decreases, then respectively decreases the lot size. I do not understand how to make Lots_New take a new value at each new trade.

This is a far from trivial task for a person who is just beginning to learn programming. After all, in order to solve it, you have to think of a mechanism for storing the next balance value. Moreover, we need to figure out where to store this value. Variables in programs are not suitable for this purpose. For example, you may use global variables of the terminal or writing them to a file. Everything depends on where and how you plan to use the program.

The most universal solution (if the program is planned to be used on different computers without the possibility to transfer the data between the copies of the program) is to scan the account history to calculate the profit/loss, obtained as a result of the program work. But then there is also the question of choosing a reference point (where to get the balance value from which to count up).

 
Hello, can you please explain the lines for selecting a medgic :

Extern bool hand orders =true ;
Extern int Magic_Number =777;
//first line
((OrderMagicNumber()==Magic_Number && hand_orders==false) || (OrderMagicNumber()==0 && hand_orders==true))

//second line
(OrderMagicNumber()==Magic_Number || (OrderMagicNumber()==0 && hand_orders==true)))


What kind of medgic values are they missing? Please write
 
Tigerfreerun:
Hello, please explain the lines for selecting a medjic :

Extern bool hand orders =true ;
Extern int Magic_Number =777;
//first line
((OrderMagicNumber()==Magic_Number && hand_orders==false) || (OrderMagicNumber()==0 && hand_orders==true))

//second line
(OrderMagicNumber()==Magic_Number || (OrderMagicNumber()==0 && hand_orders==true)))


What kind of medgic values are they missing? Please write

replace in your expressions - && with "AND AT THE SAME TIME", and replace || with "OR".

you should be able to read that and see how it works.


the first line will work with either magic =777 (when hand_orders=false) or magic = 0 (when hand_orders=true)

the second line ALWAYS works with majic=777, and if hand_orders=true, it works ADDITIONALLY with majic=0

 

How do I calculate, in one function, the profit in pips for two instruments?

Spin

double Punkts_B(string Sy_1="",string Sy_2="",int _Mag=-1)
  {
   double xxx=0;
   bool bw;
   for(int t=0;t<=OrdersTotal();t++)
     {
      bw=OrderSelect(t,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Sy_1 || OrderSymbol()==Sy_2
         && OrderMagicNumber()==_Mag
         && (OrderType()==OP_BUY || OrderType()==OP_SELL))
         xxx=OrderClosePrice()-OrderOpenPrice();
      RefreshRates();
     }
   return(xxx);
  }
 
PolarSeaman:

How do I calculate, in one function, the profit in pips for two instruments?

Rolling

int Punkts_B(string Sy_1="",string Sy_2="",int _Mag=-1)
  {
   int xxx = 0;
   double tickValue_1 = SymbolInfoDouble(Sy_1, SYMBOL_TRADE_TICK_VALUE),
          tickValue_2 = SymbolInfoDouble(Sy_2, SYMBOL_TRADE_TICK_VALUE);
   for(int t=0;t<OrdersTotal();t++)
     {
      if( !OrderSelect(t,SELECT_BY_POS,MODE_TRADES) )  continue;
      if( OrderSymbol()!=Sy_1 && OrderSymbol()!=Sy_2 ) continue;
      if( OrderMagicNumber()!=_Mag )                   continue;
      if( OrderType()!=OP_BUY && OrderType()!=OP_SELL) continue;
      xxx+=(int)((OrderProfit()+OrderSwap()+OrderCommission())/(OrderSymbol()==Sy_1 ? tickValue_1 : tickValue_2));
     }
   return(xxx);
  }
 
Konstantin Nikitin:
points of two different instruments cannot be stacked.
 
Maxim Kuznetsov:
points of two different instruments cannot be added up.

He asked, in points, here he is in points. Let him think =)

Reason: