SetIndexBuffer(0,StrengthBuffer); : ArrayResize(StrengthBuffer,Bars+L_Period,Bars+L_Period);
Do not resize buffers, they are already sized before the call. Make your other arrays non-visible buffers.for(int i=0; i<rates_total; i++)
Why are you recalculating all bars every tick? That is why it "slowed to stalling point." Do your lookbacks correctly.for(int i=0; i<rates_total; i++){ : AbsCandle[i]=BodySize; : for(int cnt=i; cnt<(i+L_Period); cnt++){ deltalong=deltalong+LongCandle[cnt]; deltaabs=deltaabs+AbsCandle[cnt];
You are calculating new bars first (not recommended) and at the same time looking at older values (which haven't been done.)for(int i=0; i<rates_total; i++){ double Body = MathAbs(iOpen(Symbol(),TimeFrame,i)-iClose(Symbol(),TimeFrame,i));
You are mixing apples and oranges Fails if chart is not TimeFrame.EURUSDBuffer[i] = iCustom("EURUSD",TimeFrame,"boom v1.2",Look_Back,0,0,i);
Many thanks for your response. I've cleaned my mess up to look like this
//+------------------------------------------------------------------+ //| boom.mq4 | //| Copyright 2016, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_level1 4 #property indicator_level2 4.8 #property indicator_level3 5 #property indicator_level4 5.2 #property indicator_level5 6 #property indicator_levelcolor clrWhite #property indicator_levelstyle STYLE_DASHDOTDOT //--- plot Strength #property indicator_label1 "Strength" #property indicator_type1 DRAW_LINE #property indicator_color1 clrBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 2 //--- input parameters input int L_Period=21; //--- indicator buffers double StrengthBuffer[]; //--- internal arrays double LongCandle[],AbsCandle[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping IndicatorBuffers(3); SetIndexBuffer(0,StrengthBuffer); SetIndexBuffer(1,LongCandle); SetIndexBuffer(2,AbsCandle); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { //--- for(int i=rates_total-1-MathMax(L_Period,prev_calculated); i>=0; --i) { { double Body = MathAbs(iOpen(Symbol(),0,i)-iClose(Symbol(),0,i)); double BodySize = Body/Point; if(BodySize==0.0) BodySize=0.01; if(iOpen(Symbol(),0,i)<iClose(Symbol(),0,i)) LongCandle[i]=BodySize; else LongCandle[i]=0.01; AbsCandle[i]=BodySize; } double deltalong=0.0,deltaabs=0.0; for(int cnt=i+L_Period; cnt>=i; cnt--) { deltalong=deltalong+LongCandle[cnt]; deltaabs=deltaabs+AbsCandle[cnt]; } StrengthBuffer[i]=(deltalong/deltaabs)*10; } //--- return value of prev_calculated for next call return(rates_total-1); } //+------------------------------------------------------------------+
Hope that's got the right count and taken the oranges out. Seems to work smoothly in ST.
- Why use function calls when you can use the Predefined Variables - MQL4 Reference
if(iOpen(Symbol(),0,i)<iClose(Symbol(),0,i)) if(Open[i] < Close[i])
- Are you sure you want to sum L_Period + 1 values?
for(int cnt=i+L_Period; cnt>=i; cnt--)
WHRoeder:
1) is because I'm the worst programmer ever and 2) is proof. Thanks for taking the time to help.
- Why use function calls when you can use the Predefined Variables - MQL4 Reference
- Are you sure you want to sum L_Period + 1 values?
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
From the diaries of the world's worst programmer
So I'm learning about arrays but not being very bright, struggling to understand how they actually populate themselves and how that affects memory allocation and resources.
I'm trying to build my own currency strength indicator. First step, build an indicator to measure an individual currency. I tested a few different algo's and came up with this;
Seemed to work well off a live chart, however,in strategy tester, it slowed to stalling point.
Didn't pay too much attention to this fact and moved to step two, gather data from multiple currency pairs. I came up with this basic indicator to be able to view that data.
So I applied it to a live chart and things started well. Looked to be collecting data exactly as desired. But it didn't take long before I notice my platform was starting to slow down before finally, the platform froze during the ECB conference.
Hoping someone can tell me what happen and what I need to do to fix it.