Because lowerShadow, upperShaddow are guaranteed to be initilised before they are used (they are BOTH initialised in the if and the else of the first if block/condition)
However only one of the mainBodyBear or mainBodyBull is initialised in the second if block
Generally you should initialise all stack based varibles as it can often get you into trouble
double mainBodyBear = 0; double mainBodyBull = 0; double midBody = 0;
Quiet the compiler | double lowerShadow=0, upperShadow=0; if(Close[1] < Open[1]) // Bearish body (not candle signal) { lowerShadow = Close[1] - Low[1]; upperShadow = High[1] - Open[1]; } else // Bullish body (not candle signal) { lowerShadow = Open[1] - Low[1]; upperShadow = High[1] - Close[1]; } |
Or just initialize them as you declare them | double lowerShadow = Close[1] < Open[1] ? Close[1] - Low[1] : Open[1] - Low[1]; double upperShadow = Close[1] < Open[1] ? High[1] - Open[1] : High[1] - Close[1]; |
Or simplify and self document. | double lowerBody = MathMin(Close[1], Open[1]), upperBody = MathMax(Close[1], Open[1]); double lowerShadow = lowerBody - Low[1]; double upperShadow = High[1] - upperBody; |
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
When i use these 2 similar codes to find candle patterns how come the 1st one has no errors on lowerShadow or upperShadow objects yet the 2nd one
shows error on mainBodyBear, mainBodyBull, midBody objects. I cant figure it out?