I'm having trouble with a simple line of code. Say I have 10 orders.... Both "Buys" and "Sells" open (hedge) in a single currency pair. I want to check if I have 2 buys (and 8 sells)... I want to do this to close other limit orders but this line of code is not working....
if((OrderType()==OP_SELL)&& OrdersTotal()==2)
n8937g,
OrdersTotal() will give you the total number of trades, say 10. You will need a counter variable to increment each time a buy trade is found. Something like this:
int buy_counter=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((OrderType()==OP_BUY)&&(OrderSymbol()==Symbol()))
{
buy_counter++;
}
}
}
if(buy_counter==2) { //do whatever you want }
Good luck!
I'm having trouble with a simple line of code. Say I have 10 orders.... Both "Buys" and "Sells" open (hedge) in a single currency pair. I want to check if I have 2 buys (and 8 sells)... I want to do this to close other limit orders but this line of code is not working....
if((OrderType()==OP_SELL)&& OrdersTotal()==2)
robotfx is absolutely right.
I don't normally do this, but I have to say that attempt of yours was absolutely woeful.
Please talk me through why you thought that line of code would tell you if there were 2 buy orders.
Please don't take this post the wrong way - I'm genuinely intrigued as to what you were thinking.
robotfx is absolutely right.
I don't normally do this, but I have to say that attempt of yours was absolutely woeful.
Please talk me through why you thought that line of code would tell you if there were 2 buy orders.
Please don't take this post the wrong way - I'm genuinely intrigued as to what you were thinking.
cloudbreaker...Please, I'm looking to be taught /helped....I'm sure there are people who can't code as well as me...and many that are far far better... My skills are only basic. I looked through everything I could find and understand here before I posted. I'd assume that there are situations were you get stumped and ask for help too. I tried EVERY combination of commands I could think of...None worked as hoped. I was trying to first check 1. using only OP_Buy orders and 2. if there were 2 of them ... If the condition was met the { code.....} would execute. I couldn't get the right syntax to consider both things........ Although woeful I' m sure you could see what I was trying to do. I know the code (&& etc) is not correct. (I'm not totally code illiterate my REAL account is making money every day with an EA I created___ SIMPLE is KEY). Robofx thank you for your help!!! I'm testing !! Thanks to both of you for helping--- I do value and respect your insights and knowledge.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
if((OrderType()==OP_SELL)&& OrdersTotal()==2)