Hi coders, I'm a beginner, please help as I do not know the correct way to code.
I would like to get below Open Trades info from a loop :-
1) OrderOpenTime() of BUY open order, i.e. bOpTm
2) OrderOpenTime() of SELL open order, i.e. sOpTm
3) OrderOpenPrice() of BUY open order, i.e. bOpPx
4) OrderOpenPrice() of SELL open order, i.e. sOpPx
You may have a question what if there are 3 BUY open trades and 5 SELL open trades for a symbol, but no worry about the number of BUY and SELL trades as I have set to maximum number of BUY trades=1 and maximum number of SELL trades=1 for each symbol.
FYI, in my MT4's "Trade" tab, there are many open trades for different symbols but all the BUY trades are standardly assigned with mnBUY magic number and all the SELL trades are standardly assigned with mnSEL magic number.
I know that the way I wrote {i=bOpTm; i=bOpPx;} and {i=sOpTm; i=sOpPx;} are seriously and logically wrong as the " i " is an integer value, ended up the MetaEditor prompts a warning message "possible loss of data due to type conversion". I purposely present my wrong set of codes just for the coders to understand what I intend to achieve.
Could you please help to correct my codes so that I can get the correct Open Order outputs for the bOpTm, sOpTm, bOpPx=0 and sOpPx, thanks.
I would like to get below Open Trades info from a loop :-
1) OrderOpenTime() of BUY open order, i.e. bOpTm
2) OrderOpenTime() of SELL open order, i.e. sOpTm
3) OrderOpenPrice() of BUY open order, i.e. bOpPx
4) OrderOpenPrice() of SELL open order, i.e. sOpPx
You may have a question what if there are 3 BUY open trades and 5 SELL open trades for a symbol, but no worry about the number of BUY and SELL trades as I have set to maximum number of BUY trades=1 and maximum number of SELL trades=1 for each symbol.
FYI, in my MT4's "Trade" tab, there are many open trades for different symbols but all the BUY trades are standardly assigned with mnBUY magic number and all the SELL trades are standardly assigned with mnSEL magic number.
Inserted Code
// input variables int mnBUY=10; // Magic Number for BUY Trades int mnSEL=20; // Magic Number for SELL Trades datetime bOpTm=0, sOpTm=0; double bOpPx=0, sOpPx=0; for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==symbol) { bOpTm=OrderOpenTime(); bOpPx=OrderOpenPrice(); if(OrderMagicNumber()==mnBUY) {i=bOpTm; i=bOpPx;}} { sOpTm=OrderOpenTime(); sOpPx=OrderOpenPrice(); if(OrderMagicNumber()==mnSEL) {i=sOpTm; i=sOpPx;}} }
I know that the way I wrote {i=bOpTm; i=bOpPx;} and {i=sOpTm; i=sOpPx;} are seriously and logically wrong as the " i " is an integer value, ended up the MetaEditor prompts a warning message "possible loss of data due to type conversion". I purposely present my wrong set of codes just for the coders to understand what I intend to achieve.
Could you please help to correct my codes so that I can get the correct Open Order outputs for the bOpTm, sOpTm, bOpPx=0 and sOpPx, thanks.