SELLLIMIT & BUYLIMIT Orders - Reopening Issue - page 2

 
ubzen:

I'm gonna make a wild guess and say that your ExistOrdersByPrice() is failing because of a Price != Price issue. Again this is just a guess as I'm not seeing whats within the function. In general, you'll want to use better debugging techniques. If its getting OK from an if statement || function() which it shouldn't, then you'll want to isolate the function or statement ... with more Print Commands.

If thats not the problem then sorry. Post more of your functions so I wouldn't have to guess whats inside.


Thanks for help ubzen. Above (https://www.mql5.com/en/forum/147106) is the code where the Expert set the SELLLIMIT and BUYLIMIT orders. The Expert works fine in general, the only thing I would like to change is to place the limit orders only above or below the last SELL or BUY open order.

SELLLIMIT: above the highest SELL open order
BUYLIMIT: below the lowest BUY open order

 
af1:

Here is the part of the code where the Expert set SELLIMIT and BUYLIMIT orders.

The Expert set 10 SELLLIMIT orders above the Price Level, and set 10 BUYLIMIT orders below the Price Level.

Based on that, the Expert allways keep 10 limit orders ready for each side, and that is fine. I just want to change the price level where the Expert set the first limit orders for both sides.

In simpler words,
SELLLIMIT orders should be set above the highest SELL opened order.
BUYLIMIT orders should be set below the lowest BUY opened order.


I didn't ask for the part where the EA set SELLIMIT and BUYLIMIT orders.

I was asking for the part where you can find how many trades you have open each OrderType()

and where you can find your levels......

A SELLIMIT can become a SELL then you have to know new amount of SELLIMIT trades

and what that moment is your highest orderopenprice selllimittrade

only if you do it that way you can open new selllimit trade at the right level

I don't see the line of code i gave that is inside the loop checking trades

.....

 
af1: Thanks for help ubzen. Above is the code where the Expert set the SELLLIMIT and BUYLIMIT orders. The Expert works fine in general, the only thing I would like to change is to place the limit orders only above or below the last SELL or BUY open order.

SELLLIMIT: above the highest SELL open order
BUYLIMIT: below the lowest BUY open order

What I do is create a function which returns the Price of the Highest Open Sell Order. Then Pending Order price would equal that price + gap_size or whatever.
 
deVries:


I didn't ask for the part where the EA set SELLIMIT and BUYLIMIT orders.

I was asking for the part where you can find how many trades you have open each OrderType()

and where you can find your levels......

A SELLIMIT can become a SELL then you have to know new amount of SELLIMIT trades

and what that moment is your highest orderopenprice selllimittrade

only if you do it that way you can open new selllimit trade at the right level

I don't see the line of code i gave that is inside the loop checking trades

.....


I'm really not sure where is that part, the code is very large. But here is attached the expert.

 
ubzen:
What I do is create a function which returns the Price of the Highest Open Sell Order. Then Pending Order price would equal that price + gap_size or whatever.

ubzen, I have no experience at coding. I only know the basics. Here (https://www.mql5.com/en/forum/147106/page2#847580) is the EA so we can speak the same language. Maybe you could help me to add that function. If not I also appreciate your time. Thanks!.
 

I haven't solved the issue yet. I hope this explain better. If anyone could help, thanks in advance!

At the start, the expert opens 10 SELLLIMIT and 10 BUYLIMIT orders.That's OK.

Then the price goes down and the BUYLIMIT orders #11, 12, 13 and 14, become BUY orders. And the Expert detects that there are only 6 BUYLIMIT orders left, so to complete 10 orders, opens 4 BUYLIMIT orders more, #21, 22, 23 and 24. That's OK.

The problem is when the price return (goes up), the Expert set another BUYLIMIT (#25), at the same price of BUY #14.


If I had closed the order #14, the order #25 will be welcomed, but not before. This is I would like to fix.

Thanks again for any idea. Here is the EA

 

I'm not sure exactly what you are trying to accomplish with a chart full of pending orders.. when you can simply place the next one as the orders get filled but that's beside the point.

It seems that all you need to do before you place a selllimit is to loop through your open sell trades and look at the OrderOpenPrice() of each and come up with the highest one. Then make a rule that you can only place a selllimit above that price... for instance you have open sell trades (filled pending selllimit orders) at 1.35,1.36,1.37.... as it comes down it can not place a selllimit unless it is above 1.37.. in fact do not even check about the need to place a new pending order unless it is above the HighestSellPosition() or below the LowestBuyPosition()

as it comes down the 1.37 position will take profit.. then the 1.36 and the 1.35.. as it does.. the spot for a sell limit above moves down.. until let's say it does not takeprofit on the 1.35 but gives a slight bounce up to 1.3501.. siince it's the highest sell position open.. it will place a sell limit above at 1.36.... any way you can play with the idea.. in the meantime here are some functions you can try and use..PipPip... Jimdandy.

double HighestSellPosition()

{

double HighestOpenPrice=0.0;

for (int cnt=OrdersTotal()-1; cnt >= 0; cnt--)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if(OrderMagicNumber()!= MagicNumber || OrderType()!=1 || !OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))

continue;

if(OrderOpenPrice()>HighestOpenPrice)

HighestOpenPrice=OrderOpenPrice();

}

return(HighestOpenPrice);

}

double LowestBuyPosition()

{

double LowestOpenPrice=0.0;

for (int cnt=OrdersTotal()-1; cnt >= 0; cnt--)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if(OrderMagicNumber()!= MagicNumber || OrderType()!=0 || !OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))

continue;

if(LowestOpenPrice==0.0)

LowestOpenPrice=OrderOpenPrice();

if (OrderOpenPrice()<LowestOpenPrice)

LowestOpenPrice=OrderOpenPrice();

}

return(LowestOpenPrice);

}

 

Play video
Please edit your post.
For large amounts of code, attach it.

 
Jimdandy:



With your code you do twice a orderloop while you can do this also with using it one time at most a tick

it is also needed that you count all trades of the different OrderType()

 
Jimdandy:

I'm not sure exactly what you are trying to accomplish with a chart full of pending orders.. when you can simply place the next one as the orders get filled but that's beside the point.

It seems that all you need to do before you place a selllimit is to loop through your open sell trades and look at the OrderOpenPrice() of each and come up with the highest one. Then make a rule that you can only place a selllimit above that price... for instance you have open sell trades (filled pending selllimit orders) at 1.35,1.36,1.37.... as it comes down it can not place a selllimit unless it is above 1.37.. in fact do not even check about the need to place a new pending order unless it is above the HighestSellPosition() or below the LowestBuyPosition()

as it comes down the 1.37 position will take profit.. then the 1.36 and the 1.35.. as it does.. the spot for a sell limit above moves down.. until let's say it does not takeprofit on the 1.35 but gives a slight bounce up to 1.3501.. siince it's the highest sell position open.. it will place a sell limit above at 1.36.... any way you can play with the idea.. in the meantime here are some functions you can try and use..PipPip... Jimdandy.

<CODE REMOVED>


Please . . . edit . . . . your post . . . please use the SRC button to post code: How to use the SRC button.

Reason: