ticket is just a convenient name for the variable to be used, and in the context you mentioned, it means the variable "ticket " is to be assigned the value returned by the OrderSend() function.
When you send a request to open a position using the OrderSend() function, and it is successful, the function returns the ticket number of the trade, if the OrderSend() request is not successful the function returns -1.
That is why in the example you will see the next line is if (ticket<0) ... do some error handling
What am I missing here ?
Please advise
OrderSend is a function . . . it's type is int, it returns the ticket number . . . so it might look something like this . . .
int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE) { int TicketNumber; . . . . if(. . . .) return(TicketNumber); else return(-1); }
in your post, ticket is used to hold the return value from the function.
initialization of the variable ticket=OrderSend
int two(){ // define a function that returns an integer int var = 2; // an assignment of a value to a variable return (var); // return a value from the function } ////////// int four = 2 + two(); // call a function, calculate, and assign. int ticket = OrderSend(...); // same thing
So unless I need to reference ticket for some purpose there is no need for this at all right ?
I could just use OrderSend on it's own, as long as I didn't need that ticket expression for some reason it should be no different to open orders ?
Thanks
Agent86:
I see, just seems like return(ticket); or something would require the execution of OrderSend, but I guess it executes silently
So unless I need to reference ticket for some purpose there is no need for this at all right ?
I could just use OrderSend on it's own, as long as I didn't need that ticket expression for some reason it should be no different to open orders ?
Thanks
No. We do need the ticket to get the result of OrderSend() function, whether the OrderSend() function was executed properly or not, and/or whether order was really sent or not.
int success = OrderSend (Symbol(), ... ); if (success > 0) { Print ("Order was sent"); } else { Print ("Order was not sent and there is error "+GetLastError()); // should I re-send the order ??? }
And with ECN broker we do need the ticket so we can add the SL and TP later, because ECN brokers does not allow order to be sent with SL and TP, the SL and TP must be set to zero.
int success = OrderSend (Symbol(), Order_type, Lots, Price, Slippage, 0, 0); if (success > 0) { Print ("Order was sent. Now we\'re going to add SL and TP"); OrderSelect (success, SELECT_BY_TICKET, MODE_TRADES); bool modif = OrderModify (success, OrderOpenPrice(), SL, TP, 0); if (modif == false) { Print ("Fail to add TP and SL to ticket no "+success+" with error no "+GetLastError()); // must execute OrderModify() again } else { Print ("Success adding TP and SL"); } } else { Print ("Order was not sent and there is error "+GetLastError()); // should I re send the order ??? }
//++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.015 0.0150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ OptParameters(); if (Digits % 2 == 1){ // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262 pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl //---- These are adjusted for 5 digit brokers. /* On ECN brokers you must open first and THEN set stops int ticket = OrderSend(..., 0,0,...) if (ticket < 0) Alert("OrderSend failed: ", GetLastError()); else if (!OrderSelect(ticket, SELECT_BY_TICKET)) Alert("OrderSelect failed: ", GetLastError()); else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0) Alert("OrderModify failed: ", GetLastError()); */
Also do have my EA's adjusted for 5 or 3 digit brokers also
This makes sense now thanks all
Happy coding
Hello, Friends,
I am using the OrderSend function with the last parameter being Green or Red (for BUY or SELL). The EA places an order but the color sign is not visible on the chart. What can I do to make it work? Thank you very much!! Solator
Don't double post
Don't hijack other threads
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Regarding OrderSend and this documenatation
https://docs.mql4.com/trading/OrderSend
I see in many EA's and tutorials including the documentation what appears to be a declaration and initialization of the variable ticket=OrderSend
I have been using this syntax as shown in the documentation, but after some thought I realized I don't know exactly why ?
How is ticket called ? Why does the OrderSend place an order ? OrderSend it really not being called but just being assigned to the variable as part of the initialization ?
What am I missing here ?
Please advise