Der Code funktioniert bereits zu 99%, das Problem ist die "While()" Loop.
Wie nutze ich die While Loop?:
Wie benötige ich die While Loop?:
Code:
while(highNumber>Close[I+1])
Aber wenn ich sie wie benötigt nutzen möchte stürzt das System ab.
Mein Aktueller Code:
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);
}
//+------------------------------------------------------------------+
Anbei siehe bitte auch den beigefügten Screenshot.
Jedesmal wenn er ein weiteres Close[i+1]<High[i+2] entdeckt springt er aus der "While()" Loop aber er müsste die in der "While()" Loop drin bleiben bis
Close[i+1]>Als die gespeicherte "highNumber" ist.
So müsste der Code sein den ich brauche (ohne Absturz)
Code:
else if(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 highNumber
if(lowCheck>Low[i+1]){
bar++;
lowCheck=Low[bar];
}else{
upStop_1[i+1]=lowCheck;
break;
}
}
}