When I try to calculate within my snippet, I found that Empty4 zeroes my fragment after decimal, though all variables are double. The same fragment runs ok within indicator. Please advise how to cope with this, without using NormalizeDouble?
TIA,
Need help: data zeroes by Empty4
-
phil_trade
Re: Need help: data zeroes by Empty4
Hi giailanggiailang wrote:When I try to calculate within my snippet, I found that Empty4 zeroes my fragment after decimal, though all variables are double. The same fragment runs ok within indicator. Please advise how to cope with this, without using NormalizeDouble?
TIA,
you should publish this code snippet So that we can understand
cheers
Philippe
-
giailang
- Trader
- Posts: 18
- Joined: Wed Oct 24, 2012 10:57 am
Re: Need help: data zeroes by Empty4
Thanks, it's so simple so I did not post. Here it goesphil_trade wrote:Hi giailanggiailang wrote:When I try to calculate within my snippet, I found that Empty4 zeroes my fragment after decimal, though all variables are double. The same fragment runs ok within indicator. Please advise how to cope with this, without using NormalizeDouble?
TIA,
you should publish this code snippet So that we can understand
cheers
Philippe
Code: Select all
void testdata(string sym, int TF, int period, int Fast, int Slow)
{
double ma1,ma2,testbuf[];
for(int i=0;i<period;i++)
{
ma1=iMA(symb,TF,Fast,0,MODE_EMA,PRICE_CLOSE,i);
ma2=iMA(symb,TF,Slow,0,MODE_EMA,PRICE_CLOSE,i);
testbuf[i]=ma1-ma2;
Print("ma1= ",ma1,", ma2= ",ma2, ", testbuf[",i,"]= ",testbuf[i]);
}
}
I did add IndicatorDigits(Digits+1) to the code, but nothing change. When put inside the indicator, it works normally, but the iCustom has drawback of consuming too much RAM, increase each time the indicator is called.
Thanks for your help.
-
garyfritz
Re: Need help: data zeroes by Empty4
testbuf[] is a POINTER to an array of doubles, not the array itself. MQL should have thrown an error when you accessed the un-initialized pointer, but, well, MQL.
If you just need an array of doubles, you would declare it as "double testbuf[100]". But you probably need an array that corresponds to your display buffers?
If you want to display the values in testbuf[], you should use SetIndexBuffer(). That will tell MQL to allocate space to the array, and grow it by one every time a new bar is added to the chart.
If you just want to use it for calculation, you have to allocate the space yourself. And I've forgotten the function for that and I just got an emergency call and have to leave. Someone will remember.
If you just need an array of doubles, you would declare it as "double testbuf[100]". But you probably need an array that corresponds to your display buffers?
If you want to display the values in testbuf[], you should use SetIndexBuffer(). That will tell MQL to allocate space to the array, and grow it by one every time a new bar is added to the chart.
If you just want to use it for calculation, you have to allocate the space yourself. And I've forgotten the function for that and I just got an emergency call and have to leave. Someone will remember.
-
phil_trade
Re: Need help: data zeroes by Empty4
giailang wrote:Thanks, it's so simple so I did not post. Here it goesphil_trade wrote:Hi giailanggiailang wrote:When I try to calculate within my snippet, I found that Empty4 zeroes my fragment after decimal, though all variables are double. The same fragment runs ok within indicator. Please advise how to cope with this, without using NormalizeDouble?
TIA,
you should publish this code snippet So that we can understand
cheers
PhilippeRun the code, you can see ma1!=ma2, but testbuf ==0. Later, compare testbuf and testbuf[i+1] you got testbuf=testbuf[i+1];Code: Select all
void testdata(string sym, int TF, int period, int Fast, int Slow) { double ma1,ma2,testbuf[]; for(int i=0;i<period;i++) { ma1=iMA(symb,TF,Fast,0,MODE_EMA,PRICE_CLOSE,i); ma2=iMA(symb,TF,Slow,0,MODE_EMA,PRICE_CLOSE,i); testbuf[i]=ma1-ma2; Print("ma1= ",ma1,", ma2= ",ma2, ", testbuf[",i,"]= ",testbuf[i]); } }
I did add IndicatorDigits(Digits+1) to the code, but nothing change. When put inside the indicator, it works normally, but the iCustom has drawback of consuming too much RAM, increase each time the indicator is called.
Thanks for your help.
I don't know if it's the bug with another varibale, but you Have "sym" param in TestData but use "symb" variable in it. Just a typo ?
- milanese
- TechAdmin
- Posts: 3293
- Joined: Wed Jan 09, 2013 9:02 am
- Location: btr rdx, r8 +
Re: Need help: data zeroes by Empty4
giailang wrote:Thanks, it's so simple so I did not post. Here it goesphil_trade wrote:Hi giailanggiailang wrote:When I try to calculate within my snippet, I found that Empty4 zeroes my fragment after decimal, though all variables are double. The same fragment runs ok within indicator. Please advise how to cope with this, without using NormalizeDouble?
TIA,
you should publish this code snippet So that we can understand
cheers
PhilippeRun the code, you can see ma1!=ma2, but testbuf ==0. Later, compare testbuf and testbuf[i+1] you got testbuf=testbuf[i+1];Code: Select all
void testdata(string sym, int TF, int period, int Fast, int Slow) { double ma1,ma2,testbuf[]; for(int i=0;i<period;i++) { ma1=iMA(symb,TF,Fast,0,MODE_EMA,PRICE_CLOSE,i); ma2=iMA(symb,TF,Slow,0,MODE_EMA,PRICE_CLOSE,i); testbuf[i]=ma1-ma2; Print("ma1= ",ma1,", ma2= ",ma2, ", testbuf[",i,"]= ",testbuf[i]); } }
I did add IndicatorDigits(Digits+1) to the code, but nothing change. When put inside the indicator, it works normally, but the iCustom has drawback of consuming too much RAM, increase each time the indicator is called.
Thanks for your help.
you should add in init() this:
Code: Select all
if(ArraySize( testbuf) < Bars)
{
ArraySetAsSeries( testbuf, false);
ArrayResize( testbuf, Bars);
ArraySetAsSeries (testbuf, true);
} Cheers
Tommaso
Global Prime is the official SHF broker 
Searching for Servers and Workstations with individual configuration?
Just PM
Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
Searching for Servers and Workstations with individual configuration?
Just PM
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
-
phil_trade
Re: Need help: data zeroes by Empty4
You need to initialize array like this :
Unfortunately, you can pass period to init it like this as mql need a literal integer
cheers
Philippe
Code: Select all
void testdata(string sym, int TF, int period, int Fast, int Slow)
{
double ma1,ma2;
double testbuf[10];
for(int i=0;i<period;i++)
{
ma1=iMA(sym,TF,Fast,0,MODE_EMA,PRICE_CLOSE,i);
ma2=iMA(sym,TF,Slow,0,MODE_EMA,PRICE_CLOSE,i);
testbuf[i]=ma1-ma2;
Print("ma1= ",ma1,", ma2= ",ma2, "ma1-ma2= ",(ma1-ma2), "testbuf[",i,"]= ",NormalizeDouble(testbuf[i],5));
}
}Code: Select all
double testbuf[period];cheers
Philippe
-
giailang
- Trader
- Posts: 18
- Joined: Wed Oct 24, 2012 10:57 am
Re: Need help: data zeroes by Empty4
phil_trade wrote:giailang wrote:Thanks, it's so simple so I did not post. Here it goesphil_trade wrote:Hi giailanggiailang wrote:When I try to calculate within my snippet, I found that Empty4 zeroes my fragment after decimal, though all variables are double. The same fragment runs ok within indicator. Please advise how to cope with this, without using NormalizeDouble?
TIA,
you should publish this code snippet So that we can understand
cheers
PhilippeRun the code, you can see ma1!=ma2, but testbuf ==0. Later, compare testbuf and testbuf[i+1] you got testbuf=testbuf[i+1];Code: Select all
void testdata(string sym, int TF, int period, int Fast, int Slow) { double ma1,ma2,testbuf[]; for(int i=0;i<period;i++) { ma1=iMA(symb,TF,Fast,0,MODE_EMA,PRICE_CLOSE,i); ma2=iMA(symb,TF,Slow,0,MODE_EMA,PRICE_CLOSE,i); testbuf[i]=ma1-ma2; Print("ma1= ",ma1,", ma2= ",ma2, ", testbuf[",i,"]= ",testbuf[i]); } }
I did add IndicatorDigits(Digits+1) to the code, but nothing change. When put inside the indicator, it works normally, but the iCustom has drawback of consuming too much RAM, increase each time the indicator is called.
Thanks for your help.
I don't know if it's the bug with another varibale, but you Have "sym" param in TestData but use "symb" variable in it. Just a typo ?
Thanks Phil, that's my typo, in the real code it is sym. Thanks Garry for pointing out my declaration is only pointer, not array.Thanks Tomasso for the init code.
Actually, I am trying to convert BB_MACD indicator into Signal detector. When finish my mod, I'll post it asap.