Questions from Beginners MQL5 MT5 MetaTrader 5 - page 790

 
Vladimir Karputov:

Found the definition of the clause. Figured out what this beast is. Too bad I didn't find the definition in mql5.

A point in economics is a minimal change in an indicator when no smaller changes are envisaged for that indicator. One point corresponds to a single change in the most recent published figure of the indicator.

Thanks for your help.

 
pivomoe:

A point in the economy is the minimum change in an indicator when no smaller changes are foreseen for that indicator. One point corresponds to a single change in the most recent published figure for an indicator.

Even simpler: Point = 10^(-Digits). And it is clear that the price of opening a position, for example, may not equal a whole number of points.

 
fxsaber:

And it is understandable that the price of opening a position, for example, may not equal a whole number of pips.

How is it? Can I give you an example?

 
pivomoe:

How does it work ? Can you give an example ?

On the netting do BUY 1 lot and, when the Ask price changes, BUY 6 lots.

#include <MT4Orders.mqh>

#define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

void OnInit()
{
  OrderSend(_Symbol, OP_BUY, 1, Ask, 100, 0, 0);
  Sleep(1 e4);
  OrderSend(_Symbol, OP_BUY, 6, Ask, 100, 0, 0);

  if (PositionSelect(_Symbol))
    Print(PositionGetDouble(POSITION_PRICE_OPEN));
}
 
fxsaber:

On the netting, BUY 1 lot and, when the Ask price changes, BUY 6 lots.

Interesting information.
 

Please help with the iHighest function from MT4 - I am interested in a question for an EA, how to do it the right way?

I understand that you need to copy the values to an array, but it turns out that to determine the size of the array you need to calculate the number of bars...

I have a task to find the maximum bar when I know two dates.

Can you tell me how to calculate the number of bars in a given time frame?

 
Aleksey Vyazmikin:

Please help with the iHighest function from MT4 - I am interested in a question for an EA, how to do it the right way?

I understand that you need to copy the values to an array, but it turns out that to determine the size of the array you need to calculate the number of bars...

I have a task to find the maximum bar when I know two dates.

Can you tell me how to calculate the number of bars in a given time frame?

You need to use the 3rd parameter

Then, after forming the array, find the maximum with theArrayMaximum function

Документация по MQL5: Доступ к таймсериям и индикаторам / CopyHigh
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyHigh
  • www.mql5.com
Функция получает в массив high_array исторические данные максимальных цен баров для указанной пары символ-период в указанном количестве. Необходимо отметить, что отсчет элементов от стартовой позиции ведется от настоящего к прошлому, то есть стартовая позиция, равная 0, означает текущий бар. При копировании заранее неизвестного количества...
 
Vitaly Muzichenko:

You need to use the 3rd parameter

Further, after formation of an array to find the maximum with functionArrayMaximum


This is understandable, but without knowing the number of bars I cannot use theArrayMaximum function because I don't know the size of the array - you can just set the maximum, but I want to use the right solution.

 

I did it this way:

MqlDateTime strDt;  
datetime         StartDt=TimeTradeServer();
datetime         StopDt=TimeTradeServer();
double          arrTimeD[];
TimeToStruct(StartDt,strDt);
   strDt.hour=0;
   strDt.min=0;
   strDt.sec=0;
StartDt=StructToTime(strDt);   
int BarsGo=iBarShift(_Symbol,0,StartDt,false); //Узнаем, индекс бара с начала временного периода (открытия дня)
ArrayFree(arrTimeD);
ArrayResize(arrTimeD,BarsGo);
CopyHigh(_Symbol,_Period,StartDt,StopDt,arrTimeD);
double Max=arrTimeD[ArrayMaximum(arrTimeD,0,BarsGo)];
Print("StartDt=",TimeToString(StartDt,TIME_DATE|TIME_MINUTES)," Max=",Max," BarsGo=",BarsGo);

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int iBarShift(string symbol,int tf,datetime time,bool exact=false)
  {
   if(time<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   datetime Arr[],time1;
   CopyTime(symbol,timeframe,0,1,Arr);
   time1=Arr[0];
   if(CopyTime(symbol,timeframe,time,time1,Arr)>0)
     {
      if(ArraySize(Arr)>2) return(ArraySize(Arr)-1);
      if(time<time1) return(1);
      else return(0);
     }
   else return(-1);
  }

But I'm not sure this is the best option.

 
//+------------------------------------------------------------------+
//|                                                          max.mq5 |
//|                                                   Copyright 2017 |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_plots 0
#property indicator_chart_window

double high_array[];
int CountBars;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
  datetime start_time = D'2017.11.03 04:00', 
           stop_time  = D'2017.11.03 12:00';
   
  if(CopyHigh(Symbol(),PERIOD_CURRENT,start_time,stop_time,high_array) < 0) return(0);
  
  CountBars = Bars(Symbol(),PERIOD_CURRENT,start_time,stop_time);
  
   Print( "high_array=",high_array[ArrayMaximum(high_array)],", CountBars=",CountBars ); // максимум во временном диапазоне, и количество баров
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Reason: