Download MetaTrader 5

problems with timeframe

To add comments, please log in or register
The Market has more than 400 indicators. Try any of them!
amando
423
amando 2013.01.21 21:59 

Hello,

i want to make a script which give me few data from the Hour chart back

the problem is, i always get an error



double High[],Low[], Open[];




int count = 23; // Anzahl der Stunden die benötigt werden für einen tag, 23 da 6:00 Kerze = 0

      int aktuelleStunde()
        {
         MqlDateTime tm;
         TimeCurrent(tm);
         return(tm.hour);
        }

      int Start = aktuelleStunde() - 6;  // gibt die Bars an die ich zurückzählen muss (6 wegen der 1 die ich als Versatz brauche 7:00 Kerze = 0 Kerze, 7-6 = 1 Kerze zurück
      
//+------------------------------------------------------------------+
//| Tageshoch                                                        |
//+------------------------------------------------------------------+

/*
      int iHighest(string symbol,ENUM_TIMEFRAMES timeframe,int count_high = 0,int start=0) // welcher Bar hat das Maximum
        {
          symbol = _Symbol; timeframe = PERIOD_H1; count_high = count; start = Start;
          ArraySetAsSeries(High,true);
          CopyHigh(symbol,timeframe,start,count_high,High);
          return(ArrayMaximum(High,start,count_high));
          return(0);
        }
   
       
       double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index_high)
        {
         double high=0; timeframe = PERIOD_H1; symbol = _Symbol;
         index_high = iHighest(Symbol(),PERIOD_H1,count,Start);
         ArraySetAsSeries(High,true);
         int copied=CopyHigh(symbol,timeframe,Start, Bars(symbol,timeframe),High);
         if(copied>0 && index_high<copied) high=High[index_high];
         return(high);
        }
    */
//+------------------------------------------------------------------+
//| Tagestief                                                        |
//+------------------------------------------------------------------+


      int iLowest(string symbol,ENUM_TIMEFRAMES timeframe,int count_low = 0,int start=0) // welcher Bar hat das Maximum
        {
          symbol = _Symbol; timeframe = PERIOD_H1; count_low = count; start = Start;
          ArraySetAsSeries(Low,true);
          CopyLow(symbol,timeframe,start,count_low,Low);
          return(ArrayMinimum(Low,start,count_low));
          return(0);
        }



       double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index_low)
        {
         double low=0;
         timeframe = PERIOD_H1;
         symbol = _Symbol;
         index_low = iLowest(Symbol(),timeframe,count,Start);
         ArraySetAsSeries(Low,true);
         int copied=CopyLow(symbol,timeframe,Start, Bars(symbol,timeframe),Low);
         if(copied>0 && index_low<copied) low=Low[index_low];
         return(low);
        }
        
void OnStart()
  {
//---

 // Print("Hoch: ",iHighest(Symbol(),PERIOD_H1,count,Start), " an Bar Nummer: ",iHigh(Symbol(),PERIOD_H1,iHighest(Symbol(),PERIOD_H1,count,Start)), " von 7:00 weg");
  Print("Tief: ",iLowest(Symbol(),PERIOD_H1,count,Start), " an Bar Nummer: ",iLow(Symbol(),PERIOD_H1,iLowest(Symbol(),PERIOD_H1,count,Start)), " von 7:00 weg");

 

   
  }
//+------------------------------------------------------------------+

the high Value i get the right data back
For the Low value i get the wrong candle index. if i decrease the count to as example 10, i get an error back
phi nuts
2184
phi nuts 2013.01.26 11:10  
amando:

Hello,

i want to make a script which give me few data from the Hour chart back

the problem is, i always get an error

the high value i get the right data back

For he low value i get the wrong candle index. if i decrease the count to as example 10, i get an error back 

 

I apologize for taking this too long for you to get the answer, that's because I don't understand what exactly you trying to do here - or maybe I'm too lazy to try to understand it ;D

So I create small script to find the highest bar since the market is open 

Pay attention to ArrayMaximum (and ArrayMinimum), it will treat the array as standard conventional array even if we using timeseries array.

Below is the code, hope this help.

//+------------------------------------------------------------------+
//|                    find the highest bar since market is open.mq5 |
//|                                  Copyright 26 Jan 2013, phi.nuts |
//|                https://www.mql5.com/en/forum/10193#comment_414969 |
//+------------------------------------------------------------------+
#property copyright "Copyright 26 Jan 2013, phi.nuts "
#property link      "https://www.mql5.com/en/forum/10193#comment_414969"
#property version   "1.00"
//+------------------------------------------------------------------+
void OnStart()
  {
  // the highest bar since market open
  
  double   high_price [];
  datetime time_period_d1 [];
  int      highest_bar, copied_high;
  
  //--- what time market is open
  if (CopyTime (_Symbol, PERIOD_D1, 0, 1, time_period_d1) > 0)  //--- when the market open
    {
    Print("1. market open at ", TimeToString (time_period_d1[0],TIME_DATE|TIME_SECONDS));
    
    copied_high = CopyHigh(_Symbol, _Period, TimeCurrent(), time_period_d1[0], high_price);//--- copying high price
    if (copied_high > 0) 
       {
       Print ("2. number of data of high price is ", copied_high);
       
       highest_bar = ArrayMaximum(high_price, 0, WHOLE_ARRAY); //--- find the highest 
       if (highest_bar !=  -1)
          {
          Print("3. the highest price is ",high_price [highest_bar] ," at bar ",copied_high - highest_bar - 1);
          }
       }
    }
  
  return;
  }  

//+------------------------------------------------------------------+

 

To add comments, please log in or register