- Questions from Beginners MQL5 MT5 MetaTrader 5
- Very noob question - will delete soon
- Single array calculation during optimisation
- Off course not. you have to do it yourself.
- You could write a sort secondary array but since you said they are an array of Closing prices, just sort the indexes
#define ASCENDING +1 #define DESCENDING -1 int GetShiftsOrderByClose(int& shifts[], int iLimit, int iCurr = 0, double asc=ASCENDING){ int nShifts = iLimit - iCurr; if(ArraySize(shifts) <= nShifts) ArrayResize(shifts, nShifts); for(nShifts = 0; iCurr < iLimit; iCurr++){ double curr = Close[iCurr]; for(int iEmpty = nShifts; iEmpty > 0; iEmpty--){ // Insertion sort. int iPrev = shifts[iEmpty-1]; double prev = Close[iPrev]; if((curr - prev)*asc >= 0.) break; shifts[iEmpty] = iPrev; } shifts[iEmpty] = iCurr; nShifts++; // Insert. } }Not compiled, not tested
- Off course not. you have to do it yourself.
- You could write a sort secondary array but since you said they are an array of Closing prices, just sort the indexes
Thank you for your help. I see where you are going with this! It just seems like a lot of code to do something very simple. I just surprised that there is not more coding options for manipulating data in arrays, particularly, since most of the data used comes in an array format. Thank you again.
Thank you for your help. I see where you are going with this! It just seems like a lot of code to do something very simple. I just surprised that there is not more coding options for manipulating data in arrays, particularly, since most of the data used comes in an array format. Thank you again.
Is there a way to save data to an array that is the result of a formula going through a "for loop"? So, for each loop of it, the variable "results" is saved in the array, "Array1" at the increase index?
double Array1[];
double results;
for (int i = 0; i<someNumber; i++)
{
results = iHigh[i]-iLow[i]+ iClose[i] + iOpen[i];
Array1[i] = results;
}
Is there a way to save data to an array that is the result of a formula going through a "for loop"? So, for each loop of it, the variable "results" is saved in the array, "Array1" at the increase index?
<CODE REMOVED>
Please edit your post . . . please use the SRC button to post code: How to use the SRC button.
double Array1[];
Has a size of zero elements . . .
- Use SRC
- Use non-empty array
- That is not what you originally posted.
- Use SRC
- Use non-empty array
- That is not what you originally posted.
Thank you. That worked.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use