You have to show the code.
Did you select the order by using OrderSelect() function?
OrderOpenPrice
Returns open price of the currently selected order.
double OrderOpenPrice(); |
Returned value
Open price of the currently selected order.
Note
The order must be previously selected by the OrderSelect() function.
Example:
if(OrderSelect(10, SELECT_BY_POS)==true) Print("open price for the order 10 ",OrderOpenPrice()); else Print("OrderSelect returned the error of ",GetLastError()); |
- docs.mql4.com
//Breakeven Price double be_JG_duod(double &be_JG_kongd){ double jg_duod=0; double jg_kongd=0; double xz_kcJG=OrderOpenPrice(); double ot=OrdersTotal(); for(int k=0;k<ot;k++){ if(OrderSelect(k,SELECT_BY_POS,MODE_TRADES)==true){ if(OrderSymbol()==Symbol()&& OrderMagicNumber()==hm_1 && OrderComment()==zs_1){ if(OrderType()==kc_lx_0){ jg_duod+=syg_kcJG; } if(OrderType()==kc_lx_1){ jg_kongd+=syg_kcJG; } } } } be_JG_kongd=jg_kongd; return(jg_duod); } //Breakeven Lots double be_SS_duod(double &be_SS_kongd){ double ss_duod=0; double ss_kongd=0; double DL=OrderLots(); double ot=OrdersTotal(); for(int j=0;j<ot;j++){ if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==true){ if(OrderSymbol()==Symbol()&& OrderMagicNumber()==hm_1 && OrderComment()==zs_1){ if(OrderType()==kc_lx_0){ ss_duod++; } if(OrderType()==kc_lx_1){ ss_kongd++; } } } } be_SS_kongd=ss_kongd; return(ss_duod); } double BE_DUOD(double &BE_KONGD){ double be_JG_kongd; double be_JG_duod=(double)be_JG_duod(be_JG_kongd); double be_SS_kongd; double be_SS_duod=(double)be_SS_duod(be_SS_kongd); double beduod=0;//beduod=NormalizeDouble(beduod,5); double bekongd=0;//bekongd=NormalizeDouble(bekongd,5); double ot=OrdersTotal(); for(int j=0;j<ot;j++){ if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==true){ if(OrderSymbol()==Symbol()&& OrderMagicNumber()==hm_1 && OrderComment()==zs_1){ if(OrderType()==kc_lx_0){ if(be_JG_duod!=0 || be_SS_duod!=0){ beduod=be_JG_duod/be_SS_duod; Print("be_JG_duod="+be_JG_duod+"be_SS_duod+"+be_SS_duod); } } if(OrderType()==kc_lx_1){ if(be_JG_kongd!=0 || be_SS_kongd!=0){ bekongd=be_JG_kongd/be_SS_kongd; } } } } } BE_KONGD=bekongd=NormalizeDouble(bekongd,5); return(beduod); }
Actually , I want to get the breakeven price , but my breakeven price always wrong , and finally , if I try to print the OrderOpenPrice() in OnTick() , it will show the last OrderOpenPrice even it's from different pair.
and I have tried to correct the code , and it's still wrong for the breakeven ....need help . The Breakeven will become the price of last order . dont know why .
Break even price is lots weighted average price. | Sum( lots[i] * OOP[i] ) / Sum( lots[i] ) | 1@6 + 2@10 = 26/3 = 8.667 = 1@(+2.667) + 2@(-1.333) = 0.001 |
If you have hedging trades include their direction (dir buy=+1, sell=-1) thus: | Sum( dir(i) * lots[i] * OOP[i] ) / Sum( dir(i) * lots[i] ) | 1@6 - 2@10 = -14/-1 = 14.00 = 1@(+8)-2@(-4) = 0 |
Actually , I am trying to get the simple average price . still can not . lol ( up there , I try to get "Lots total " and " Orders total" and Orders total / orders total . finally the average price is incorrect too ..i need to think about it . i have to do this .
Tsz Ho Chow: I am trying to get the simple average price .
| Lots weighted average price, is the break even price, is the only average that makes sense. |
Tsz Ho Chow: , I have searched something about " Bars " it's uesless on demo/live account .
bool sm_kx(){ static int yiyou_kx=0; if(Bars==yiyou_kx) return(false); yiyou_kx=Bars; return(true); } |
|
//Breakeven Price double be_JG_duod(double &be_JG_kongd){ double jg_duod=0; double jg_kongd=0; double xz_kcJG=OrderOpenPrice(); double ot=OrdersTotal(); for(int k=0;k<ot;k++){ if(OrderSelect(k,SELECT_BY_POS,MODE_TRADES)==true){
Here you call OrderOpenPrice() function, but there is no order selected (yet).
You can only call this function after an order has been selected by OrderSelect() function.
//Breakeven Lots double be_SS_duod(double &be_SS_kongd){ double ss_duod=0; double ss_kongd=0; double DL=OrderLots(); double ot=OrdersTotal(); for(int j=0;j<ot;j++){ if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==true){
And here you make the same mistake, but this time you call OrderLots() function, before and order has been selected by OrderSelect() function.
Here you call OrderOpenPrice() function, but there is no order selected (yet).
You can only call this function after an order has been selected by OrderSelect() function.
And here you make the same mistake, but this time you call OrderLots() function, before and order has been selected by OrderSelect() function.
Thanks for your help . Do you mean i should make it like this ? but the same problem occur to me , the average price become the last OrderOpenPrice . lol
double be_SS_duod(double &be_SS_kongd){ double ss_duod=0; double ss_kongd=0; double ot=OrdersTotal(); for(int j=0;j<ot;j++){ if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==true){ if(OrderSymbol()==Symbol()&& OrderMagicNumber()==hm_1 && OrderComment()==zs_1){ double DL=OrderLots(); if(OrderType()==kc_lx_0){ ss_duod++; } if(OrderType()==kc_lx_1){ ss_kongd++; } } } } be_SS_kongd=ss_kongd; return(ss_duod); }
Please see: https://docs.mql4.com/trading ,lol
Function |
Action |
Closes opened order |
|
Closes an opened order by another opposite opened order |
|
Returns close price of the currently selected order |
|
Returns close time of the currently selected order |
|
Returns comment of the currently selected order |
|
Returns calculated commission of the currently selected order |
|
Deletes previously opened pending order |
|
Returns expiration date of the selected pending order |
|
Returns amount of lots of the selected order |
|
Returns an identifying (magic) number of the currently selected order |
|
Modification of characteristics of the previously opened or pending orders |
|
Returns open price of the currently selected order |
|
Returns open time of the currently selected order |
|
Prints information about the selected order in the log |
|
Returns profit of the currently selected order |
|
The function selects an order for further processing |
|
The main function used to open an order or place a pending order |
|
Returns the number of closed orders in the account history loaded into the terminal |
|
Returns stop loss value of the currently selected order |
|
Returns the number of market and pending orders |
|
Returns swap value of the currently selected order |
|
Returns symbol name of the currently selected order |
|
Returns take profit value of the currently selected order |
|
Returns ticket number of the currently selected order |
|
Returns order operation type of the currently selected order |
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have no idea why my OrderOpenPrice() would remember the last price even in Backtesting with different pair .
for example , last OrderOpenPrice was eurusd 1.00000 , and I test on usdjpy , the OrderOpenprice will be 1.00000 also . and usdjpy was no order begin.