all i need for now to print each trade ticket number
thanks for any help in advance
You can use this code :
int Magic = 00100; int ticket; double StartPoints = 12; double pips; double ticksize; int positions = 4; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { ticksize = MarketInfo(Symbol(),MODE_TICKSIZE); if(ticksize == 0.00001 || 0.001) pips = ticksize * 10; else pips = ticksize; return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(OrdersTotal() < positions) { ticket = OrderSend(Symbol(), OP_SELL, 0.01, Bid, 3, Bid+(StartPoints*pips), Bid-(StartPoints*pips), NULL, Magic, 0, Red); } int intticketNumber[1]; int intOrdersTotal = OrdersTotal(); if ( intOrdersTotal > 1 ) ArrayResize( intticketNumber, intOrdersTotal ); for( int i = intOrdersTotal - 1; i >= 0; i-- ) if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) ) { intticketNumber[i] = OrderTicket(); Print ("here: ", intticketNumber[i]); } }
It's better to use a well made collection. Your best bet is to use CArrayInt for store ticket numbers. You could also subclass and make a method to formate the string how you like. Example:
#include <arrays/arrayint.mqh> class ArrayInt : public CArrayInt { public: virtual string to_string() const { string res = "["; for(int i=0; i<this.Total(); i++) { res += string(this[i]); if(i < size - 1) res += ", "; } return res + "]"; } }; void OnStart() { ArrayInt arr; for(int i=OrdersHistoryTotal()-1, x=0; i>=0 && x < 6; i--, x++) if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) arr.Add(OrderTicket()); Print(arr.to_string()); }
output
EURUSD,H1: [20284, 17619, 17453, 17283, 17109, 91828]
thank you for your replaying
i found a solution also so ill put it here to anyone may be have the same problem
void OnTick(){ int Pos_Order_Ticket[1]; int TotalOrders = OrdersTotal(); if(ArrayResize(Pos_Order_Ticket, TotalOrders) == TotalOrders){ for(int i = TotalOrders - 1; i >= 0; i--){ if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){ Pos_Order_Ticket[i] = OrderTicket(); }else{ Pos_Order_Ticket[i] = EMPTY; } Print ("here: ", Pos_Order_Ticket[i]); } } }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hello
i made an expert, it works good but for a reason it need a unique number to restore every trade so i tried to save ticket number
i searched file open, and arrays but i couldnt find what i want beside im not good in arrays
finally i found something near to what i want
i got the code but it not give me the result