Track and control both the total number of open tickets/account and the number of each specific open Order Symbol/Instrument(types?)
I need to maintain the number of open market orders, and perhaps eventual pending orders as well, by each instrument symbol that are currently active and open.
This needs to persist past each new tick and only gets altered when a specified symbol is closes and/or opens.
I'm contemplating the usage of the 'switch......, case......'
just control the number of orders that will be open at any one time (for each instrument symbol so that other pairs can open as well) and for the entire account so that it doesn't get 'stopped out'.
would be a lot more efficient and quicker than having to cycle through the whole stack of open orders every time (wouldn't it)?- OK, so code it.
- Why does it need to persist. The list of open orders already exists and has been updated before each tick.
- Huh?
- Stopped out can happen with one order or never with a 1000. All depends on account size and SL. See here
- Efficiency is irrelevant. The list of open orders already exists, all you need to do it look at it.
string pair.name[]; int pair.count[]; int OrderSelectByPairs(){ int nPairs = 0; for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--) if( OrderSelect(iPos, SELECT_BY_POS) // Only my orders w/ // && OrderMagicNumber() == magic.number // my magic number // && OrderSymbol() == chart.symbol // and my pair. ){ string chartSymbol = OrderSymbol(); for(int iPair=0; iPair < nPairs; iPair++) if (pair.name[iPair] == chartSymbol){ pair.count[iPair]++; break; // In the list-increment } if (iPair == nPair){ // Not in list-add. ArrayResize(pair.name, nPair+1); pair.name[nPair] = chartSymbol; ArrayResize(pair.count, nPair+1); pair.count[nPair] = 1; nPair++; } } // Open Orders return(nPairs); } int OrdersTotalByPair(string pair){ for(int iPair=ArraySize(pair.name) - 1; iPair >= 0; iPair--) if (pair.name[iPair] == pair) return(pair.count[iPair]); return(0); } //////////////////////////////////////////////////////////////////////////////// int start(){ int nPairs = OrderSelectByPairs(); Print("EURUSD as ", OrdersTotalByPair("EURUSD"),"/",nPairs, " open orders"); : }Not compiled, not tested.
- OK, so code it.
- Why does it need to persist. The list of open orders already exists and has been updated before each tick.
- Huh?
- Stopped out can happen with one order or never with a 1000. All depends on account size and SL. See here
- Efficiency is irrelevant. The list of open orders already exists, all you need to do it look at it.
Not compiled, not tested.
Hi WHR:
Just making a quick pass through: will look at it more later and try some of the coding you suggested:
2 & 5: I want to determine if an 'opening' even exists (for a specific) pair before I start testing for it to see if the conditions are valid to place an order (with that pair). If there is no possibility open, I don't want to use the time or resources to bother finding out if the correct conditions exist that would be favorable to open a new order for that specific pair if there is no room to place it on an overall, broader scale anyway.
4: I have is so that lot size can be and is determined dynamically by both the equity and the current SL level. However so far, it is only taking that into account for each individual order but in trading as opposed to testing it just keeps placing orders if conditions are right for that one order but regardless of if the account is getting over extended and could end up getting stopped out. I know: Add a logic test for the account becoming over extended. Most of my concern is that I want to limit the number of orders that each pair can and will open so that it leaves spaces open for other pairs to trade if the conditions become favorable them. Not real clear yet on A) the validity of this specific approach in the first place. But as this EA is meant for the trade to stay open for quite some time IF it is profitable but close out at a very low SL otherwise. Hence my desire to only have a limited number of trades, likely one, for any pair open at any one time.
Overall, I understand: 'OK, So CODE it!' It back tests very nicely, but when forward tested, it starts opening up multiple orders on one pair, which I don't want; and on many different pairs, which I do want: but within limitations of the number of orders per pair and per account. My question is more along the lines of the approach to utilize to determine if the conditions exist for another order to be placed BEFORE checking logic conditions for that specific order in the cases of:
1) Can the account handle any more orders of any pair? Does this HAVE have to be checked each time as it occurs to make sure I don't get over extended and stopped out or can I have this predetermined which is preferable.
2) But if there is the possibility of say placing a USDCAD order, I want to track and know this from the outset rather than figuring out if the conditions to place the USDCAD order are valid only to THEN discover that the account, &/or this pair can not handle any more orders being opened regardless. This is why I want to track and know going into it so that is these possibilities are not currently available, I don't waste time and computer resources figuring it out only to find out it can't be made anyway.
A I may have 20 charts open in just one EA and have other EAs doing similar as well. Time and resources do become very important. Especially as I also want to make VERY time sensitive trades such as occur in news trading &/or constant real time monitoring for sudden significant breakouts where parts of a second, let alone seconds, can make a VERY significant difference! So another EA having the computer tied up &/or bogged down for a few seconds needlessly that hopefully with diligence I can avoid, can make the difference between making or not making or even losing significant profits. So the overall flow chart and algorithm do become quite important.
Please do not feed the troll.
When you respond, you give the troll power. When you ignore the troll, he starves for attention and eventually dies.
- OK, so code it.
- Why does it need to persist. The list of open orders already exists and has been updated before each tick.
- Huh?
- Stopped out can happen with one order or never with a 1000. All depends on account size and SL. See here
- Efficiency is irrelevant. The list of open orders already exists, all you need to do it look at it.
Not compiled, not tested.
Hi WHR,
Thanks for your help.
This is a simple MA Cross utilizing an OCO. My coding below of your code is (hopefully the almost finished) 'half' of the OCO
I haven't worked out what and why the OrdersTotalByPair() function is yet nor how it fits in, so I haven't included it as of yet.
Below is what I have done so far and it compiles and back tests OK and has only one order open at a time, but then so does the original in the BT. However the quantity is adjustable and when MaxOrders is at 2, it still only does 1 order at a time in BT so ??? I'll forward test it and see what we have so far:
// Code from https://forum.mql4.com/50210 by >>> https://www.mql5.com/en/users/whroeder to limit number of orders per pair/chart // Order Arrays: string pair.name[]; int pair.count[]; int OrderSelectByPairs() { int nPairs = 0; for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--) if(OrderSelect(iPos, SELECT_BY_POS) // Only my orders w/) && OrderSymbol() == pair.name[iPos]) // <<<<< ?????? ....chartSymbol) // and my pair. // && OrderMagicNumber() == magic.number // my magic number { string chartSymbol = OrderSymbol(); for(int iPair=0; iPair < nPairs; iPair++) if (pair.name[iPair] == chartSymbol) { pair.count[iPair]++; if(pair.count[iPair] > i_MaxTradesPerSymbol) break; // If the new order is in the Array list of exsisting orders: // increment the 'iPos' counter and if the allowed number of exsisting orders // > i_MaxTradesPerSymbol, break out of the counter loop for placing new orders for this Pair } else if (iPair == nPairs) // else if not in the Array list, add an order for this pair.name { ArrayResize(pair.name, nPairs+1); pair.name[nPairs] = chartSymbol; ArrayResize(pair.count, nPairs+1); pair.count[nPairs] = 1; nPairs++; } } // Open Orders return(nPairs); } /* int OrdersTotalByPair(string pair) { for(int iPair=ArraySize(pair.name) - 1; iPair >= 0; iPair--) if (pair.name[iPair] == pair) return(pair.count[iPair]); return(0); } */ //////////////////////////////////////////////////////////////////////////////// int start() { ......... ................. ......................... // Open BUY orders if havn't exceeded the limit if(OrderSelectByPairs() < i_MaxTradesPerSymbol)
{ while(IsTradeContextBusy()) Sleep(10); RefreshRates(); BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,UseSlippage,0,0, s_Comment,i_MagicNumber, 0, Lime); // Error handling {
I forgot that you are a troll and a thief and shouldn't have tried to help you again. My bad
Please do not feed the troll.
When you respond, you give the troll power. When you ignore the troll, he starves for attention and eventually dies.
LoL WH
That's a bum rap that I don't deserve WH
Initially I didn't want to learn how to program MQL4. In theory there are lots of others around that are already doing it, and there are. I should know, I must of bought at least a hundred so called 'commercial' EAs till I finally gave up on that route. The only one that makes any money on 99+% of them are those that make and or market and sell them. These rip offs 'scams' have the dubious distinction of having the highest return rate of any and all digital download products globally for numerous years )< 8(
So reluctantly I finally gave into what I finally accepted as the inevitable and like the rest of you here, and hopefully like MANY others before me, with the significant help of others such as yourself.
But I'm certainly no thief WH et al and most definitely resent that accusation.
As to the 'Troll' part. I'm not exactly sure what connotation folks here are using for it, but it obliviously 'arn't gud' I don't think I rate the rank for that one. (< 8)
So it's FINALLY onward and upward with MQL4 for me WH et al. But you have to admit, I DID hold out for a LONG time! I do likely have and certainly 'earned' the dubious distinction of being the 'longest running/ longest term MQL4 NuB' around. LoL Ah well. Hopefully better late than never! (< 8)
int OrdersTotalByPair(string pair) { for(int iPair=ArraySize(pair.name) - 1; iPair >= 0; iPair--) if (pair.name[iPair] == pair) return(pair.count[iPair]); return(0); }
How can there be two 'return' statements to one function WH? How does this work ?
How can there be two 'return' statements to one function WH? How does this work ?
I don't think you should expect a reply from WHRoeder.
I added some braces to help you "see" . . .
int OrdersTotalByPair(string pair) { for(int iPair=ArraySize(pair.name) - 1; iPair >= 0; iPair--) { if (pair.name[iPair] == pair) { return(pair.count[iPair]); } } return(0); }
. . . the braces are not needed in this case, you can get into troubles not using them if you use else though . . .
I don't think you should expect a reply from WHRoeder.
I added some braces to help you "see" . . .
. . . the braces are not needed in this case, you can get into troubles not using them if you use else though . . .
Hi Raptor,
Did the smell test and seemed OK, but I got the Brillo pads out and scrubbed the ol hide raw just to be on the safe side anyway. My cat tries to keep up with the job, but very thankfully, his tongue isn't anywhere near big enough. Friggin Diamond rasps those things are! I can see how they can lick absolutely everything off right clean down to the bone. But I won't hold that still for him unless I completely stop waking up before he does. With a pet door and no dogs at this point in time, if I do pass on before he does, all the cats in the whole neighborhood might have quite a feast though. But no stinky VOC parfummess, nor formaldehyde for that matter either, for this cat either way though! (< 8)
Meanwhile, back at the ranch:
I see. if the first 'if(statement)' isn't true, it's going to ignore the first return() statement anyway.
Thanks.
I did use the odd else in WH's code just to clarify the logic a bit for me while finally learning this stuff. It's good not to forget about 'else' entirely as one can still put it to good use it without the 'if' at times anway.
/
So are you close enough that you are gong to get caught up in the 'Olympics' crush'?
Think your 2 wheeled monster will be able to 'Bring Home the Gold' for England? LoL
Hope all you folks don't keep getting totally drowned throughout the entire 'rings' fest.
Either way, Enjoy
Contemplating making it 'MaxOrdersPerChart' instead of 'Max...Symbol' as I do have more than one chart with the same pair open at times and want to have the option of using different settings for Long & Short available. Not sure how I would do it though. The MagicNumber is an obvious option. But I don't tend to use it to much. The actual order number must be available, though I don't think it would be the way to go in this situation: just make it more cumbersome. Good to bring these to mind when learning though.
Not sure I really need to set arrays for the purposes been looking at here. Could just use the default Open Orders list/pool [Array?] and check it 'for' the order type and pair that I want.
More than one way to skin a cat(fish). 6 of 1.....
When you respond, you give the troll power. When you ignore the troll, he starves for attention and eventually dies.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to maintain the number of open market orders, and perhaps eventual pending orders as well, by each instrument symbol that are currently active and open. This needs to persist past each new tick and only gets altered when a specified symbol is closes and/or opens. I'm contemplating the usage of the 'switch......, case......' operators for this and just have a global variable for each pair and the number of open orders for each pair.
Basically all I am trying to do is control the number of open orders both per symbol instrument & account. I may have two charts per symbol open at the same time: one for long Buy orders parameters and the other for Short Sell Orders. But these 2 separate buy/sell charts are a secondary consideration at this point in time. All I really want to do is just control the number of orders that will be open at any one time (for each instrument symbol so that other pairs can open as well) and for the entire account so that it doesn't get 'stopped out'. I want to be able to control the number of trades per chart to that a couple don't fill it up and not leave room for other pairs to trade. There must be numerous ways to do this including a lot simpler than my initial example than the use of the switch......., case ..... operators that I am contemplating.
All I really need to do is to go through the list of open & pending?) orders and either place it or not if my limit for that symbol pair has been reached. This will likely be one per pair, but I want the flexibility to allow for other quantities. But already having and maintaining a constant list of open pairs and only change it when an order is open or closed would be a lot more efficient and quicker than having to cycle through the whole stack of open orders every time (wouldn't it)? I want to keep everything as quick and as efficient as possible.
Thanks for any and all assistance. (< 8)