// The code below is uncheck and will not compile. It is only an sample code. ulong posTicket = 0; int OnInit( void ) { posTicket = 0; }; void OnTick( void ) { if( posTicket == 0 ) { if( trade.Sell( lot_size, _Symbol ) ) { posTicket = trade.ResultOrder(); Print( "Sell order placed with ticket number = ", posTicket ); } else Print( "Sell order failed!" ); }; };
Then what is stopping you?
In both your example and mine, the ticket number is stored in a "global" variable (i.e. "posTicket"), so it is accessible globally/anywhere in your program.
EDIT: Unless you are declaring a local variable with the same name which overrides it. Are you getting any compiler warning about that?
I have a global variable
and on the onTick function I use this condition to open a trade
Using a print statement I found out that the global variable does not hold the ticket value and is 0 at every check in the onTick, could somebody please help me understand what I'm doing wrong ?
trade.ResultOrder() will return an Order Ticket. Although technically the position ticket will be same when opening a position but it is better to perform checks ( if a position actually opened ) before storing that in the position ticket variable.
- www.mql5.com
Then what is stopping you?
In both your example and mine, the ticket number is stored in a "global" variable (i.e. "posTicket"), so it is accessible globally/anywhere in your program.
EDIT: Unless you are declaring a local variable with the same name which overrides it. Are you getting any compiler warning about that?
That's what I'm confused about, I've declared it globally and yet it returns 0 every time. 0 errors and 0 warnings.
Then you will have to show more of your code. We cannot read your mind nor see your computer. We can't possible know what you are doing to be able to offer you advice.
If you don't show you your actual code, how are we se supposed to know what you are doing? We can't read you mind nor see your computer.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
ulong posTicket;
and on the onTick function I use this condition to open a trade
Using a print statement I found out that the global variable does not hold the ticket value and is 0 at every check in the onTick, could somebody please help me understand what I'm doing wrong ?