Download MetaTrader 5

op_buy not work

To add comments, please log in or register
ashraf mohamed
131
ashraf mohamed  

hi every one

i have this expert open orders when no orders open and if current order is loss EA open new order

EA use this code ordertotal()==0 to check no orders open to start work but i need to change this code ordertotal()==0 to check if any buy orders was opened,

any one cn hlp

i try to use OrderType()!=OP_BUY but in this case not open any orders


please advice

bool buycondition;
buycondition=Close[1]>Open[1];
if(OrdersTotal()==0)

{
OrderSend(Symbol(),OP_BUY,lots,Ask,3,sl,tp,"s_03",1013,0,Green);//--open sell order

}


if (buycondition==true)

    OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES);  
    if(OrderSymbol()==Symbol() && OrderType()==OP_BUY  
    &&buycondition==true&& OrdersTotal()<max_of_open_lots&& Bid<=(OrderOpenPrice()-neworder*Point*10))
OrderSend(Symbol(),OP_BUY,0.2,Ask,3,sl,tp,"s_04",1013,0,Red);//--open sell order


   return(0);
Simon Gniadkowski
Moderator
18042
Simon Gniadkowski  
verofx:

hi every one

i have this expert open orders when no orders open and if current order is loss EA open new order

EA use this code ordertotal()==0 to check no orders open to start work but i need to change this code ordertotal()==0 to check if any buy orders was opened,

any one cn hlp

i try to use OrderType()!=OP_BUY but in this case not open any orders

You need a loop to loop through all the open orders, and check if any are OrderType() == OP_BUY . . .

You also need to check the return values from your trading functions to see if they have worked or failed, if they fail you will want to know about it, you will want to know why they failed - the error, and what made them fail - the relevant variables involved such as Bid, Ask Open price, etc, etc read this and implement it: What are Function return values ? How do I use them ?

ashraf mohamed
131
ashraf mohamed  
RaptorUK:

You need a loop to loop through all the open orders, and check if any are OrderType() == OP_BUY . . .

You also need to check the return values from your trading functions to see if they have worked or failed, if they fail you will want to know about it, you will want to know why they failed - the error, and what made them fail - the relevant variables involved such as Bid, Ask Open price, etc, etc read this and implement it: What are Function return values ? How do I use them ?


i try using OrderType()!=OP_SELL and work fine, only OrderType()!=OP_BUY not work the last code i submit with ordertotl()==0 work fine i replace this coed by OrderType()!=OP_BUY


bool buycondition;
buycondition=Close[1]>Open[1];
if(OrderType()!=OP_BUY)

{
OrderSend(Symbol(),OP_BUY,lots,Ask,3,sl,tp,"s_03",1013,0,Green);//--open sell order

}


if (buycondition==true)

    OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES);  
    if(OrderSymbol()==Symbol() && OrderType()==OP_BUY  
    &&buycondition==true&& OrdersTotal()<max_of_open_lots&& Bid<=(OrderOpenPrice()-neworder*Point*10))
OrderSend(Symbol(),OP_BUY,0.2,Ask,3,sl,tp,"s_04",1013,0,Red);//--open sell order


   return(0);
Simon Gniadkowski
Moderator
18042
Simon Gniadkowski  
verofx:

i try using OrderType()!=OP_SELL and work fine, only OrderType()!=OP_BUY not work the last code i submit with ordertotl()==0 work fine i replace this coed by OrderType()!=OP_BUY


If you want help listen to the help you are given . . .
whroeder1
16295
whroeder1  
RaptorUK: If you want help listen to the help you are given . . .
He's hard of reading!
ashraf mohamed
131
ashraf mohamed  
may i ask you for loop code do this function?
Simon Gniadkowski
Moderator
18042
Simon Gniadkowski  
verofx:
may i ask you for loop code do this function?
You can find sample code here: Loops and Closing or Deleting Orders
ashraf mohamed
131
ashraf mohamed  
bool buycondition;
buycondition=Close[1]>Open[1];
int j;
for(j=1;j<=OrdersTotal(); j++)

OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES);  

if (buycondition==true&&OrderType()!=OP_BUY)

{
OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"buy_0",0,0,Red);//--open sell order
}

OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES);  
    if(OrderSymbol()==Symbol() && OrderType()==OP_BUY  
    &&buycondition==true&& OrdersTotal()<max_of_open_lots&& Ask<=(OrderOpenPrice()-neworder*Point*10))
OrderSend(Symbol(),OP_BUY,0.2,Bid,3,0,0,"s_02",0,0,Red);//--open sell order

i use loop as i suit but no any order opened

pleae advice

Simon Gniadkowski
Moderator
18042
Simon Gniadkowski  
verofx:

i use loop as i suit but no any order opened

pleae advice


If you can't think logically about coding then your best option is here, pay someone to code for you: Jobs
To add comments, please log in or register