Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1465

 

const string name="VLine,VLine2,VLine3", // line name

I made the line name unique. In input too. Doesn't help.

 
Alexey Belyakov #:

const string name="VLine,VLine2,VLine3", // line name

I made the line name unique. In input too. Doesn't help.

datetime time1 = D'2021.11.15 00:00:00';
datetime time2 = D'2022.11.15 00:00:00';
datetime time3 = D'2023.11.15 00:00:00';
// в этом случае так делаем
VLineCreate(0, "InpName1", 0, time1, InpColor, InpStyle, InpWidth, InpBack, InpSelection, InpHidden);
VLineCreate(0, "InpName2", 0, time2, InpColor, InpStyle, InpWidth, InpBack, InpSelection, InpHidden);
VLineCreate(0, "InpName3", 0, time3, InpColor, InpStyle, InpWidth, InpBack, InpSelection, InpHidden);

You made the name somewhere in the wrong place, and not like that).

 
Alexey Belyakov #:

const string name="VLine,VLine2,VLine3", // line name

I made the line name unique. In input too. Doesn't help.

Here, run without input parameters, copy it directly like this and maybe it will become clearer.

//+------------------------------------------------------------------+
//| Создает вертикальную линию                                       |
//+------------------------------------------------------------------+
bool VLineCreate(const long            chart_ID = 0,      // ID графика
                 const string          name = "VLine",    // имя линии
                 const int             sub_window = 0,    // номер подокна
                 datetime              time = 0,          // время линии
                 const color           clr = clrRed,      // цвет линии
                 const ENUM_LINE_STYLE style = STYLE_SOLID, // стиль линии
                 const int             width = 1,         // толщина линии
                 const bool            back = false,      // на заднем плане
                 const bool            selection = true,  // выделить для перемещений
                 const bool            hidden = true)     // скрыт в списке объектов

  {
   ObjectCreate(chart_ID, name, OBJ_VLINE, sub_window, time, 0);
//--- установим цвет линии
   ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- установим стиль отображения линии
   ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style);
//--- установим толщину линии
   ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, width);
//--- отобразим на переднем (false) или заднем (true) плане
   ObjectSetInteger(chart_ID, name, OBJPROP_BACK, back);
//--- включим (true) или отключим (false) режим перемещения линии мышью
//--- при создании графического объекта функцией ObjectCreate, по умолчанию объект
//--- нельзя выделить и перемещать. Внутри же этого метода параметр selection
//--- по умолчанию равен true, что позволяет выделять и перемещать этот объект
   ObjectSetInteger(chart_ID, name, OBJPROP_SELECTABLE, selection);
   ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection);

   return(true);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   datetime time1 = D'2023.06.26 10:00:00';
   datetime time2 = D'2023.06.26 11:00:00';
   datetime time3 = D'2023.06.26 12:00:00';
//--- создадим вертикальную линию
   VLineCreate(0, "Name1", 0, time1, clrBlue, STYLE_DASHDOTDOT);
   VLineCreate(0, "Name2", 0, time2, clrGreen, STYLE_SOLID, 5);
   VLineCreate(0, "Name3", 0, time3);
  }
//+------------------------------------------------------------------+
 
Aleksandr Slavskii #:

Here, run it without input parameters, copy it directly like this and maybe it will become clearer.


Thank you very much! Just what I need!

 

Here are the Buy/Sell functions in the CTrade trading class

I specify a price in them, but the position is still opened by Ask/Bid.

What kind of price can I specify here?

 
Alexey Belyakov #:


Thank you very much! Just what I need!

unique name)

string  var1=TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
     string NameLine="VLine_" +  "_"+var1;
 
deerhunter22 CTrade trading class

I specify a price in them, but the position is still opened by Ask/Bid.

What kind of price can I specify here?

Pay attention to other methods

   //--- additions methods
   bool              Buy(const double volume,const string symbol=NULL,double price=0.0,const double sl=0.0,const double tp=0.0,const string comment="");
   bool              Sell(const double volume,const string symbol=NULL,double price=0.0,const double sl=0.0,const double tp=0.0,const string comment="");
   bool              BuyLimit(const double volume,const double price,const string symbol=NULL,const double sl=0.0,const double tp=0.0,
                              const ENUM_ORDER_TYPE_TIME type_time=ORDER_TIME_GTC,const datetime expiration=0,const string comment="");
   bool              BuyStop(const double volume,const double price,const string symbol=NULL,const double sl=0.0,const double tp=0.0,
                             const ENUM_ORDER_TYPE_TIME type_time=ORDER_TIME_GTC,const datetime expiration=0,const string comment="");
   bool              SellLimit(const double volume,const double price,const string symbol=NULL,const double sl=0.0,const double tp=0.0,
                               const ENUM_ORDER_TYPE_TIME type_time=ORDER_TIME_GTC,const datetime expiration=0,const string comment="");
   bool              SellStop(const double volume,const double price,const string symbol=NULL,const double sl=0.0,const double tp=0.0,
                              const ENUM_ORDER_TYPE_TIME type_time=ORDER_TIME_GTC,const datetime expiration=0,const string comment="");
 
Alexey Viktorov #:

Pay attention to other methods

Yes, I know about them, of course, but I need for other things.... Anyway, the point is this. I recently started trading on binance and wanted to test it. There is also a kitchen broker with a lot of cryptocurrencies, but the spread interferes. And so the quotes match pretty well with binance quotes, especially if you consider the price (bid+ask)/2.

Here I wanted to maximise the match, although of course it will be possible to neglect these discrepancies.

 
deerhunter22 #:

Yeah, I know about them, but that's not what I'm after. Anyway, the point is this. I recently started trading on binance and wanted to test it. There is also a kitchen broker with a lot of cryptocurrencies, but the spread interferes. And so the quotes match pretty well with those of binance, especially if you consider the price (bid+ask)/2.

Here I wanted to maximise the match, although of course it will be possible to neglect these discrepancies.

Perhaps you can look into creating your own chart. MQL5 allows it.

 

Good afternoon. When writing an Expert Advisor on Mql5 I encountered a problem. There is an array with values of candlesticks opening for the year. On each candlestick of this array I need to create an array of n-candles, say 30, to check the highs and lows. Something like a Zigzag indicator.

I wrote this code, which gives an error: "array out of range" or the values of maximum and minimum in the whole array, but not in the required 30-candle period.

for(int i=0; i<ArraySize(opens); i++)
  {
    if(i+30<=ArraySize(opens))
      {
       double maximum=0;
       double minimum=9;
       for(int j=0; j<30; j++)
        {
         maximum = ArrayMaximum(opens, i, i+j);
         minimum = ArrayMaximum(opens, i, i+j);
        }
     }
  }

Perhaps I need to create another array to check in the ArrayMaximum() and ArrayMinimum() functions, but I'm confused with nested loops and array size.

Please, give me a hint.

Reason: