Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1457

 
ANDREY #:

Thank you very much for your valuable advice. If you don't mind, please send me a link to an Expert Advisor (not an indicator) that was on 4 and then became on 5 (if you can on the simplest), or the Expert Advisor itself in 4 and then the same in 5
I started to study. I realised that trading operations for a beginner is easiest to open in the trading class STrade and I even managed to open orders and deals with the help of this class
But as soon as I conditioned the opening of an order, orders stopped opening, please tell me what I did wrong. Here is the code that opened orders when there were no conditions.

I have not yet understood this point.... When orders BAY were opened, they were closed, as I understood, by counter orders CEL. And I don't understand where the code took the information about how many pips to close the orders, because I didn't specify the size of SL and TP anywhere and I didn't specify the function of closing orders at all. I suspect that this information is written in some place of some attached file, i.e. in some class or structure. If it is so, how to find this place to make changes in the parameters of the opened order?

Thanks again for your help

I can only give advice - I was born in the country of soviets...

Search for it - here's an option.

I myself still have not learnt all the nuances of trade operations - I ordered a class in freelance many years ago and use it with minor modifications.

 
Aleksey Vyazmikin #:

I can only give advice - I was born in the land of soviets....

You can search for it, that' s an option.

I myself still have not learnt all the nuances of trade operations - I ordered a class in freelance many years ago and use it with minor modifications.

Got it. Thanks for the valuable information

 
ANDREY #:

Thank you very much for your valuable advice. If you don't mind, please send me a link to an Expert Advisor (not an indicator) that was on 4, and then became on 5 (if you can on the simplest), or the EA itself in 4 and then the same in 5.

Here is the simplest one. It is called so. It has both MQL5 code and MQL4.

Simple advisor
Simple advisor
  • www.mql5.com
Советник на отложенных ордерах
 
Alexey Viktorov #:

Here's the simplest one. That's its name. It contains both MQL5 and MQL4 code.

Thanks for your help.

 
ANDREY #:

But as soon as I conditioned the opening of an order, the orders stopped opening, please tell me what I did wrong. Here is the code that opened orders when there were no conditions.

I have not yet understood this point.... When orders BAY were opened, they were closed, as I understood, by counter orders CEL. And I don't understand where the code took the information about how many pips to close the orders, because I didn't specify the size of SL and TP anywhere and I didn't specify the function of closing orders at all. I suspect that this information is written in some place of some attached file, i.e. in some class or structure. If it is so, how to find this place to make changes in the parameters of the opened order?

Thanks again for your help

You have declared the MqlDateTime structure, but have not initialised it, it is now either empty or rubbish.

This is how it will open buy positions on each tick from 10:00 hrs, for a minute. Then at 11:00 will start opening buy positions for one more minute.

//+------------------------------------------------------------------+
#include<Trade\Trade.mqh>
 CTrade  trade;
//+------------------------------------------------------------------+
void OnTick()
  {
   MqlDateTime time_now;
   TimeCurrent(time_now);
   if((time_now.hour == 10 || time_now.hour == 11) && time_now.min == 0)
      trade.Buy(0.1);
  }
//+------------------------------------------------------------------+
This code cannot close positions, there is nothing like that inside the CTrade class.
 
Aleksandr Slavskii #:

You declared the structure MqlDateTime , but did not initialise it, it is now either empty or rubbish.

This is how it will open buy positions on each tick from 10:00 hours, for a minute. Then at 11:00 will start opening more buy positions for one minute.

This code cannot close positions, there is nothing like that inside the CTrade class.

Thank you very much.... You've made me a lot more advanced in mastering the 5. You say that this code cannot close positions. But if you remove all conditions, then positions are opened and closed by counter orders CEL.... as I understand it. Then what code command is used to close orders? Where does the programme get the data for closing orders exactly after a certain number of points, or at the occurrence of some event? I don't even understand by what rule it closes them.

#include<Trade\Trade.mqh>
 CTrade  trade;

void OnTick()
{
trade.Buy(0.1);
}

I also noticed that SEL orders, which are used to close BAY orders, for some reason have a ticket number very far away from the ticket number of the BAY order they are closing. For example, the first BAY order has ticket 2, but the CEL order that closes it has a ticket not 3 (which would be logical) but 91779 for some reason.

And if you open only 1 order, everything becomes logical. Bai order has number 2, and closing CEL order has number 3.

int y;
#include<Trade\Trade.mqh>
 CTrade  trade;
//+------------------------------------------------------------------+
void OnTick()
  {
   MqlDateTime time_now;
   TimeCurrent(time_now);
   if(time_now.hour == 10&&y==0)
   {trade.Buy(0.1);y =1;}
      
  }


 
ANDREY #:

Thank you so much.... You've made me a lot of progress in mastering the 5. You say that this code cannot close positions. But if you remove all conditions, then positions are opened and closed by counter orders CEL.... as I understand it. Then what code command is used to close orders? Where does the programme get the data for closing orders exactly after a certain number of points, or at the occurrence of some event? I don't even understand by what rule it closes them.

I also noticed that SEL orders, which are used to close BAY orders, for some reason have a ticket number very far away from the ticket number of the BAY order they are closing. For example, the first BAY order has ticket 2, but the CEL order that closes it has a ticket not 3 (which would be logical) but 91779 for some reason.

And if you open only 1 order, everything becomes logical. Bai order has number 2, and closing CEL order has number 3.


Well, it is hard to understand what is going on there, but I think you open more positions than allowed by the broker on this instrument and the tester starts to close the extra ones.

Actually, it should not open these extra positions. But I can't explain what is happening with you in any other way.


I don't understand one position either. Why it closes at the end of the day. Perhaps your broker forbids to carry positions to the next day.

 
Aleksandr Slavskii #:

Well, it's hard to understand what's going on there, but I think you open positions more than allowed by the broker on this instrument and the tester starts closing the extra ones.

Actually, it should not open these extra positions. But I cannot explain what you have going on in any other way.


I don't understand one position either. Why it closes at the end of the day. Perhaps your broker does not allow you to carry positions to the next day.

Thank you. The explanation looks very logical. On a quad with exactly the same code and the same period, the same thing happens, only orders are not closed with a counter order. My broker is Alpari. After your explanations, it became clear why the numbers of closing counter orders differ so much from the orders they close. Because all closing orders are opened at the very end after all closing orders.

 

Good afternoon everyone!
I am trying to learn how to place orders in the five using the CTrade class, as it seemed to me that this is the fastest and easiest way to set them. To be more precise, I am trying to learn how to set the STOPLOSS parameter. In four the last bid price was stored in the predefined Bid, and in five as I understood the last bid price is not stored, but, if I'm not mistaken, as one of the options, is calculated in the Bid method of the CSymbolInfo class. But for this method to calculate the price Symbol must be previously selected by the Name method. How the Name method works I understand.In it you need to insert either the name of the symbol or NULL and it will return false or true.

But I can't understand how and where to combine the Name method and the Bid method , so that the Bid price would be stored in the variable c

In four orders were selected using the Select() function. But in five orders should be selected not orders but symbol..... I don't understand how to do it

I would be very grateful if you could write a fragment in my code to save the Bid price to the variable with, which I use in the SL parameter of the Btsu method of the CTrade class.

int y;
double c,d;
#include<Trade\Trade.mqh>        //класс
#include <Trade\SymbolInfo.mqh>  //класс 
CTrade  trad;                   //класс (создание объекта класса)
CSymbolInfo pris;
//+------------------------------------------------------------------+
void OnTick()
  {
   c=pris.Bid();//
   Print(" ---------------------CТОП------------------------------------------------------------  ",c);
   MqlDateTime t;                //структура (объявление структуры)
   TimeCurrent(t);               //структура (инициализация структуры)
   if(t.hour == 9&&y==0)
   {trad.Buy(0.1,NULL,0,c);y =1;}   //класс
      
  }
Документация по MQL5: Стандартная библиотека / Торговые классы / CSymbolInfo / Name
Документация по MQL5: Стандартная библиотека / Торговые классы / CSymbolInfo / Name
  • www.mql5.com
Name - CSymbolInfo - Торговые классы - Стандартная библиотека - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 

Help me understand. In the line ObjectMove(0, "LineAB", prevTime, prevPrice, newAx, newAy); it says wrong parameters count. Where is the error?