What's wrong with that? - page 5

 
sss2019:


Wow thank you, I think this method is more versatile.

By the way, how to declare in EA that the order has been opened, OrderSend as I understand sends only the order ticket. Maybe, this can be implemented using OrderSelect?


Before the initialization block, let's declare a variable which will carry the order ticket. For example:

int Ticket;

In the start () function, before calling OrderSend(), we write:

Ticket=-1;

Since the OrderSend() function returns a ticket of the order, then we check if the Ticket variable is greater than zero, then the order has been placed. Otherwise, we have no order - see OrderSend reference - it is written there that if the order cannot be set, the function will return the value = (-1), not a tick. On the next tick, because the variable is first initialised with value = -1 and no order is set, the variable will remain negative until the end of the code. And this continues until a new order is placed.

 
Could you please show me an example, because I'm having a hard time.
 
sss2019:
Could you please show me an example, because I'm having a hard time.
#property copyright ""
#property link      ""

int Ticket;
//+------------------------------------------------------------------+
//|                  Блок инициализации                              |
//+------------------------------------------------------------------+
int init(){
        return(0);
}
//+------------------------------------------------------------------+
//|                  Блок деинициализации                            |
//+------------------------------------------------------------------+
int deinit(){
        return(0);
}
//+------------------------------------------------------------------+
//|                  Старт работы советника                          |
//+------------------------------------------------------------------+
int start(){
        Ticket=(-1);
        
        if(если есть торговый сигнал){
                Ticket=OrderSend();
        }
        if(Ticket>0){// тикет более нуля - ордер встал
                // выполняем какие-то действия
        }
        return(0);
}
//+------------------------------------------------------------------+
//|                  Пользовательские подпрограммы                   |
//+------------------------------------------------------------------+
 

Why is Ticket=(-1); in brackets?

What kind of nonsense is this, the order is open and the ticket is still -1.

//+------------------------------------------------------------------+
//|                                                         Test.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern int MaFastPeriod = 30;
extern int MaSlowPeriod = 90;
extern int StopLoss = 25;
extern int TakeProfit = 50;

int Ticket;
int init()
  {

  }



int deinit()
  {

  }

int start()
  {
  Ticket=(-1);
  double MyPoint = Point;
   if(Digits == 3 || Digits == 5)
      {
      MyPoint = Point * 10;
      }
      
double MaFast0 = iMA(Symbol(),0,MaFastPeriod,0,MODE_EMA,PRICE_CLOSE,0);
double MaSlow0 = iMA(Symbol(),0,MaSlowPeriod,0,MODE_EMA,PRICE_CLOSE,0);
   
   if(OrdersTotal() == 0 && MaFast0 > MaSlow0 && Ticket==(-1))
      {
      Ticket=OrderSend(Symbol(),0,0.1,Ask,30,Ask-StopLoss*MyPoint,Ask+TakeProfit*MyPoint,"CommentA",0,0,Green);
      return(Ticket);
      }
  Alert("Ticket = ",Ticket); 
   return(0);
  }
 
Why do you write So the programme goes no further, and you won't get an alert
return(Ticket);?
 
It turns out that the alert window will only pop up if there was no signal to open a position at all, and will necessarily display -1
 
So once an order has assigned its number to the Ticket variable, there is no need to output it with return, the variable will not be deleted further on the next tick?
 

Is it possible to open several orders at the same time? For example like this

if(условие выполнено)
{
OrderSend()
OrderSend()
OrderSend()
}
 
sss2019:

Is it possible to open several orders at the same time? For example like this

It may not work that way, because the first request will be handled by the server and the next ones will get an error - the trade thread is busy. It would be better to use your own orders with error handling.
 
sss2019:

Is it possible to open several orders at the same time? For example like this?


You cannot do it all at once.

Only consecutively.