How do I save the order/open price for all open orders in an array?

 

Hello,

How would I save the order open price for all open orders and save it into an array which updates every time I add another order?

My code is below. 

double OrderOpenPriceBuyArray[10]; 

datetime LastTimeBuy; //LastBuyOrderTime

(int j = 0; j < OrdersTotal(); j++) {
if(OrderSelect(j, SELECT_BY_POS,MODE_TRADES)==True){
if(OrderSymbol() == Symbol() && OrderType() == OP_BUY && OrderOpenTime() > LastTimeBuy){ 
OrderOpenPriceBuyArray[OrderOpenPrice()];
}
}
}
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
  1.    (int j = 0; j < OrdersTotal(); j++) {

    Do not post code that will not even compile.

  2. OrderOpenPriceBuyArray[OrderOpenPrice()];

    This is nonsense. You use an int to index into an array. You store a double (a price) into the array.

  3. double OrderOpenPriceBuyArray[10]; 
    
    // datetime LastTimeBuy; //LastBuyOrderTime
    
    int count = 0;
    for(int j = 0; j < OrdersTotal(); j++) if(
       OrderSelect(j, SELECT_BY_POS)
    && OrderType() == OP_BUY
    && OrderSymbol() == Symbol() 
       ){ 
       OrderOpenPriceBuyArray[count] = OrderOpenPrice();
       ++count;
    }
 
William Roeder #:
  1. Do not post code that will not even compile.

  2. This is nonsense. You use an int to index into an array. You store a double (a price) into the array.

Thanks for your input @WilliamRoeder. However it does not save the latest orderopenprice into the array. What is wrong with this new piece of code?


int count = 0;
double OrderOpenPriceBuyArray[10];


for(double n = 0; n < OrdersTotal(); n++){
    if(OrderSelect(n,SELECT_BY_POS) && OrderType() == OP_BUY && OrderSymbol() == Symbol() ){
    OrderOpenPriceBuyArray[count] = OrderOpenPrice();
    ++count; 
    }
    }
 
Rahul Shaji Parmeshwar #: Thanks for your input @WilliamRoeder. However it does not save the latest orderopenprice into the array. What is wrong with this new piece of code?
  1. Your posted code (#2) and mine are identical.
  2. It does not save the latest. It saves all which include the latest.
  3. There is nothing wrong.
 
William Roeder #:
  1. Your posted code (#2) and mine are identical.
  2. It does not save the latest. It saves all which include the latest.
  3. There is nothing wrong.

@WilliamRoeder I understand now that array's save data with the latest data being the last element but I don't know how I can access that last element. Could you point me in the right direction please?

 
  1. Rahul Shaji Parmeshwar #: but I don't know how I can access that last element. 

    You know the array name. You know the array size. If you don't know how, step away from the computer and hire someone.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.


  2. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

 
Rahul Shaji Parmeshwar

I have deleted your other topic.

 
William Roeder #:
  1. You know the array name. You know the array size. If you don't know how, step away from the computer and hire someone.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.


  2. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

@WilliamRoeder Why are you being so aggressive? I only wanted to educate myself and not get violated by members in this forum! And my question still stands unanswered!

 
Rahul Shaji Parmeshwar #:

@WilliamRoeder Why are you being so aggressive? I only wanted to educate myself and not get violated by members in this forum! And my question still stands unanswered!

William Roeder #:
  1. You know the array name. You know the array size. If you don't know how, step away from the computer and hire someone.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.


  2. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

I've modified the code now and it still doesn't seem to be working. 


    double OrderOpenPriceBuyArray[];
    double OrderOpenPriceNewBuy = 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; 
    }}
    }
    
    for(double p =0; p > ArraySize(OrderOpenPriceBuyArray); p++){
    OrderOpenPriceNewBuy = p;
    }
 
 
Rahul Shaji Parmeshwar #: @WilliamRoeder Why are you being so aggressive? I only wanted to educate myself and not get violated by members in this forum! And my question still stands unanswered!
Why are you wasting hundreds of peoples time when you can't ever read an element out of an array. L E A R N   T O   C O D E.