double v1[1000]; double v2[1000]; double v3[1000];<------ leave out the '1000' initialization for indicator buffers, as they don't require
Well, I did that at first but then I could not print the values of the buffer which I wanted to do
Well wait, let me restate this:
If I do not declare the number of elements in the buffer, then the indicator will work as with v1[i]=High[i]
But Print (v1[i]); will not output because from what I can tell there is no way to print non-declared array values if the number of elements was not declared, thus it will always prints 0
So if I do not declare it globally, then the indicator works, however the if(faster>slower) still makes the indicator disappear, AND I can't print the values either.
If I declare it and also re-initialise again with v1[i]=High[i] again then I can print, however any additions such as && faster > slower will remove the indicator again.
I don't completely understand why.
Thanks
I took your code, took out the values from the buffer declarations and it works just fine . . .
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[4]= 1.5913 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v1[8]= 1.5962 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[11]= 1.5948 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v1[15]= 1.5992 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v1[18]= 1.5996 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[20]= 1.5919 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[27]= 1.5954 if
I took your code, took out the values from the buffer declarations and it works just fine . . .
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[4]= 1.5913 if <----High
------> at this time Fractals inconsistent High is lower the prev Low <---------
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[11]= 1.5948 if<----High
------> at this time Fractals inconsistent High is lower the prev Low <---------
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v1[15]= 1.5992 if<----Low
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v1[18]= 1.5996 if<----High
------> at this time alternating Fractals consistent <---------
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[20]= 1.5919 if <----Low
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[27]= 1.5954 if <----High
Interesting, thx for the result Agent86V2. Fractals are indeed one of those intriguing yet can be profitable way to trade.
I took your code, took out the values from the buffer declarations and it works just fine . . .
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[4]= 1.5913 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v1[8]= 1.5962 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[11]= 1.5948 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v1[15]= 1.5992 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v1[18]= 1.5996 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[20]= 1.5919 if
2011.09.27 13:04:03 Agent86V2 GBPUSD,H1: v2[27]= 1.5954 if
I am sorry I just don't get it. I thought that I did, but I seem to still be missing something.
int start() { double test[]; test[39] = 45.6; Print("test[39]= ",test[39] ); return(0); }You instructed me to declare as above :
And you quoted this topic:
"When declaring an array, data type, array name and number of elements of each dimension must be specified:"
So on one hand I cannot print the array as in this script without first declaring double test[40]; as you instructed, but now I seem to be able to print without declaration as well.So it appears I can print the values in the buffer regardless of the declaration.
However, I can not add additional conditions that would normally produce the desired result such as if(faster > slower) or && faster > slower
It can be EMA anything I just want to understand why it's not working.
It causes the indicator highs to disappear and v1 print output quits printing. I was expecting it to fall in line with the condition and print the output.
I tried to add additional code blocks for this also with same results.
Thanks
I also wrote this . . .
Indicator buffers are special Arrays . . . don't mix up Arrays and Buffers, they are similar yet different.
In the original code v1[] and v2[] are buffers, in your latest code they are Arrays, when you declare an Array you have to give it a size, for example, v1[50] has 50 elements from v1[0] to v1[49]. The Buffer automatically Resizes when there are more elements needed and the values shift along in the Buffer automatically. Consider the currently forming bar, bar 0, when this bar completes an Indicator value associated with that bar has to shift to index 1 . . . this is done automatically with Buffers . . if you want to so something similar with Arrays you can, but you have to code it yourself.
However, I can not add additional conditions that would normally produce the desired result such as if(faster > slower) or && faster > slower
It can be EMA anything I just want to understand why it's not working.
It causes the indicator highs to disappear and v1 print output quits printing. I was expecting it to fall in line with the condition and print the output.
I tried to add additional code blocks for this also with same results.
Thanks
I also wrote this . . .
Indicator buffers are special Arrays . . . don't mix up Arrays and Buffers, they are similar yet different.
In the original code v1[] and v2[] are buffers, in your latest code they are Arrays, when you declare an Array you have to give it a size, for example, v1[50] has 50 elements from v1[0] to v1[49]. The Buffer automatically Resizes when there are more elements needed and the values shift along in the Buffer automatically. Consider the currently forming bar, bar 0, when this bar completes an Indicator value associated with that bar has to shift to index 1 . . . this is done automatically with Buffers . . if you want to so something similar with Arrays you can, but you have to code it yourself.
I only created a secondary loop because I was unable to print within the first indicator loop, but now it's printing
Anyhow I won't rehash this I think I get it.
So the code that will not work are some examples shown here:
//+------------------------------------------------------------------+ //| //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 White //---- buffers double v1[]; double v2[]; double v3[]; double val1; double val2; double val3; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { //---- IndicatorBuffers(3); SetIndexArrow(0, 111); SetIndexStyle(0,DRAW_ARROW,STYLE_DOT,1,Blue); SetIndexBuffer(0, v1); SetIndexLabel(0,"Resistance"); SetIndexArrow(1, 111); SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,1,Red); SetIndexBuffer(1, v2); SetIndexLabel(1,"Support"); SetIndexArrow(2, 111); SetIndexStyle(2,DRAW_ARROW,STYLE_DOT,1,White); SetIndexBuffer(2, v3); SetIndexLabel(2,"High A"); //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { double faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL int i=Bars; //---- for(i=Bars; i>=0; i--) { val1=iFractals(NULL, 0, MODE_UPPER,i); if (val1 > 0 && faster > slower) // I think I need to add some more comparisons for the Low[i] also // the comparison works but shows indicator when faster < slower too. // adding additional code blocks instead of above and including the part below and inserting this instead // if(faster>slower) // { // v1[i]=High[i]; // } // causes indicator to disappear { v1[i]=High[i]; Print ("v1[", i, "]= ", v1[i], " if"); } else { //v1[i]=v1[i+1]; //Print ("v1[", i, "]= ", v1[i], " else"); } val2=iFractals(NULL, 0, MODE_LOWER,i); if (val2 > 0) { v2[i]=Low[i]; Print ("v2[", i, "]= ", v2[i], " if"); } else { //v2[i]=v2[i+1]; //Print ("v2[", i, "]= ", v2[i], " else"); } } //---- return(0); } //+------------------------------------------------------------------+
Thanks
So the code that will not work are some examples shown here:
Thanks
OK, I can tell you what your issue is or I can give you some clues . . . . clues first, if you want me to tell you just say and I'll tell you . .
Inside the Loop, for(i=Bars; i>=0; i--) . . what are the values for faster and slower ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I was learning some general topics about arrays from a code base indicator which has iFractals with some big help from guru's in the forums.
So Anyhow
I was unable to add add conditional operators or logic operations to add addition function to the indicator
I tried inserting if(faster > slower) into various areas of the code just to play with the idea. Normally these ideas would work in an EA but not in an indicator
IE if(v1 > 0 && faster > slower)
but this causes the indicator to disappear.
Many other combinations that I thought should produce the desired indicator if(other conditions) etc and so on.
All produce no print statement outputs.
What point am I missing here.
Please advise
Thanks