Help Me, How Script to Filter Profit Open Position - page 2 12 New comment Keith Watford 2021.05.31 01:19 #11 asror bersemi: still get solution, i have not right code now Despite repeated requests, you have not edited and inserted your code correctly so i have deleted your code. Derry Putra 2021.05.31 01:23 #12 asror bersemi: this my code : <Deleted. Edit your post and format your code properly using the "Alt-S" or by clicking the code Icon "</>" in the posting toolbar.> but cant work for read 4 from 10 buys position with highest profit double profit4buy() { int tt=0; double prf4buy=0; //for(i=OrdersTotal()-1; i>=0; i--) for(i = 0; i <=4; i++) if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { tt++; if(tt<=4) prf4buy+=OrderProfit()+OrderSwap()+OrderCommission(); } } return(prf4buy); } Keith Watford 2021.05.31 01:34 #13 asror bersemi: Now try using the suggestions that Fernando made in post #4 and post your new code. Derry Putra 2021.05.31 13:59 #14 Keith Watford: Now try using the suggestions that Fernando made in post #4 and post your new code. still trial code, not yet fix Derry Putra 2021.06.03 04:43 #15 Keith Watford: Now try using the suggestions that Fernando made in post #4 and post your new code. void OnTick() { int x=0; double trades[]; int total=OrdersTotal(); if(total>0) { ArrayResize(trades,total); for( x=0; x<total; x++) { if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES==true)&&OrderType()==0 && OrderSymbol()==Symbol()) trades[x]=OrderOpenPrice(); Print( "No : " ,x, " " , DoubleToStr(trades[x],5)); // just for print, not yet sorted } } ArraySort(trades,WHOLE_ARRAY,0,MODE_ASCEND); Comment ("\n", " price 4 : " ,DoubleToStr(trades[3],5), "\n", " price 3 : " ,DoubleToStr(trades[2],5), "\n", " price 2 : " ,DoubleToStr(trades[1],5), "\n", " price 1 : " ,DoubleToStr(trades[0],5) ); } I think now is ok.. Files: sorted.jpg 181 kb Derry Putra 2021.06.03 18:43 #16 Fernando Ca Fernando Carreiro: Use "OrdersTotal()" to obtain the count of currently open positions. Create an array of this maximum size base on the above count Create an index variable for the array and set it to an initial value of "0". Loop through all the open positions using "OrderSelect()" to select them. Filter by symbol "OrderSymbol()", magic number "OrderMagicNumer()" and if necessary, by type "OrderType()". Obtain the profit for the position using "OrderProfit()". Save the profit value in the array at the current array index, and increment the array index variable. After the loop is concluded, sort the array, in descending order with with "ArraySort()", based on the count obtained from the array index variable. Create a new variable for the total profit and set it to an initial value of "0.00". Loop through the first 4 (or less based on array index count) elements of the array, and add the value to the total profit varia int x=0; double trades[][2]; double tiket=0; int total=OrdersTotal(); if(total>0) { ArrayResize(trades,total); for( x=0; x<total; x++) { if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES==true)&&OrderType()==0 && OrderSymbol()==Symbol()) trades[x][0]=OrderOpenPrice(); trades[x][1]=OrderTicket(); } } ArraySort(trades,WHOLE_ARRAY,0,MODE_ASCEND); if (x==0) tiket=((int)trades[x][1]); hello Fernando, i have problem with Array.. the message " Array Out Of Range with code " at this code,, can you explain to me?.. thank you if (x==0) tiket=((int)trades[x][1]); 12 New comment
still get solution, i have not right code now
Despite repeated requests, you have not edited and inserted your code correctly so i have deleted your code.
this my code :
<Deleted. Edit your post and format your code properly using the "Alt-S" or by clicking the code Icon "</>" in the posting toolbar.>
but cant work for read 4 from 10 buys position with highest profit
Now try using the suggestions that Fernando made in post #4 and post your new code.
Now try using the suggestions that Fernando made in post #4 and post your new code.
still trial code, not yet fix
Now try using the suggestions that Fernando made in post #4 and post your new code.
I think now is ok..
hello Fernando, i have problem with Array.. the message " Array Out Of Range with code " at this code,, can you explain to me?.. thank you