Hello all, this is a follow up to my previous question and the feedback provided by @PaulMF. I am attempting indicator parameter optimization in order to find the most suitable inputs for trading the RSI indicator. So for the indicator, we have...
The objective is to maximize the number of net wins (NET_WINS) by adjusting the Timeframe, Period, and Applied Price of the RSI. My thinking is to create 4 arrays, with 3 of them containing the parameter constraints and the 4th one having the results. The optimal parameters would then be the ones that maximize the net wins.
My thinking was something along the line of
I would then use array maximum on the Results_array to find the parameters with the highest net wins. My question are;
1. Can using multiple loops as shown above work ?
2. Is there a more efficient way of looping through all the parameter arrays?
3. How many dimensions would the Results_array need since the parameter arrays are of different sizes?
4. What would be the size of the Results_array?
I will appreciate any help on this and will be much grateful for any code (pseudo code included) that would lead to a successful resolution.
Inserted Code
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]){
double GOOD_TRADE=0, BAD_TRADE=0, NO_TRADE=0, NET_WINS;
static int limit;
static int i;
limit = rates_total - prev_calculated;
if(prev_calculated == 0)
limit -= 15;
else if(limit > 0)
limit++;
//---- indicator calculation
for(i=limit; i>=0; i--)
{
rsi[i]=iRSI(NULL,0,14,PRICE_CLOSE,i);
}
for(i=limit; i>=0; i--)
{
if(rsi[i+2] < 70 && rsi[i+1] > 70 && iClose(NULL,0,i) < iOpen(NULL,0,i)) {GOOD_TRADE++;} // Good sell
if(rsi[i+2] > 30 && rsi[i+1] < 30 && iClose(NULL,0,i) > iOpen(NULL,0,i)) {GOOD_TRADE++;} // Good buy
if(rsi[i+2] < 70 && rsi[i+1] > 70 && iClose(NULL,0,i) > iOpen(NULL,0,i)) {BAD_TRADE++;} // Bad sell
if(rsi[i+2] > 30 && rsi[i+1] < 30 && iClose(NULL,0,i) < iOpen(NULL,0,i)) {BAD_TRADE++;} // Bad buy
if(rsi[i+2] < 70 && rsi[i+1] > 70 && iClose(NULL,0,i) == iOpen(NULL,0,i)) {NO_TRADE++;} // NIL sell
if(rsi[i+2] > 30 && rsi[i+1] < 30 && iClose(NULL,0,i) == iOpen(NULL,0,i)) {NO_TRADE++;} // NIL buy
}
NET_WINS = GOOD_TRADE - BAD_TRADE - NO _TRADE; The objective is to maximize the number of net wins (NET_WINS) by adjusting the Timeframe, Period, and Applied Price of the RSI. My thinking is to create 4 arrays, with 3 of them containing the parameter constraints and the 4th one having the results. The optimal parameters would then be the ones that maximize the net wins.
My thinking was something along the line of
Inserted Code
int TimeFrame_array[5]={60, 240, 1440, 10080, 43200};
int Period_array[100]={2,3,4,5,6,...,102};
int Price_array[7] = {
0, // close
1, // open
2, // high
3, // low
4, // median
5, // typical
6, // weighted
};
double Results_Array[]; // uncertain about array size and dimensions
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]){
double GOOD_TRADE=0, BAD_TRADE=0, NO_TRADE=0, NET_WINS;
static int limit;
static int i, j, k, l;
limit = rates_total - prev_calculated;
if(prev_calculated == 0)
limit -= 15;
else if(limit > 0)
limit++;
//---- indicator calculation
for(i=limit; i>=0; i--)
{
for(j=0;j<ArraySize(Timeframe_array);j++)
{
for(k=0;k<ArraySize(Period_array);k++)
{
for(l=0;l<ArraySize(Price_Array);l++)
{
rsi[i]=iRSI(NULL,Timeframe_array(j),Period_array(k),Price_array(l),i);
}
}
}
}
}
for(i=limit; i>=0; i--)
{
for(j=0;j<ArraySize(Timeframe_array);j++)
{
if(rsi[i+2] < 70 && rsi[i+1] > 70 && iClose(NULL,Timeframe_array(j),i) < iOpen(NULL,Timeframe_array(j),i)) {GOOD_TRADE++;} // Good sell
if(rsi[i+2] > 30 && rsi[i+1] < 30 && iClose(NULL,Timeframe_array(j),i) > iOpen(NULL,Timeframe_array(j),i)) {GOOD_TRADE++;} // Good buy
if(rsi[i+2] < 70 && rsi[i+1] > 70 && iClose(NULL,Timeframe_array(j),i) > iOpen(NULL,Timeframe_array(j),i)) {BAD_TRADE++;} // Bad sell
if(rsi[i+2] > 30 && rsi[i+1] < 30 && iClose(NULL,Timeframe_array(j),i) < iOpen(NULL,Timeframe_array(j),i)) {BAD_TRADE++;} // Bad buy
if(rsi[i+2] < 70 && rsi[i+1] > 70 && iClose(NULL,Timeframe_array(j),i) == iOpen(NULL,Timeframe_array(j),i)) {NO_TRADE++;} // NIL sell
if(rsi[i+2] > 30 && rsi[i+1] < 30 && iClose(NULL,Timeframe_array(j),i) == iOpen(NULL,Timeframe_array(j),i)) {NO_TRADE++;} // NIL buy
}
}
NET_WINS = GOOD_TRADE - BAD_TRADE - NO _TRADE;
Results_array[i] = NET_WINS; I would then use array maximum on the Results_array to find the parameters with the highest net wins. My question are;
1. Can using multiple loops as shown above work ?
2. Is there a more efficient way of looping through all the parameter arrays?
3. How many dimensions would the Results_array need since the parameter arrays are of different sizes?
4. What would be the size of the Results_array?
I will appreciate any help on this and will be much grateful for any code (pseudo code included) that would lead to a successful resolution.