fly7680: I fixedthe codebut I havethe same problem...this indicatorhas toread data to thehistoricbut it does notproperly.my problem isin this line, butI do not knowwhy
N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i);
If I is 100, then you are looking at bars [104 .. 209] 106 bars. If I is 200 you are looking at bars [204 .. 409] 206 bars. Can you answer the question "What is your lookback?" No you can't.
honest_knave#6 posted part of my post to do your look back correctly I linked #7 to my post to do your look back correctly. Once you fix #1, Fix look backs correctly.
Whroeder1Thanksfor yourhelp,I do not understandhow to write this code forthe correct readingof thestroico.
//set all accessed arrays and buffers to ArraySetAsSeries(false) Not the Predefined Variables
for(int iBar = MathMax(lookback, prev_calculated; iBar < Bars; ++iBar){ // To access a Timeseries use index=Bars -1- iBar // and convert any results back index=Bars -1- result } return rates_total-1; // Recalculate current bar next tick.
//Always count up so you're not using future values.
int lookback = ... // iMA(period) has look back of period. // buffer[i+2] has look back of 2 (as TimeSeries) // buffer[i-2] has look back of 2 (not TimeSeries) // use maximum of all.
int lookback = ... // iMA(period) has look back of period.// buffer[i+2] has look back of 2 (as TimeSeries)// buffer[i-2] has look back of 2 (not TimeSeries)// use maximum of all.
set all accessed arrays and buffers to ArraySetAsSeries(false) Not the Predefined Variablesfor(int iBar = MathMax(lookback, prev_calculated; iBar < Bars; ++iBar){
// To access a Timeseries use index=Bars -1- iBar// and convert any results back index=Bars -1- result
}
return rates_total-1; // Recalculate current bar next tick.
You cannot ignore the comments. WHRoeder rarely writes something without meaning.
I suggest you use this example instead, to avoid more confusion:
Helloeveryone and thank youagainfor your comments.I did not understandwhat is the differenceif I use"i"in candlesor "i" in iHighest.I found anothersoluzuonewhich is finefor me.
if(prev_calculated < 1) limit=MathMin(5000-1, rates_total-1-50);
:
return(rates_total);
I linked #7 to my post to do your look back correctly.
Once you fix #1, Fix look backs correctly.
Whroeder1 Thanks for your help, I do not understand how to write this code for the correct reading of the stroico.
for(int iBar = MathMax(lookback, prev_calculated; iBar < Bars; ++iBar){
// To access a Timeseries use index=Bars -1- iBar
// and convert any results back index=Bars -1- result
}
return rates_total-1; // Recalculate current bar next tick.
//Always count up so you're not using future values.
// buffer[i+2] has look back of 2 (as TimeSeries)
// buffer[i-2] has look back of 2 (not TimeSeries)
// use maximum of all.
Your code has a maximum of:
&& iOpen(Symbol(), PERIOD_CURRENT, 2+i) > iClose(Symbol(), PERIOD_CURRENT, 2+i)
&& iOpen(Symbol(), PERIOD_CURRENT, 3+i) > iClose(Symbol(), PERIOD_CURRENT, 3+i)
&& iOpen(Symbol(), PERIOD_CURRENT, 4+i) < iClose(Symbol(), PERIOD_CURRENT, 4+i);
I updated the code but nothing has changed
//| 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[])
{
int limit = rates_total - prev_calculated;
int lookback= Buffer1[4];
//--- initial zero
//--- main loop
//for(int i = limit-1; i >= 0; i--)
for(int i = MathMax(lookback, prev_calculated); i < Bars; ++i)
{
double val;
int N;
bool Pattern = Open [1+i] > Close[ 1+i]
&& Open [2+i] > Close[ 2+i]
&& Open [3+i] > Close[ 3+i]
&& Open [4+i] < Close[ 4+i];
//Indicator Buffer 1
if( Pattern == true )
{
N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i);
if(N!=-1) val = High[N];
else PrintFormat("Error in call iHighest. Error code=%d. Bars=%i start=%i",GetLastError(),Bars,4+i);
Buffer1[N] = val + 30*Point;
Print("Numero Candela: "+IntegerToString(N));
}
return(rates_total-1);
}
//+------------------------------------------------------------------+
I updated the code but nothing has changed
You need to be very precise when writing code.
WHRoeder's notes say:
It does not say:
___________________
I updated the code but nothing has changed
You have chosen to use WHRoeder's final example:
You cannot ignore the comments. WHRoeder rarely writes something without meaning.
I suggest you use this example instead, to avoid more confusion:
_____________________
You still need to fix this. It is wrong, as WHRoeder explained above:
I updated the code but nothing has changed
//| 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[])
{
int limit = rates_total - prev_calculated;
int lookback = Buffer1[4];
ArraySetAsSeries(Buffer1, false);
for(int i = Bars-1-MathMax(lookback, prev_calculated); i >= 0; --i){
double val;
int N;
bool Pattern = Open [1+i] > Close[ 1+i]
&& Open [2+i] > Close[ 2+i]
&& Open [3+i] > Close[ 3+i]
&& Open [4+i] < Close[ 4+i];
//Indicator Buffer 1
if( Pattern == true )
{
N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i);
if(N!=-1) val = High[N];
else PrintFormat("Error in call iHighest. Error code=%d. Bars=%i start=%i",GetLastError(),Bars,4+i);
Buffer1[N] = val + 30*Point;
Print("Numero Candela: "+IntegerToString(N));
}
return rates_total-1;
}
You have been told many times about
but you still do nothing about it.
What are you trying to do?
break it down using some different values for i
What does it do?
really thanks to everyone for the help ... I am a beginner and some concepts can not understand them. I added this code, but still we did not.
ArraySetAsSeries(Buffer1, false);
N = iHighest(NULL,0,MODE_CLOSE,6+i,4+i);
You seem to be ignoring most of the comment people give you. You can't do that. Your code will not work.
Hello everyone and thank you again for your comments. I did not understand what is the difference if I use "i" in candles or "i" in iHighest. I found another soluzuone which is fine for me.
//| 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[])
{
int limit = rates_total - prev_calculated;
int lookback = Buffer1[4];
ArraySetAsSeries(Buffer1, true);
for(int i = Bars-1-MathMax(lookback, prev_calculated); i >= 0; --i){
bool Pattern = Open [1+i] > Close[ 1+i]
&& Open [2+i] > Close[ 2+i]
&& Open [3+i] > Close[ 3+i]
&& Open [4+i] < Close[ 4+i];
bool C4 = Close[4+i] > Close[5+i] && Close[4+i] > Close[6+i];
bool C5 = Close[5+i] > Close[4+i] && Close[5+i] > Close[6+i];
bool C6 = Close[6+i] > Close[4+i] && Close[6+i] > Close[5+i];
//Indicator Buffer 1
if( Pattern == true && C4 == true ) Buffer1[4+i] = High[4+i] + 30*Point;
if( Pattern == true && C5 == true ) Buffer1[5+i] = High[5+i] + 30*Point;
if( Pattern == true && C6 == true ) Buffer1[6+i] = High[6+i] + 30*Point;
}
return rates_total-1;
}
//+------------------------------------------------------------------+
There are still problems with your lookback, but if you're happy with how your code works, great!
I'd like to say I'm glad we helped, but I'm not entirely sure we did.