A few of the buffer names are duplicated in the calculations and one in ArraySetAsSeries().
Ernst Van Der Merwe:
A few of the buffer names are duplicated in the calculations and one in ArraySetAsSeries().
A few of the buffer names are duplicated in the calculations and one in ArraySetAsSeries().
So I looked at it and thought about the code, changed this
//--- preliminary calculations if(prev_calculated==0) { BullPowerIndicator[0]=0.0; BearPowerIndicator[0]=0.0; BullSentimentIndicator[0]=0.0; BearSentimentIndicator[0]=0.0; Body[0]=0.0; Range[0]=0.0; Sentiment[0]=0.0; SentimentCount[0]=0.0; BullBodySize[0]=0.0; BullBodyCount[0]=0.0; TotalPipCount[0]=0.0; //--- filling out the array of count values for each period for(i=1; i<rates_total; i++) { bool IsBullBar=close[i]>open[i]; //--- To determine if current candle direction Body[i] = MathAbs(close[i]-open[i]); //--- Calculate the body size Range[i] = MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]); //--- Calculate the true range Sentiment[i] = (Body[i]/Range[i])*100; //--- Sentiment strength is a Percentage calculation body vs range. if(IsBullBar) //--- if the current bar is a bull bar assign body to array. A bear bar has the value of 0 for counting purposes. BullBodySize[i]=Body[i]; else BullBodySize[i]=0; } //--- first Period values of the indicator are not calculated double MovingSentimentCount=0.0; //--- variable to store the accumulated sentiment count for the input period double MovingBullBodyCount =0.0; //--- variable to store the accumulated bull body count for the input period double MovingPipcount=0.0; //--- variable to store the accumulated range for the input period for(i=1; i<=InpPeriod; i++) { BullPowerIndicator[i] = 0.0; BearPowerIndicator[i] = 0.0; BullPowerIndicator[i] = 0.0; BearPowerIndicator[i] = 0.0; MovingSentimentCount+=Sentiment[i]; MovingBullBodyCount+=BullBodySize[i]; MovingPipcount+=Range[i]; } //--- calculating the first value of the indicator BullPowerIndicator[InpPeriod] = MovingSentimentCount/InpPeriod; BearPowerIndicator[InpPeriod] = 100-(MovingSentimentCount/InpPeriod); BullSentimentIndicator[InpPeriod] = (MovingBullBodyCount/MovingPipcount)*100; BearSentimentIndicator[InpPeriod] = 100-((MovingBullBodyCount/MovingPipcount)*100); limit=InpPeriod+1; } else limit=prev_calculated-1; //--- the main loop of calculations for(i=limit; i<rates_total; i++) { bool IsBullBar=close[i]>open[i]; Body[i] = MathAbs(close[i]-open[i]); Range[i] = MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]); if(Body[i]==0 || Range[i]==0) Sentiment[i]=50; else Sentiment[i]=(Body[i]/Range[i])*100; SentimentCount[i]=SentimentCount[i-1]+Sentiment[i]-Sentiment[i-InpPeriod]; if(IsBullBar) BullBodySize[i]=Body[i]; else BullBodySize[i]=0; BullBodyCount[i]=BullBodyCount[i-1]+Body[i]-Body[i-InpPeriod]; TotalPipCount[i]=TotalPipCount[i-1]+Range[i]-Range[i-InpPeriod]; //--- calculating the value of the indicator BullPowerIndicator[i] = SentimentCount[i]/InpPeriod; BearPowerIndicator[i] = 100 - BullPowerIndicator[InpPeriod]; BullPowerIndicator[i] = (BullBodyCount[i]/TotalPipCount[i])*100; BearPowerIndicator[i] = 100-((BullBodyCount[i]/TotalPipCount[i]))*100; }
to this
//--- filling out the array of count values for each period for(i=1; i<=InpPeriod; i++) { bool IsBullBar=close[i]>open[i]; //--- To determine if current candle direction Body[i]=MathAbs(close[i]-open[i]); //--- Calculate the body size Range[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]); //--- Calculate the true range Sentiment[i]=(Body[i]/Range[i])*100; //--- Sentiment strength is a Percentage calculation body vs range. if(IsBullBar) //--- if the current bar is a bull bar assign body to array. A bear bar has the value of 0 for counting purposes. BullBodySize[i]=Body[i]; else BullBodySize[i]=0; SentimentCount[i]+=SentimentCount[i-1]+Sentiment[i]; BullBodyCount[i]+=BullBodyCount[i-1]+BullBodySize[i]; TotalPipCount[i]+= TotalPipCount[i-1]+Range[i]; BullPowerIndicator[i] = SentimentCount[i]/i; BearPowerIndicator[i] = 100-(SentimentCount[i]/i); BullSentimentIndicator[i] = (BullBodyCount[i]/TotalPipCount[i])*100; BearSentimentIndicator[i] = 100-((BullBodyCount[i]/TotalPipCount[i])*100); } limit=InpPeriod+1; } else limit=prev_calculated-1; //--- the main loop of calculations for(i=limit; i<rates_total; i++) { bool IsBullBar=close[i]>open[i]; Body[i] = MathAbs(close[i]-open[i]); Range[i] = MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]); if(Body[i]==0 || Range[i]==0) Sentiment[i]=50; else Sentiment[i]=(Body[i]/Range[i])*100; if(IsBullBar) BullBodySize[i]=Body[i]; else BullBodySize[i]=0; SentimentCount[i]=SentimentCount[i-1]+Sentiment[i]-Sentiment[i-InpPeriod]; BullBodyCount[i]=BullBodyCount[i-1]+Body[i]-Body[i-InpPeriod]; TotalPipCount[i]=TotalPipCount[i-1]+Range[i]-Range[i-InpPeriod]; //--- calculating the value of the indicator BullPowerIndicator[i] = SentimentCount[i]/InpPeriod; BearPowerIndicator[i] = 100 - BullPowerIndicator[i]; BullPowerIndicator[i] = (BullBodyCount[i]/TotalPipCount[i])*100; BearPowerIndicator[i] = 100-BullPowerIndicator[i]; }
but alais no success
Any other thoughts
So i filled the code up with a heap of print functions. Pulled up the log files and work through each line.
Found the issues and have corrected them. Now I have a beautiful looking indicator
Thanks Ernst for responding. Better than others

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
I found an indicator a couple of years again. I don't know whom wrote it but it had this header at top so credit is due here
I've reworked the code but have never liked how it first applies itself to a chart and then how quickly it slows down, bogs and the crashes the terminal. Which is a pity cause it is a great little indicator
Here is the code
When I apply it to the chart it first looks like this
But as soon as the first tick comes in it works fine (although the coding itself is "loose" so to speak)
I believe the error root cause lies in line 107 which then calls repeat calculations on bars that haven't changed since the previous run of the function thus bogging down the terminal
So I re-engineered the code to try and fix the solution but have come to a dead end.
Here is the new code (hopefully much cleaner than before)
But when I apply to my chart all I get is this
My journal tab says it loads successfully and is initialized ans so to the expert tab.
Any help getting this one to work will be greatly appreciated.