- Actual Computer Time During Testing
- Exploit Strtotime
- Return value of 'OrderSelect' should be checked
-
Don't worry about performance, until you have a problem. Then, and only then, use the profiler, find the problem, fix the problem, and remeasure.
-
There is no such function defined. List of MQL4 Functions - MQL4 Reference
-
Don't worry about performance, until you have a problem. Then, and only then, use the profiler, find the problem, fix the problem, and remeasure.
-
There is no such function defined. List of MQL4 Functions - MQL4 Reference
- Luandre Ezra: return a value around 950 to 1050. How can I interpret this value
It is not the value, it is the difference between two calls. 950-1050 difference means it took once second.
- Luandre Ezra #: Does performance isn't equal to the speed of our order get sent to market?
Speed English; that is nonsensical. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation. (2013)
- Always post all relevant code (using Code button) or attach the source file.
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problemWe can't see your broken code.
my code looks like this,
void OnTick() { //Print("MAGIC NUMBER: ", MagicNumber); if(IsNewCandle()) { uint Start = GetTickCount(); resetCounterVar(); CloseOrders(); if(CheckPendOrder()==0) OpenOrders(); uint time = GetTickCount()-Start; Print("time: ", time); } }
So the whole process is taking around a second for MT4 to finish execute the code. Does one second is quite normal or it is slow?
Luandre Ezra #: Does performance isn't equal to the speed of our order get sent to market?
What I meant is that performance should be equal to how fast MT4 read and execute code and sent market order (from mt4 client to mt4 server to ECN) so why you say that performance should not be worried (I do scalping btw)?
There is no way for us to know if that is fast, slow or normal, because we have no ideia what your code does or under what conditions.
Also, your measurement is not only considering your code execution but also the network latency. So, your code may be fast, but your network response slow, or you code may be slow and your network fast. You can't tell from the way you are measuring things.
my code looks like this,
So the whole process is taking around a second for MT4 to finish execute the code. Does one second is quite normal or it is slow?
void OnTick() { //Print("MAGIC NUMBER: ", MagicNumber); if(IsNewCandle()) { uint Start = GetTickCount(); resetCounterVar(); CloseOrders(); if(CheckPendOrder()==0) OpenOrders(); uint time = GetTickCount()-Start; Print("time: ", time); } }
You are calling 4 different functions. As we have no idea what those functions do we cannot guess whether it may be slow or not.
I will edit your title so that it shows GetTickCount() instead of Tick value.
You are calling 4 different functions. As we have no idea what those functions do we cannot guess whether it may be slow or not.
I will edit your title so that it shows GetTickCount() instead of Tick value.
int CheckOpenPosition(int shift=0) { int result=0; if(buySignal) result=1; if(sellSignal) result=2; return result; } // int CheckClosePosition(int shift=0) { int result=0; if(sellSignal) result=1; if(buySignal) result=2; return result; } // void OpenOrders() { if(CheckOpenPosition()==1) { MarketBuyOrder(); } if(CheckOpenPosition()==2) { MarketSellOrder(); } } //+------------------------------------------------------------------+ void MarketBuyOrder() { RefreshRates(); openPriceBuy = Ask; stoplossBuy = iLow(Symbol(),PERIOD_CURRENT,iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,BarShift,0));; takeProfitBuy = (openPriceBuy - stoplossBuy)*RiskReward+openPriceBuy; if(Take_profit == 0) takeProfitBuy = 0; if(LotSizeType == Fixed) lotSizeBuy = FixedLotSize; if(LotSizeType == Dynamic) lotSizeBuy = CalculateLotSize(Risk_Per_Trade/100,stoplossBuy)/lotType; if(lotSizeBuy < MarketInfo(Symbol(),MODE_MINLOT)) lotSizeBuy = MarketInfo(Symbol(),MODE_MINLOT); ticketBuy = OrderSend(Symbol(),OP_BUY,lotSizeBuy,openPriceBuy,slippage,stoplossBuy,takeProfitBuy,"BUY",MagicNumber); } // void MarketSellOrder() { RefreshRates(); openPriceSell = Bid; stoplossSell = iHigh(Symbol(),PERIOD_CURRENT,iHighest(Symbol(),PERIOD_CURRENT,MODE_HIGH,BarShift,0));; takeProfitSell = openPriceSell - (stoplossSell - openPriceSell)*RiskReward; if(Take_profit == 0) takeProfitSell = 0; if(LotSizeType == Fixed) lotSizeSell = FixedLotSize; if(LotSizeType == Dynamic) lotSizeSell = CalculateLotSize(Risk_Per_Trade/100,stoplossSell)/lotType; if(lotSizeSell < MarketInfo(Symbol(),MODE_MINLOT)) lotSizeSell = MarketInfo(Symbol(),MODE_MINLOT); ticketSell = OrderSend(Symbol(),OP_SELL,lotSizeSell,openPriceSell,slippage,stoplossSell,takeProfitSell,"SELL",MagicNumber); } // void CloseOrders() { RefreshRates(); if(sellSignal) { for(int i = OrdersTotal() - 1; i >= 0; i--) { if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if(OrderType() == OP_BUY) { bool res = OrderClose(OrderTicket(),OrderLots(),Bid,0); if(!res) Print("Order failed to CLOSE OPEN ORDER for ticket # ",OrderTicket()," with error: ",GetLastError()); } } } } if(BuySignal) { for(int i = OrdersTotal() - 1; i >= 0; i--) { if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if(OrderType() == OP_SELL) { bool res = OrderClose(OrderTicket(),OrderLots(),Ask,0); if(!res) Print("Order failed to CLOSE OPEN ORDER for ticket # ",OrderTicket()," with error: ",GetLastError()); } } } } } //NEW OnTick() void OnTick() { if(IsNewCandle()) { uint Start = GetTickCount(); CloseOrders(); if(OrdersTotal()<MaxOpenTrade) OpenOrders(); uint time = GetTickCount()-Start; Print("time: ", time); } }
here's all the code and function except the logic after I clean all unnecessary variable and function.
Fernando Carreiro : There is no way for us to know if that is fast, slow or normal, because we have no ideia what your code does or under what conditions.
Correct! There is no benchmark, nothing to compare your results with. The only thing you can do with it is compare it to other code to determine which one is the faster of the two.
For example, you could time different EAs from the codebase and compare your code execution speed to those, to see if at least your code is more efficient than those. Or another example, is for you to streamline your own code as best you can, and see how much you have saved.
However, usually this method of timing is done in a loop over many iterations to measure the real execution speed, because sometimes a single iteration is too quick to get a proper measurement.
Also, remember my warning, you are currently measuring not only your code execution but also the delays for the order processing, which are dependant on network latency and broker processing time, so it is not accurately giving you the metrics of your code alone. Separate the two, so that you can see your code execution time, and the order processing time.
here's all the code and function except the logic after I clean all unnecessary variable and function.
You are focusing on the wrong stuff....
The bulk of your execution time based on code shown will be in the processing of a trade request, so measure that first because there is little you can do about it with code and it provides a base line.
You code is full of duplicate calls and unnecessary functions, clean them up, do things once.
You say your are a scalper but you seem to be only executing on a new bar - so one second does not seem a lot to worry about in context of elapsed time.
Use the code profiler
here's all the code and function except the logic after I clean all unnecessary variable and function.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use