Hi,
I'm creating an EA that uses the:
-Stochastics (Main line);
-SMA21 on Stochastics ("First Indicators Data"),
to generate signals. The problem is that the "SMA21 on Stochastics" always return 0 , why ?
Here's an extract of the code:
int start()
{
if(!IsBarClosed(0, true)) return(0);
Main_Line[1] = iStochastic(Symbol(), Period(), 21, 3, 3, MODE_SMA, 0, MODE_MAIN, 1);
Main_Line[2] = iStochastic(Symbol(), Period(), 21, 3, 3, MODE_SMA, 0, MODE_MAIN, 2);
Main_Line[3] = iStochastic(Symbol(), Period(), 21, 3, 3, MODE_SMA, 0, MODE_MAIN, 3);
Main_Line[4] = iStochastic(Symbol(), Period(), 21, 3, 3, MODE_SMA, 0, MODE_MAIN, 4);
for(int i=0;i<5;i++)
{
MAofStochBuffer[i] = iMAOnArray(Main_Line, 0, 21, 0, MODE_SMA, i);
PrintFormat("SMA21 on first indicator: %s", DoubleToStr(MAofStochBuffer[i], 2));
}
return(0);
}
--Values printed out:
SMA21 on first indicator: 0.00
SMA21 on first indicator: 0.00
SMA21 on first indicator: 0.00
SMA21 on first indicator: 0.00
Why ? Thanks in advance.
Jo.
You should have enough elements in the first array to do calculations on.
double Main_Line[30]; double MAofStochBuffer[4]; //--- for(int i=0;i<30;i++) { Main_Line[i] = iStochastic(Symbol(), Period(), 21, 3, 3, MODE_SMA, 0, MODE_MAIN, i+1); } for(int i=0;i<4;i++) { MAofStochBuffer[i] = iMAOnArray(Main_Line, 0, 21, 0, MODE_SMA, i); PrintFormat("SMA21 on first indicator: %s", DoubleToStr(MAofStochBuffer[i], 2)); } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
This should give the same result.
for(int i=0;i<4;i++) { MAofStochBuffer[i] = iStochastic(Symbol(), Period(), 21, 21, 3, MODE_SMA, 0, MODE_SIGNAL, i+1); PrintFormat("SMA21 on first indicator: %s", DoubleToStr(MAofStochBuffer[i], 2)); }
Thanks. Indeed it was the number of elements in Array Main_Line[] that did not allow the calculation :)
Now the only issue left is: I need to compare Main_Line[2] with the value of MAofStochBuffer at shift 2:
if(Main_Line[2] < MAofStochBuffer[2] ) , but for some reason the MAofStochBuffer at shift 2 is different from the value read from the Indicator window.
Is it because the iMAOnArray populates the output Array in reverse mode ? (as per documentation).
Thanks again for the help.
Problem fixed thx.
Created a custom indicator that calculates the Stochastics and iMAOnArray on Stochastics, and read the values from the EA.
Thanks. Indeed it was the number of elements in Array Main_Line[] that did not allow the calculation :)
Now the only issue left is: I need to compare Main_Line[2] with the value of MAofStochBuffer at shift 2:
if(Main_Line[2] < MAofStochBuffer[2] ) , but for some reason the MAofStochBuffer at shift 2 is different from the value read from the Indicator window.
Is it because the iMAOnArray populates the output Array in reverse mode ? (as per documentation).
Thanks again for the help.
You're right, so it's important to have the exact amount of elements in the first array.
double Main_Line[21+4]; double MAofStochBuffer[4]; //--- for(int i=0;i<21+4;i++) { Main_Line[i] = iStochastic(Symbol(), Period(), 21, 21, 3, MODE_SMA, 0, MODE_MAIN, i); } for(int i=0;i<4;i++) { MAofStochBuffer[i] = iMAOnArray(Main_Line, 0, 21, 0, MODE_SMA, i); } PrintFormat("SMA21 on third index [2] : %s", DoubleToStr(MAofStochBuffer[2], 2)); //--- return value of prev_calculated for next call return(rates_total); }
.
- 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,
I'm creating an EA that uses the:
-Stochastics (Main line);
-SMA21 on Stochastics ("First Indicators Data"),
to generate signals. The problem is that the "SMA21 on Stochastics" always return 0 , why ?
Here's an extract of the code:
int start()
{
if(!IsBarClosed(0, true)) return(0);
Main_Line[1] = iStochastic(Symbol(), Period(), 21, 3, 3, MODE_SMA, 0, MODE_MAIN, 1);
Main_Line[2] = iStochastic(Symbol(), Period(), 21, 3, 3, MODE_SMA, 0, MODE_MAIN, 2);
Main_Line[3] = iStochastic(Symbol(), Period(), 21, 3, 3, MODE_SMA, 0, MODE_MAIN, 3);
Main_Line[4] = iStochastic(Symbol(), Period(), 21, 3, 3, MODE_SMA, 0, MODE_MAIN, 4);
for(int i=0;i<5;i++)
{
MAofStochBuffer[i] = iMAOnArray(Main_Line, 0, 21, 0, MODE_SMA, i);
PrintFormat("SMA21 on first indicator: %s", DoubleToStr(MAofStochBuffer[i], 2));
}
return(0);
}
--Values printed out:
SMA21 on first indicator: 0.00
SMA21 on first indicator: 0.00
SMA21 on first indicator: 0.00
SMA21 on first indicator: 0.00
Why ? Thanks in advance.
Jo.