Download MetaTrader 5

Array issue... i dont understand

To add comments, please log in or register
Publish your article to let the traders see it in MetaTrader 5!
Gregory
72
Gregory 2014.01.26 18:13 

Hello,

This is just some code to show on a graph sell dots. I want to track the history of buy/sell signals in an array, so by default i assign "0" to "SignalHisto".

When there is a signal, the value gets 1.


Now i want to use the data stored in the array. If i put in the last "if" statement : if (SignalHisto[i] == 1) then i will have two signal displayed on my graph ON THE SAME BAR, the one from the first "if" and the one from the second "if" (buffer 6 & 7). That is fine. But when i put as in the code below "if (SignalHisto[i+1] == 1), i would expect for have two signals displayed on the chart on TWO CONSECUTIVE BARS... But the buffer 6 signal isn't displayed.


Any reason ? With the i+1 it doesn't work but with "i" that is fine. With the "i+1" i only have Buffer 7 signal displayed.

Thanks
Greg

       SignalHisto[i] = 0;     
       
       if [SELL CONDITION]
            {
             ExtMapBuffer7[i] = High[i]+1*Point; //sell signal
             SignalHisto[i] = 1;
            }                                
 
       if (SignalHisto[i+1] == 1)
         {
            ExtMapBuffer6[i] = High[i]+2*Point; //sell signal     
           } 
Vladrath
4
Vladrath 2014.01.26 20:45  

I could be wrong here, I'm newer to programming EA's


Lets say you wanted to save the last 10 signals in your array. Set

int (or double if you have a decimal) SignalHisto[10];


Then realize that your index starts at zero so ...

SignalHisto[0] = "whatever your saving in the most recent index space";

SignalHisto[1] = "whatever your saving in the second most recent index space";

...

SignalHisto[9] = "whatever your saving in the 10th index space";

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.26 20:57  
Greg_:

Hello,

This is just some code to show on a graph sell dots. I want to track the history of buy/sell signals in an array, so by default i assign "0" to "SignalHisto".

When there is a signal, the value gets 1.


Now i want to use the data stored in the array. If i put in the last "if" statement : if (SignalHisto[i] == 1) then i will have two signal displayed on my graph ON THE SAME BAR, the one from the first "if" and the one from the second "if" (buffer 6 & 7). That is fine. But when i put as in the code below "if (SignalHisto[i+1] == 1), i would expect for have two signals displayed on the chart on TWO CONSECUTIVE BARS... But the buffer 6 signal isn't displayed.


Any reason ? With the i+1 it doesn't work but with "i" that is fine. With the "i+1" i only have Buffer 7 signal displayed.

Thanks
Greg

Does your loop count up or down ?
whroeder1
14519
whroeder1 2014.01.26 22:06  
So close together you can't see them.
ExtMapBuffer7[i] = High[i]+1*Point; //sell signal
ExtMapBuffer6[i] = High[i]+2*Point; //sell signal     
Try a minimum of 5 pips difference
ExtMapBuffer7[i] = High[i]+1*Point; //sell signal
ExtMapBuffer6[i] = High[i]+50*Point; //sell signal     
Adjust for 4/5 digit brokers
Gregory
72
Gregory 2014.01.27 18:16  

Thanks for answers, it's on DAX, so 1pt is enough to see it :)

The loop go forward i++

In fact the code works with "if (SignalHisto[i-1] == 1)" (so minus 1). It will give the signal on the bar before my sell condition.

It works "
if (SignalHisto[i] == 1)", will give signal on my sell condition.

But i can't get it give the signal on i+1, so the bar after my sell condition.

Weird.

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.27 18:24  
Greg_:

Thanks for answers, it's on DAX, so 1pt is enough to see it :)

The loop go forward i++

How can you get a value for i+1 when you haven't calculated it yet ? new bars are attached to the right of the chart, your Indicator works left to right with real time data, why doesn't it work from left to right on historical data, i.e. i-- ?
whroeder1
14519
whroeder1 2014.01.27 19:04  
Greg_: Thanks for answers, it's on DAX, so 1pt is enough to see it :)
Dax ranges 9300-9400 today, do you really think you can see two arrows separated by 0.01?
Gregory
72
Gregory 2014.01.28 20:35  

Thanks RaptorUK, i need to check that indeed :) That might be the issue i guess.

@WHRoeder, on the dax, "point" = 1 point, so not 0.01. On the screen you may have 50 point gap, so yes a 1pt difference you can see it :-)

Thanks guys!

whroeder1
14519
whroeder1 2014.01.28 21:12  

Dax is quoted as 9,406.91 http://daytrading.about.com/od/marketprofiles/a/ProfileDAX.htm says "Tick size / Minimum price change : 0.5 "

You are confusing mt4's Point (0.01) and MODE_TICKSIZE of 0.50 with the DAX "point" (1 point=2 ticks=1.00)

Ex Ovo Omnia
3154
Ex Ovo Omnia 2014.01.29 09:00  
Well, my experience is that some brokers have DAX futures with tick size 50c, some have CFD on DAX with tick size 1€, some 1c, some 0.1c so it is hard to generalize.
whroeder1
14519
whroeder1 2014.01.29 14:12  
Ovo: Well, my experience is that some brokers have DAX futures with tick size 50c, some have CFD on DAX with tick size 1€, some 1c, some 0.1c so it is hard to generalize.
True and irrelevant to OP. He can not see two arrows placed 1 Point (0.01) apart.
12
To add comments, please log in or register