Questions from Beginners MQL4 MT4 MetaTrader 4 - page 236

 
s4sha45:

Hello all! Just started to learn how to write a simple trading robot from the examples of YouTube videos. I want to write a script to open the firstbuy order, and it must open if I have no other open orders, the script wrote this, but the order does not open, please advise where the error is!

<

void OnTick()

{

if(OP_SELL==0 && OP_BUY==0)

int ticket=OrderSend(Symbol(),OP_BUY,Lot1,Ask,Slippage,StopLoss,TakeProfit, "My order",MagicNumber,0,clrGreen);

>

You have written (verbatim in Russian):

If 1 equals 0 and 0 equals 0, then open a position.

 
Artyom Trishkin:

You have written (verbatim in Russian):

If 1 equals 0 and 0 equals 0, then open a position.

In the video the author wrote this line as if (b==0&& s==0) and it worked. and before that he didn't enter any variables b and s. maybe the version is old. if this is wrong, then how should the line that determines that I have no orders now look?
 
bool FindOrder(int eType, int eMagic, string eSymbol)
   {
   for(int i=OrdersTotal()-1; i>=0; i--)
      {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if(OrderCloseTime()>0) continue;
      if(OrderSymbol()!=eSymbol) continue;
      if(OrderMagicNumber()!=eMagic) continue;
      if(OrderType()!=eType) continue;
      return(true);
      }
   return(false);
   }
bool b=FindOrder(OP_BUY,Magic,Symbol());
if(b)
   {
   
   }
 
s4sha45:

Hello all! Just started to learn how to write a simple trading robot from the examples of YouTube videos. I want to write a script to open the firstbuy order, and it must open if I have no other open orders, the script wrote this, but the order does not open, please tell me where the error is!

<

void OnTick()

  {

  if (OrdersTotal()==0)   int ticket=OrderSend(Symbol(),OP_BUY,Lot1,Ask,Slippage,StopLoss,TakeProfit,"My order",MagicNumber,0,clrGreen);

  }

If you need to open an order when there are no buy, sell, stop or limit orders.

OrdersTotal()
Closed orders are not taken into account.
 
Александр:

If you need to open an order when there are no buy, sell, stop or limit orders.

Closed orders are not taken into account.
Thank you!
 

Good evening, I have a question: I need to compare market prices on every tick with prices from a certain csv file (7 columns), and the orders are grouped in series and the number of orders in each series may be arbitrary. I want to understand what would be faster: spending time on initialization to create an array with all data on each order, and then iterating over the array on a tick, or opening the file and copying everything into the cursor each time. I wonder what is the approximate time to access the file and array, how much time I'll gain. Thanks!

 
Karomos:

Good evening, I have a question: I need to compare market prices on every tick with prices from a certain csv file (7 columns), and the orders are grouped in series and the number of orders in each series may be arbitrary. I want to understand what would be faster: spending time on initialization to create an array with all data on each order, and then iterating over the array on a tick, or opening the file and copying everything into the cursor each time. I wonder what is the approximate time to access the file and array, how much time I'll gain. Thank you!

What you wrote is not very clear, but accessing memory is definitely faster than reading from a file.

 

Hello. Can you tell me if it's possible to call the EA parameter window PROGRAMMatically ?

The problem is that the parameters can only be initialized with constants and I want to first calculate them using a certain algorithm.

I have BUY_STOP and SELL_STOP levels in my EA parameters. Actually, the Expert Advisor can calculate these levels by itself in most cases, I just need to check their correctness.

Therefore, I want my EA to calculate these levels on startup and put them in the parameters and display the parameters window. If they are correct, I press OK and the EA continues its normal operation. If my Expert Advisor has incorrectly identified levels, I correct them to the correct values. If it is impossible to display the parameter window programmatically, then advise whether we can somehow initialize the parameters (I have written a function for their calculation) BEFORE displaying the EA's parameter window.

 

Dear experts!

Can you tell me how to find a warrant?

The situation is as follows:

- my EA is opening 2 orders at the same time. SL is the same, TP is not set.

- And then, under certain circumstances, my EA will close the first order and I have to correct SL in the second one.

The question is how to find the second order?

The problem is that there may be several open pairs. But the time of opening is different for every pair.


As I see it, there may be many variants. How to make it easier and more correct?

I don't want to write the ticket in the comments because the broker may delete it.

Actually, the second order can be given another magik. But this does not solve the problem.

We can search by time or by opening price. But where is the guarantee that the second order will be opened at the same price?

What do you advise?

 

The indicator from MT5 draws a line in two colours.

The values of the line are in the same buffer.

Is there any way to identify the colour of the line when requesting values from the indicator?

Reason: