The Code is working 99% properly my real Problem is the While Loop I use it that way:
while(bar<Bars-1)
But the way I need is:
while(highNumber>Close[I+1])
But when I use it that way the whole System crashes.
Pls See my full code:
//---
//Special Loop to avoid Array Out of Range
int counted_bars = IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
//int limit = Bars-counted_bars;
int limit = MathMin(Bars-3,Bars-counted_bars);
//+------------------------------------------------------------------+
//LongTrariling
for(int i=limit;i>=0;i--){
if(Close[i+1]>High[i+2]){
lastDirection = 1;
int bar=i+2;
double lowCheck=Low[bar];
while(bar<Bars-1){
if(lowCheck>Low[i+1]){
bar++;
lowCheck=Low[bar];
}else{
upStop_1[i+1]=lowCheck;
break;
}
}
//THIS IS THE PROBLEM PART THIS IS THE PROBLEM PART THIS IS THE PROBLEM PART THIS IS THE PROBLEM PART THIS IS THE PROBLEM PART THIS IST THE PROBLEM PART
}else if(Close[i+1]<High[i+2]){
lastDirection =-1;
int bar=i+2;
//Remember high of Position
double highNumber=High[i+2];
//Remember Position of Index
double lowCheck=Low[bar];
while(bar<Bars-1){
if(highNumber>Close[i+1]){
if(lowCheck>Low[i+1]){
bar++;
lowCheck=Low[bar];
}else{
upStop_1[i+1]=lowCheck;
break;
}
}
}
}else{
if(lastDirection == 1) upStop_1[i+1]=upStop_1[i+2];
if(lastDirection ==-1) upStop_2[i+1]=upStop_2[i+2];
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Pls See also the attached Picture to understand it better:
Every time when it detects another Close[I+1]<High[I+2] it starts a new sequence but it need to hold the Stop until Close[I+1]>Than the saved High[I+2]
Thats the way how I need it to work "Stay in Loop until Close[I+1] > than the saved highNumber (But when I use it that way the System crashes
elseif(Close[i+1]<High[i+2]){
lastDirection =-1;
//Save bar Index of the previous High (which is Higher than the Closei+1)int bar=i+2;
//Save high of previous Bar (which is Higher than the Closei+1)double highNumber=High[bar];
//Save and initialize Low of the previous Bar (from the Bar which High is higher than the Closei+1)double lowCheck=Low[bar];
while(Close[i+1]<highNumber){ //Stay in Loop until Close[i+1] is higher than the saved highNumberif(lowCheck>Low[i+1]){
bar++;
lowCheck=Low[bar];
}else{
upStop_1[i+1]=lowCheck;
break;
}
}
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
But the way I need is:
But when I use it that way the whole System crashes.
Pls See my full code:
//--- //Special Loop to avoid Array Out of Range int counted_bars = IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; //int limit = Bars-counted_bars; int limit = MathMin(Bars-3,Bars-counted_bars); //+------------------------------------------------------------------+ //LongTrariling for(int i=limit;i>=0;i--){ if(Close[i+1]>High[i+2]){ lastDirection = 1; int bar=i+2; double lowCheck=Low[bar]; while(bar<Bars-1){ if(lowCheck>Low[i+1]){ bar++; lowCheck=Low[bar]; }else{ upStop_1[i+1]=lowCheck; break; } } //THIS IS THE PROBLEM PART THIS IS THE PROBLEM PART THIS IS THE PROBLEM PART THIS IS THE PROBLEM PART THIS IS THE PROBLEM PART THIS IST THE PROBLEM PART }else if(Close[i+1]<High[i+2]){ lastDirection =-1; int bar=i+2; //Remember high of Position double highNumber=High[i+2]; //Remember Position of Index double lowCheck=Low[bar]; while(bar<Bars-1){ if(highNumber>Close[i+1]){ if(lowCheck>Low[i+1]){ bar++; lowCheck=Low[bar]; }else{ upStop_1[i+1]=lowCheck; break; } } } }else{ if(lastDirection == 1) upStop_1[i+1]=upStop_1[i+2]; if(lastDirection ==-1) upStop_2[i+1]=upStop_2[i+2]; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+Pls See also the attached Picture to understand it better:
Every time when it detects another Close[I+1]<High[I+2] it starts a new sequence but it need to hold the Stop until Close[I+1]>Than the saved High[I+2]
Thats the way how I need it to work "Stay in Loop until Close[I+1] > than the saved highNumber (But when I use it that way the System crashes