int Array1[5] = {1, 2, 3, 4, 5}; int Array2[8] = {22, 8, 32, 5, 15, 65, 4, 13}; int myarray[40]; int n=0; for(int x=0; x<ArraySize(Array1); x++){ for(int i=0; i<ArraySize(Array2); i++){ if(Array1[x]==Array2[i]){ myarray[n]=Array2[i]; n++; } } } ArrayResize(myarray,n,n);
thank you Naguisa Unada
it works for the first tick, but after it gives me array out of range?!!!!
//+------------------------------------------------------------------+ //| e.mq4 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict int Array1[5] = {1, 2, 3, 4, 5}; int Array2[8] = {22, 8, 32, 5, 15, 65, 4, 13}; int myarray[40]; int n=0; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick(){ for(int x=0; x<ArraySize(Array1); x++){ for(int i=0; i<ArraySize(Array2); i++){ if(Array1[x]==Array2[i]){ myarray[n]=Array2[i]; n++; } } } ArrayResize(myarray,n,n); PrintFormat("Copied array myarray size=%d",ArraySize(myarray)); for(int z=0; z<ArraySize(myarray); z++){ PrintFormat("index=%d, value=%d",z,myarray[z]); } } //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //| e.mq4 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict int Array1[5] = {1, 2, 3, 4, 5}; int Array2[8] = {22, 8, 32, 5, 15, 65, 4, 13}; int myarray[40]; int n=0; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick(){ for(int x=0; x<ArraySize(Array1); x++){ for(int i=0; i<ArraySize(Array2); i++){ if(Array1[x]==Array2[i]){ Print("N: "+n); myarray[n]=Array2[i]; n++; ArrayResize(myarray,n+1); } } } PrintFormat("Copied array myarray size=%d",ArraySize(myarray)); for(int z=0; z<ArraySize(myarray)-1; z++){ PrintFormat("index=%d, value=%d",z,myarray[z]); } } //+------------------------------------------------------------------+
my plane is to
open number of trades = x
collect its ticket number in an array
if y number of trades closed by tp or sl, and off course y is a part of x
collect its ticket numbers in an array, then deal with it one by one
ill put a code now but i cant connect it together
so if some help ill be so thankful
int No_of_Positions = 20; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick(){ if(OrdersTotal() > 0){ if(OrdersTotal() == No_of_Positions){ //copy all tickets number in an array (Pos_Orders_Ticket) if(ArrayResize(Order_Ticket, OrdersTotal()) == OrdersTotal()){ for(int x = OrdersTotal() - 1; x >= 0; x--){ if(OrderSelect(x, SELECT_BY_POS, MODE_TRADES)){ Order_Ticket[x] = OrderTicket(); }else{ Order_Ticket[x] = EMPTY; } ArrayCopy(Pos_Orders_Ticket, Order_Ticket, 0, 0, WHOLE_ARRAY); } } //now if an order closed Order_Ticket[] will change //but Pos_Orders_Ticket[] will be as it without changes }else if(OrdersTotal() < No_of_Positions){ //this case when order closed //i want here the closed orders ticket numbers //myarray[] = {ticket1 , ticket2, etc..} } } //+------------------------------------------------------------------+ //functions //collect all history order ticket number //compere it with Pos_Orders_Ticket[] //save closed orders ticket in an array, myarray[] //this function gives mye only one result but i need all closed orders int OHT(){ int a = 0; int History_Order_Ticket[1]; int Orders_History_Total = OrdersHistoryTotal(); if(ArrayResize(History_Order_Ticket, Orders_History_Total) == Orders_History_Total){ for(int x = Orders_History_Total - 1; x >= 0; x--){ if(OrderSelect(x, SELECT_BY_POS, MODE_HISTORY)){ History_Order_Ticket[x] = OrderTicket(); }else{ History_Order_Ticket[x] = EMPTY; } for(int y = 0; y < ArraySize(Pos_Orders_Ticket); y++){ if(History_Order_Ticket[x] == Pos_Orders_Ticket[y]){ a = Pos_Orders_Ticket[y]; //should save all a values in myarray[] } } } }return(a); }
i wish i explained it good
thanks for any help

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hello im working with a code using arrays
i need to save the equal values from 2 arrays to another one to use it after
i search every where but didnt found such subject
here is the code bellow
any help?
thanks in advance