skyblazer: maybe like a loop where he checks: if orderymbol = chartsymbol and if ordertype=op_buy || op_sell
| You already stated the answer. Using OrdersTotal directly and/or no Magic number filtering on your
OrderSelect loop means your code is incompatible with every EA (including
itself on other charts and manual trading.) Symbol Doesn't equal
Ordersymbol when another currency is added to another seperate chart . - MQL4
forum
|
You already stated the answer. |
Well I cant just copy this, can I?
Because I dont understand in the code from the link why you return false when he checks the attributes from the order. Dont you want to go through them when they are true ? I mean you used !=
you need to fiter with either OrderMagicNumber() and or OrderSymbol()
{
// The chart symbol is equal to the order symbol
}
if(OrderMagicNumber()==magicnumber)
{
// The ordermagic number is equal to the magicnumber (int)
}
I go through all of them. Any that are != are not my MN and pair, I don't want to process them. Remove the function and put the code inside your loop if you want to. Then you'll have to join the lines with ampersands and change everything to ==. Big deal. | for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--) if(MySelect(iPos, SELECT_BY_POS) ){ oo.ticket = OrderTicket(); .. |
I go through all of them. Any that are != are not my MN and pair, I don't want to process them. Remove the function and put the code inside your loop if you want to. Then you'll have to join the lines with ampersands and change everything to ==. Big deal. | for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--) if(MySelect(iPos, SELECT_BY_POS) ){ oo.ticket = OrderTicket(); .. |
I´m sorry but this is so weird to understand for me.
What I have now are the following lines:
int i;
for(i=OrdersTotal()-1; i>=0; i--)
if(!OrderSelect( i,SELECT_BY_POS) && OrderSymbol() != _Symbol && OrderMagicNumber() != magicNr){
can_trade = true;
else{
can_trade=false;
}
if(can_trade)
{
...//conditions for placing order...etc.
}
In Backtesting ea doesnt open a single order... where is the problem ?
Please use the SRC button when posting code. I have done it for you this time. Your formatting is still a mess though.
If you follow your code you will see that can_trade is assigned a value depending on the last order checked
This should work better for you
int i;
can_trade = true;
for(i=OrdersTotal()-1; i>=0; i--)
if(OrderSelect( i,SELECT_BY_POS) && OrderSymbol() == _Symbol && OrderMagicNumber() == magicNr)
{
can_trade=false;
break;
}
Typo or maybe it is time I went to bed?
Yes, you are right.
I modified the original code and to be honest never even noticed the !.
I will edit the post.
Thanks
{
can_trade;
}
...
Thanks for your help. He opens orders now,but however still opens a ton of orders when he gets the signal... which was my initial problem and why I started with the lines above
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I´m assuming this question came a lot but I couldnt find anythin helpful..
Currently My ea works like:
if(OrdersTotal()==0){
placing order ... etc ..
}
The problem with the code above is, that it stops trading as soon as one order is open regardless of the conditions to open a new order.
So it cant decide whether the order is from the actual chart or another.
Another problem would be that I´m using Stopp orders, the ea also have to decide whether its an open order or a pending order. Meaning: Don´t trade when there´s an open order unless it´s a different symbol.
How can I solve this?
maybe like a loop where he checks: if orderymbol = chartsymbol and if ordertype=op_buy || op_sell
-> dont trade
Have you guys some better suggestions ?