How do you retrieve the latest value from an array in MQL4?

How do you retrieve the latest value from an array in MQL4?

Manage alerts

Loading saved threads...

Rahul2304 · External communityPost link
External question — Stack Overflow Stack Exchange Author: Rahul2304 Original post: https://stackoverflow.com/questions/71025836 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. How would I retrieve the latest value stored in an array in mql4? I need it so that the latest order open price is shown when I run my code below. double OrderOpenPriceBuyArray[]; int count = 0; ArraySetAsSeries(OrderOpenPriceBuyArray,True); for(double n = 0; n < OrdersTotal(); n++){ if(OrderSelect(n,SELECT_BY_POS) && OrderType() == OP_BUY && OrderSymbol() == Symbol() ){ if(OrderOpenPrice() != OrderOpenPriceBuyArray[count]){ OrderOpenPriceBuyArray[count] = OrderOpenPrice(); ++count; }} } Print(OrderOpenPriceBuyArray[0]);
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange Author: PaulB Original post: https://stackoverflow.com/a/71063222 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. The method that you are using to retrieve the latest opening price is fundamentally flawed and will not work. Why not use: datetime latestBuyOrderOpen; double latestBuyOrderPrice; void OnTick() { for(int n=OrdersTotal()-1; n>=0; n--) { if(OrderSelect(n, SELECT_BY_POS) && OrderType()==OP_BUY && OrderSymbol()==Symbol()) { if(OrderOpenTime()>latestBuyOrderOpen) { latestBuyOrderOpen=OrderOpenTime(); latestBuyOrderPrice=OrderOpenPrice(); } } } Comment(latestBuyOrderPrice); }
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Rahul2304 Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/71025836 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. How would I retrieve the latest value stored in an array in mql4? I need it so that the latest order open price is shown when I run my code below. double OrderOpenPriceBuyArray[]; int count = 0; ArraySetAsSeries(OrderOpenPriceBuyArray,True); for(double n = 0; n < OrdersTotal(); n++){ if(OrderSelect(n,SELECT_BY_POS) && OrderType() == OP_BUY && OrderSymbol() == Symbol() ){ if(OrderOpenPrice() != OrderOpenPriceBuyArray[count]){ OrderOpenPriceBuyArray[count] = OrderOpenPrice(); ++count; }} } Print(OrderOpenPriceBuyArray[0]);

Cancel quote

Checking account access…