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

 
Galim_V:

The task is to find the bar with the minimum closure

for(int x=0; x<=xBars -1; x++)

{

counter++;

// Print(Close[x],",",counter);

int h = ArrayMinimum(Close[x]);

if(counter > 20) break;

}

Compiler swears at Close

Write the closing prices in a separate array and then outside the ArrauMinimum chick
 
Alekseu Fedotov:
Write the closing prices in a separate array and then outside the ArrauMinimum chick
Thank you!
 
Galim_V:

The task is to find the bar with the minimum close

there are iHighest and iLowest functions (now also in MT5)

 
Taras Slobodyanik:

there are iHighest and iLowest functions (now also in MT5)

Thank you!
 
Galim_V:

The task is to find the bar with the minimum closure

for(int x=0; x<=xBars -1; x++)

{

counter++;

// Print(Close[x],",",counter);

int h = ArrayMinimum(Close[x]);

if(counter > 20) break;

}

The compiler swears at Close

The task of searching for the minimum/maximum price in MQL4 is solved by one line:

double fMinClose = iClose(NULL, 0, iLowest(NULL, 0, MODE_CLOSE, <сколько баров>, <начинать с бара>));
 
Taras Slobodyanik:

you can, but it won't be exactly a timer.

Thank you.

How do I calculate the lot volume in increments? If deposit =1000, lot = 0.1, deposit became 2000 lot = 0.2. That is, if the deposit is 1500 or 1700, the lot is not incremented.

 
PolarSeaman:

Thank you.

How do I calculate the lot volume in increments? If deposit =1000, lot = 0.1, deposit became 2000 lot = 0.2. That is, if the deposit is 1500 or 1700, the lot does not increase.

double percentLot = 0.01,
       lot = NormalizeDouble(MathFloor(AccountInfoDouble(ACCOUNT_BALANCE)*percentLot/10)/10, 1);

Somehow...

 
Konstantin Nikitin:

Like this...

No, no, with a deposit of 1100, the lot will be 0.11, and I need the lot not to increase up to 2000. How do I set the step =1000 in the settings?

 
Good afternoon, could you please tell me if it is possible to add coordinates to the indexer to the mouse if you can, please email me at ereminmikola@yandex.ru
 

Hello programmers. Could you give me a hint on how to correctly approach the following condition:

1. The Expert Advisor opens 2 market orders (buy and sell) with the same lot specified in the settings. - The order is executed without any problems

The next one presents a problem, the price can move both to the SELL direction and to the BUY direction. How can we arrange the code so that when n points have been passed, the Expert Advisor would scan the profitability of those two deals in LIVE and close the order which has a negative balance after n points? If you have any other ideas how to do this, please advise.

I give you the code - draft, only the first point is executed, and 2 trades are opened with TP and SL

2. When the price reaches the specified amount of points, then I close order with a minus balance and open 2 more orders (buy and sell) with the same lot,

Stops are set at the opening price of the first order, i.e. if the trend reverses, all 3 orders should close simultaneously.


extern int    _ms = 1000;  
extern double _lots = 0.01;
extern double _TP = 80;
extern double _SL = 35;

int _mn;
double pt;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  { 
   pt = Point;
   if (Digits==3||Digits==5) {pt*=10;} else pt = Point;
   _mn = MagicNumberGenerator(_ms);
   Print("The magic number is ",_mn);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
    if (IsNewCandle())
    {
      if (TotalOpenOrders(_mn)==0)
      {
        EnterTrade(OP_BUY);
        EnterTrade(OP_SELL);
      }
    }   
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|   Открытие первых позиций                                        |
//+------------------------------------------------------------------+
void EnterTrade(int type)
{
   double price = 0; double sl = 0; double tp = 0; double lot = _lots;
   
   if      (type == OP_BUY)  price = Ask;
   else if (type == OP_SELL) price = Bid;
   
   int err = 0;
   int ticket = OrderSend(_Symbol, type, lot, price, 30, 0, 0, NULL, _mn, 0, clrGreen);
   if (ticket == -1)
   {
     err = GetLastError();
     Print("Could not place the order due to error ",err," ",ErrorDescription(err));
     if (err == ERR_TRADE_NOT_ALLOWED) Alert("You need to enable you autotrade button");
   }
   else 
   {
     if(!OrderSelect(ticket,SELECT_BY_TICKET))
     {
       err = GetLastError();
       Print("Could not select the order due to error ",err," ",ErrorDescription(err));
     }
     else 
     {
       if (OrderType()==OP_SELL)
       {
         sl = OrderOpenPrice()+(_SL*pt);
         if (_SL==0) sl = 0; 
         tp = OrderOpenPrice()-(_TP*pt);
       }  
       else if (OrderType()==OP_BUY)
       {
         sl = OrderOpenPrice()-(_SL*pt);
         if (_SL==0) sl = 0; 
         tp = OrderOpenPrice()+(_TP*pt);
       }
       if(!OrderModify(ticket, OrderOpenPrice(), sl, tp, 0, clrNONE))
       err = GetLastError();
       Print("Could not modify the order due to error ",err," ",ErrorDescription(err));
     }
   }
}
Reason: