Hi,
Can someone help me with a simple matrix operation?
Here, I have built a matrix of all open orders. I have sorted them from the most loss-making to the most profitable.
Now, I take the most losing order and check if the profitable orders are able to compensate it with a small profit. It seems simple but it does not work for me.
Please give me a hint.
orders array:
Now, I want to check if element mypool[0,0] can be compensated by: mypool[count-1,0] or maybe SUM= mypool[count-1,0] + mypool[count-2,0] or maybe bigger SUM (three elements)
I tried something like this:
but it doesn't work. What is wrong? I can see/print the 'count', I can see every element of this array but I can't see or print 'SUM'
Then I wanted to close the orders pointed by 'index' and of course the first one.
Like this:
I would be very grateful for any help. We have a weekend coming up so I'm glad to be able to spend time on the problem but without help I'm not going to move forward.
Regards
Kris
I haven't tried this piece of code. But I'll try once the system boots up.
//+------------------------------------------------------------------+ //| KarZararKarsilaEA.mq4 | //| Copyright 2019, Haskaya Software | //| https://www.haskayayazilim.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, Haskaya Software" #property link "https://www.haskayayazilim.net" #property version "1.00" #property strict input double SmartProfit=40; input int magic=99243; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- CloseCompareOrders(); } //+------------------------------------------------------------------+ void CloseCompareOrders() { int ticketOld=0,ticketNew=0; double ProfitOld=0,ProfitNew=0; for( int pos = OrdersTotal() - 1; pos >= 0; pos-- ) { if( OrderSelect( pos, SELECT_BY_POS ) ) { if(OrderSymbol()==Symbol() && OrderType()<2 && OrderMagicNumber()==magic) { ticketOld = OrderTicket(); ProfitOld = OrderProfit()+OrderCommission()+OrderSwap(); } } /////////////// for( int posnewx = OrdersTotal() - 1; posnewx >= 0; posnewx-- ) { if( OrderSelect( posnewx, SELECT_BY_POS ) ) { if(ticketOld!=OrderTicket() && OrderSymbol()==Symbol() && OrderType()<2 && OrderMagicNumber()==magic) { ticketNew = OrderTicket(); ProfitNew = OrderProfit()+OrderCommission()+OrderSwap(); if(ProfitOld+ProfitNew>SmartProfit) { OrderCloseBySmartProfit(ticketOld,ticketNew); break; } } } } } } void OrderCloseBySmartProfit(int ticketOld,int ticketNew) { bool OrderCloseResult; for( int pos = OrdersTotal() - 1; pos >= 0; pos-- ) { if( OrderSelect( pos, SELECT_BY_POS ) ) { if(OrderType()<2 && (OrderTicket()==ticketOld || OrderTicket()==ticketNew)) { OrderCloseResult=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(), 9999, clrNONE ); } } } }
Hi Mehmet,
You present a different idea. Your code will find any two orders whose total profit is higher than the assumed one. Also interesting, but not as effective.
My idea is to compensate the worst order by the sum of the good ones. In this way I get rid of the most losing orders and make room for new ones.
Thank you for your post.
Regards
Hi Dominik,
Tank you for join. Your idea is interesting but quite complicated.
Have a look:
all my orders are placed and sorted by profit in one array.
Now I take the biggest looser (-7) and I start to count the SUM of winners, starting from the greatest winner (5).
In this case I need two orders to compensate the looser (-7+5+3>0), so I am closing Orders 0, 5,6 - done.
Now I have something like this:
and now I can't compensate -5 (with small profit), so I am waiting for next orders to be open.
size of the array is dynamic but the bigest looser is always at position 0 - first one.
It should be easy to program but I stuck :)
Regards
Kris
Hi Dominik,
Tank you for join. Your idea is interesting but quite complicated.
Have a look:
all my orders are placed and sorted by profit in one array.
Now I take the biggest looser (-7) and I start to count the SUM of winners, starting from the greatest winner (5).
In this case I need two orders to compensate the looser (-7+5+3>0), so I am closing Orders 0, 5,6 - done.
Now I have something like this:
and now I can't compensate -5 (with small profit), so I am waiting for next orders to be open.
size of the array is dynamic but the bigest looser is always at position 0 - first one.
It should be easy to program but I stuck :)
Regards
Kris
The sample data does not match what you wrote. I made an EA similar to this in 2003. If I can find it, I will send it to you. I think the result will not change. it will only create psychological joy.
In market orders, as the profit increases, the loss decreases, while the loss increases, the profit decreases.
Hi Dominik,
Tank you for join. Your idea is interesting but quite complicated.
Have a look:
all my orders are placed and sorted by profit in one array.
Now I take the biggest looser (-7) and I start to count the SUM of winners, starting from the greatest winner (5).
In this case I need two orders to compensate the looser (-7+5+3>0), so I am closing Orders 0, 5,6 - done.
Now I have something like this:
and now I can't compensate -5 (with small profit), so I am waiting for next orders to be open.
size of the array is dynamic but the bigest looser is always at position 0 - first one.
It should be easy to program but I stuck :)
Regards
Kris
I understood correctly, the screen shape is attached.
Hi Mehmet,
I can see that you're interested in the problem:)
Actually, after closing Orders 0, 5,6 I let the EA to play and open new positions till next big looser (here -5) can be compensated.
This is what I got on 5M EURUSD 2021 - Jan-till now,
As an entry signal I use RSI period 6, levels 20/80
The only problem is that I wrote all this procedure 'manually' and I can check only four winners.
Regards
Kris
- 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,
Can someone help me with a simple matrix operation?
Here, I have built a matrix of all open orders. I have sorted them from the most loss-making to the most profitable.
Now, I take the most losing order and check if the profitable orders are able to compensate it with a small profit. It seems simple but it does not work for me.
Please give me a hint.
orders array:
Now, I want to check if element mypool[0,0] can be compensated by: mypool[count-1,0] or maybe SUM= mypool[count-1,0] + mypool[count-2,0] or maybe bigger SUM (three elements)
I tried something like this:
but it doesn't work. What is wrong? I can see/print the 'count', I can see every element of this array but I can't see or print 'SUM'
Then I wanted to close the orders pointed by 'index' and of course the first one.
Like this:
I would be very grateful for any help. We have a weekend coming up so I'm glad to be able to spend time on the problem but without help I'm not going to move forward.
Regards
Kris