Have the open price of candle at specific hour. - page 3

 

Ok ok i give you that:

#define HR0900 14400  //All times were changed for the test to see which is the Reference.
#define HR1500 10800
#define HR1900 7200
#define HR2300 3600

extern string     Heures="11:41;11:42;12:00;11:42;"; // Times for my test today...
string            HeureSH[];

datetime TC = TimeCurrent();

int times[]={HR1500, HR2300, HR0900, HR1900};
                
    for(int k=0; k<ArraySize(HeureSH); k++)
    {
      datetime    want= TC - times[k];
    }

int iBar= iBarShift(Symbol(), PERIOD_H1, want);
double OpenPrice= iOpen(Symbol(), PERIOD_H1, iBar);
Onlyone of #define is considered. The Array HeureSH[] is correctly executed and if the time writed arrives, it's true, it's correct, this is only  times[k] don't consider all the four #define.
 
Kane59:

Ok ok i give you that:

Onlyone of #define is considered. The Array HeureSH[] is correctly executed and if the time writed arrives, it's true, it's correct, this is only  times[k] don't consider all the four #define.

The problem is pretty obvious . . .

string            HeureSH[];

 so this array has a size of 0 as you have declared it that way . . .  so this loop . . .

for(int k=0; k < ArraySize(HeureSH); k++)

 starts at 0 and ends when k >= 0  ( 0 being the array size ) 

 

Ok, i writed that cause i thought:

extern string     Heures="11:41;11:42;12:00;11:42;"; // Times for my test today...
      
                            0     1     2     3

int times[]={HR1500, HR2300, HR0900, HR1900};

               0        1       2       3
 
Kane59:

Ok, i writed that cause i thought:

I think you need to do some string manipulation,  you need to break your string into individual times,  convert each of these to a datetime and store them in your HeureSH[] array . . .  working with strings in this way can be a little tricky,  not hard buy easy to screw up.  Then your code might start to make a little sense . . .


By the way,  these are the string functions you have to work with,  study them carefully,  enjoy.
 

Hi

i work about it but i don't understand this:

RaptorUK:

The problem is pretty obvious . . .

 so this array has a size of 0 as you have declared it that way . . .  so this loop . . .

 starts at 0 and ends when k >= 0  ( 0 being the array size ) 

Can you try to tell me with more details?


For HeureSH[] i used lines to cut this in 4 strings parts to have 4 differents hours.

Edite again:

I writed ArraySize(HeureSH) in a print function and it give me: 4

Print("Open:", DoubleToStr(OpenPrice, digits), /*" Time:", TimeToStr(Time[iBar], */" ArraySise=", ArraySize(HeureSH));

2013.01.19 13:57:21    2012.11.19 19:00  Tester EURUSD,H1: Open:1.27701 ArraySise=4

i tested again and it select only the last of this:

int times[]={36000,21600,14400,14400};

So the last "14400". Why don't it select others in the same order of the Array "HeureSH[]" ?


Is there a problem with the cycle "For"?
 
Kane59:

Hi

i work about it but i don't understand this:

Can you try to tell me with more details?


For HeureSH[] i used lines to cut this in 4 strings parts to have 4 differents hours.

Edite again:

I writed ArraySize(HeureSH) in a print function and it give me: 4

2013.01.19 13:57:21    2012.11.19 19:00  Tester EURUSD,H1: Open:1.27701 ArraySise=4

The code you showed will result in what I have described,  if you have more code that has an impact on the question you are asking then you need to show it . . . .  or don't show it if you need no more help.
 

Ok ok sorry.

extern string     Heures="09:00;15:00;19:00;23:00;";
string            HeureSH[];

int start()
  {
//---- 
int times[]= {36000,21600,14400,14400};

   for(int i=0; i<ArraySize(Heures); i++)
   {
      datetime    want = TC - times[i];
   }

   int iBar= iBarShift(Symbol(), PERIOD_H1, want);
   double OpenPrice= iOpen(Symbol(), PERIOD_H1, iBar);

   if (HeureSH(TimeToStr(iTime(Symbol(),PERIOD_H1,0),TIME_MINUTES)))
   {
      if(iOpen(Symbol(), PERIOD_H1, 0) < OpenPrice)
      {
         OrderSend( OP_SELL, .......);
      }
      if(iOpen(Symbol(), PERIOD_H1, 0) > OpenPrice)
      {
         OrderSend( OP_BUY, .......);
      }
   }

//----
   return(0);
  }

//+------------------------------------------------------------------+
void UpdateHSeSpeciales()
   {
      string hour1 = "";
      int count1 = 0;
      for(int k=0; k<StringLen(Heures); k++)
      {
         if(StringSubstr(Heures, k, 1) != ";")
         {
            hour1= hour1+ StringSubstr(Heures, k, 1);
         }
         else
         {
            ArrayResize(HeureSH, ArraySize(HeureSH)+1);
            HeureSH[count1] = hour1;
            hour1 ="";
            count1 +=1;
         }   
      }
   }
   bool HeureSH(string now1)
   {
      for(int k=0; k<ArraySize(HeureSH); k++)
      {
         if(now1 == HeureSH[k])
         {
            return(true);
         }
      }
   
      return(false);
   }

So for example, when it's 09:00, the iBar is the bar of yesterday 23:00, 10 hours less than TimeCurrent. When it's 15:00, the iBar is the bar of today 09:00, ....... What i want: If selected hour comes, have a reference bar which is before Now (TimeCurrent). My problem is the program only take the last item of "times[]" no others. I want if HeureSH[0], use times[0] and continu. What can i do?


PS: it's all i have and i need.

 

Hi,

oh can anyone help me?

 
Kane59:

Hi,

oh can anyone help me?

You don't make it easy for anyone to help you,  you post bits and pieces of your code here and there . . .  I'm trying to understand your code,  I can't run it to see what it does as I don't have the full code, you have a function the same name as your array,  that is OK but it doesn't help readability.

When is  UpdateHSeSpeciales()  called ?

 

Sorry really,

I have only that but it's true i forget "UpdateHSeSpeciales".


It's called in "init" when program begin.