EA mixes BUY and SELL orders - page 3

 
WHRoeder:

int OrderType = OrderType() is not ok, one may be hiding the other (local declarations hide globals with no error.) Try

int orderType = OrderType()

The original code is . . . .

int orderType;
   for(cnt = total-1; cnt >= 0; cnt--)
   {
      while (!OrderSelect(cnt, SELECT_BY_POS)) {Sleep(500);}
      orderType = OrderType();

. . . which is effectively the same as what you are suggesting ?

I think dvarrin is saying that his problem lies with his ticket number.

 

no it's not.

Order type declared outside the loop will effectively transfer the value of orderType to next Cycle and even if error happens, that value will enter into the next conditional.

If you declare inside loop with immediate value setting of OrderType() there will not be room for such error.

(maybe it's not the OPs problem, but it may prevent others from happening) what's it to not try?

Also half a second at sleep is a bit overdoing it. While loop should be fine with 10 milisecond sleep timer without any hit to your cpu load whatsover (well almost :P)

 
forexCoder:

no it's not.

Order type declared outside the loop will effectively transfer the value of orderType to next Cycle and even if error happens, that value will enter into the next conditional.

If you declare inside loop with immediate value setting of OrderType() there will not be room for such error.

(maybe it's not the OPs problem, but it may prevent others from happening) what's it to not try?

Also half a second at sleep is a bit overdoing it. While loop should be fine with 10 milisecond sleep timer without any hit to your cpu load whatsover (well almost :P)


I suspect the problem to be the use of "ask manual confirmation" when forward testing the EA, but I don't understand what happens exactly.

All I know is that there is no way for a variable named OrderType to interfer with a method with the same name and also the declaration location has nothing to do with my problem.

The problem is that OrderTicket(), OrderStoploss(), ... are not giving the data for the same order after using OrderSelect().

If I use local variables and set them after the call to OrderSelect() it works, but if I use directly OrderTicket() or OrderStoploss() it gives wrong values.


Why in my code is OrderStopLoss() returning the stoploss of an other order inside the same iteration of the "for" loop?

 

Here is the complete code of the EA:

The problem is in the first "for" loop of the updateFbOrders() method.

To test it, I add the alligator and fractal indicators on a chart and find a chart were the last up fractal is above the alligator lines and the last bottom fractal is below the alligator lines.

Then it should create pending buy and sell orders. If there was a breakout of one of the fractal, it will open an immediate order.

Then it will modify the stoploss of each order each time the fractals change, but it sets the stoploss for the wrong order.

Check the alert windows and look for a message like this: Count: 1 Stoploss 1.41008000 for buy order: 46454014 orderType: 5, and if you check the order 46454014, you will see that it is actually a "sell" order.And it will keeps on modifying the orders even if the stoploss don't change, this because it takes the wrong stoploss level.
 

This is stupid. You're not pasting the whole code.

You have a

areBuyOrdersInProfitAt

function, which we do not see inside, please paste it. It's by now highly probable that you made a mistake somewhere else. Are you using the OrderSelect fuction anywhere else?

Also, where do you set your longSL and shortSL variables? Please paste that part of the code as well.

EDIT: you pasted it while I was typing, looking at the new post now.

 
forexCoder:

This is stupid. You're not pasting the whole code.

You have a

areBuyOrdersInProfitAt

function, which we do not see inside, please paste it. It's by now highly probable that you made a mistake somewhere else. Are you using the OrderSelect fuction anywhere else?

Also, where do you set your longSL and shortSL variables? Please paste that part of the code as well.

EDIT: you pasted it while I was typing, looking at the new post now.

Hi forexCoder

I've added the EA to the previous post.


But I think you've pointed the problem: I'm using OrderSelect() in the method "areBuyOrdersInProfitAt". :-)))))))))))

 

Yes as I thought.

The areBuyOrdersInProfitAt contains another OrderSelect function and it overwrites what the one in the original snippet is doing. When this areBuyOrdersInProfitAt functiopn returns, the OrderSelect is changed, so is the ticket. In this case you should always be getting the last order in your list here.

 

Once you start using OrderSelect in a for loop, going through all orders, you may not create another one OrderSelect for loop inside it, cause when the second one returns, you will be using the ticket of the last order in your trade pool.

You have quite a lengthy code there, so I don't feel much like correcting it (sry:P) but you now have a pointer in the right direction.

 
dvarrin:

But I think you've pointed the problem: I'm using OrderSelect() in the method "areBuyOrdersInProfitAt". :-)))))))))))

Good to hear you are on your way to a solution. :-)
 
RaptorUK:
Good to hear you are on your way to a solution. :-)
Thank you very much to everybody. It was really a stupid mistake I did :-((
Reason: