Questions from Beginners MQL5 MT5 MetaTrader 5 - page 586

 
Alexey Kozitsyn:

Use a variable of enumeration type ENUM_TIMEFRAMES.

Thank you!
 
Alexey Kozitsyn:

Use a variable of enumeration type ENUM_TIMEFRAMES.

Can I leave only a few of all primes in the enumeration? So that when selecting in the parameter settings I only see two for example.
 
barudkinarseniy:
Can I leave only a few of all the primes in the list? So, when selecting parameters in settings, I will see only two, for example.

You can, but you have to write your own enumeration

enum ENUM_ORDER_TYPE
{
   Buy  = ORDER_TYPE_BUY,
   Sell = ORDER_TYPE_SELL
};

input ENUM_ORDER_TYPE typeOrder; // Выбери тип ордера

For mql4, instead of ORDER_TYPE_BUY, we should write OP_BUY, respectively, for Sell

 
Alexey Viktorov:

You can, but you have to write your own enumeration

For mql4, instead of ORDER_TYPE_BUY you should write OP_BUY, respectively, for Sell

I got it, thank you))
 
OlegKirill:

Please advise how to fix this error

Modification of order #1506271459 buy 0.11 EURJPY at 122.824 sl: 0.000 tp: 0.000 -> sl: 0.000 tp: 122.843 failed [Invalid S/L or T/P]


 
Karputov Vladimir:
OlegKirill:

Please advise how to fix this error

Request of order #1506271459 buy 0.11 EURJPY at 122.824 sl: 0.000 tp: 0.000 -> sl: 0.000 tp: 122.843 failed [Invalid S/L or T/P]


It depends on what it is, if the stop is set less than the minimum and the terminal returns zero stop, then it is difficult. If the problem is with the price step, I use this function.

double normalize(string symbol,double value)
  {
   double ts=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE);
   if(ts==0)return(value);
   return(NormalizeDouble(value/ts,0)*ts);
  }

example of use when opening a position

   if(type==ORDER_TYPE_BUY)
     {
      double ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
      if(NormalizeDouble(normalize(_Symbol,ask),digits)!=NormalizeDouble(ask,digits))return;
      trade.Buy(volume,_Symbol,0,0,0,CommentOrder);
     }

example of use when modifying

         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
           {
            sl=NormalizeDouble(normalize(symbol,bid-sl*point),digits);
            tp=PositionGetDouble(POSITION_TP);
            //Print(__FUNCTION__,": sl = ",sl," tp = ",tp);
            if(sl>0)trade.PositionModify(tiket,sl,tp);
           }

..

 
Thanks, I'll give it a try.
 
About mql5. Why, unlike mql4, TimeLocal() changes only with a new tick / new chart shift / change of chart scale, but not continuously? The same with GetTickCount andGetMicrosecondCount. Is there some way to make the TimeLocal "clock" move uniformly and continuously without "ticks"?
 
Dream11:

Good afternoon, here's the problem... there's a trailing stop function...

   double tr=0,MATrall=0,op=0,sl=0,
   ask   = NormalizeDouble(Ask,Digits()),
   bid   = NormalizeDouble(Bid,Digits());
   tr = NormalizeDouble(TrailingStop*Point(),Digits());
   MATrall = iMA(NULL,0,13,0,MODE_SMMA,PRICE_MEDIAN,1);
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS)==true)
        {
         if(OrderSymbol()==Symbol())
           {
             if(OrderMagicNumber()==Magic)
              {
              op    = NormalizeDouble(OrderOpenPrice(),Digits());
              sl    = NormalizeDouble(OrderStopLoss(),Digits());
                 if(OrderType()==OP_BUY)
                 {
                 if((bid-op)>tr)
                 if((bid-sl)>tr)
                 if ((bid-tr)>MATrall)
                 if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(MATrall,Digits()),OrderTakeProfit(),0,clrRed)==false)
                 printf("ERROR BUY Modifi");
                 }
                  if(OrderType()==OP_SELL)
                 {
                 if((op-ask)>tr)
                 if((sl-ask)>tr || sl==0)
                 if((ask+tr)<MATrall)
                 if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(MATrall,Digits()),OrderTakeProfit(),0,clrRed)==false)
                 printf("ERROR SELL Modifi");
                 }
              }
           }
        }
     }

How to change it to trawl an unlimited number of orders instead of one ...


 
loleg1991:
About mql5. Why, unlike mql4, TimeLocal() changes only with a new tick / new chart shift / change of chart scale, but not continuously? The same with GetTickCount andGetMicrosecondCount. Maybe there is a way to make the TimeLocal "clock" move uniformly and continuously without "ticks"?
Isn't it possible to do it with OnTimer()?