English

Select a 1H bar from a daily bar

Back to topics list To post a new topic, please log in or register
 20 Thaddeus_39 2016.07.23 05:38   I am trying to select a price level on a 1hour bar that is part of a daily bar with a certain characteristic.Something along the following line, as an example: If ((daily bar  == certain characteristic) -> zoom into 1hour bars and do 'whatever'...)  To make the transfer from Daily to 1H, I thought of using CopyRates and linking the time frames through iTime(_, PERIOD_D1, _), like the following lines (I selected the 10th bar just for testing purposes):int  start() {    MqlRates 1HourRate[];    ArraySetAsSeries(1HourRate,true);       #define LEN 23       datetime daily_time = iTime(NULL,PERIOD_D1,10);     //select the opening time of                                                       //the 10th daily candle       int copied = CopyRates(Symbol(),PERIOD_H1,daily_time,LEN,1HourRate);                                                       //Copy the 23 candles of the                                                       //1H chart that make up the daily candle                                                       //into the 1HourRate array    if(copied>0)    {    //...manipulate 1HourRate at will... However, it's not working.There are two questions:1. What is the correct way to "zoom into" a different TF?2. Sometimes the daily is comprised of 22 bars as opposed to 23. In other words, the opening time of the daily is 00:00 but the first one hour bar opens at 1:00am. How to connect both time frames in this scenario?  Thanks in advance, Thad
 20 Thaddeus_39 2016.07.27 09:43 #   In the script below, I "zoom into" the daily candle and draw a horizontal line on the 2nd lowest low of the 1 hour bars that make up the daily candle. In order to select the correct daily candle though, you have to select the time of the following candle.In other words, if you want to zoom into the Daily Candle[3], select iTime from Daily Candle[2].That happens because of how CopyRates work. Cheersint  start() {    RefreshRates();       double oneHourRate[];    ArraySetAsSeries(oneHourRate,true);       #define LEN 24       datetime daily_time = iTime(NULL,PERIOD_D1,2);     //select the opening time of                                                       //the daily candle[2]       int copied = CopyLow(Symbol(),PERIOD_H1,daily_time,LEN,oneHourRate);                                                       //Copy the lows of the 24 candles of the                                                       //1H chart that make up daily candle[3]                                                       //into the 1HourRate array    if(copied>0)    {   //algo to find the 2nd lowest value within the 1HourRate array       double secondLowest = lowest(oneHourRate, LEN);   //2nd lowest value in the array          ObjectCreate("Quasimodo",OBJ_HLINE,0,0,secondLowest);       Comment("time = ", daily_time);    }       else       Comment("CopyLow didn't work.");       return(0); } //+------------------------------------------------------------------+ //Functions //Find 2nd lowest double lowest(double &tempArray[],int sizeOfArray) {    int i;    double smaller, smallest;                  smallest = tempArray[0];         smaller = tempArray[1];         for(i=1; i < sizeOfArray; i++)         {                 if(tempArray[i] < smaller)                 {                         if(tempArray[i] < smallest)                         {                         smaller = smallest;                         smallest = tempArray[i];                         }                         else                                 smaller = tempArray[i];                 }         }         return smaller; }
 20 Thaddeus_39 2016.08.03 22:50 #   The following script does a much better job and it's cleaner.Using ArrayMaximum/Minimum I can easily select the 2nd extreme to the left or to the right of the extreme.I have added the conditions of bearish/bullish move on the daily.void OnStart()   { //---    RefreshRates();       #define _bar 2    int actualBar = _bar - 1;    bool Bullish;    int firstExtreme;    int secondExtreme;    double oneHourRate[];    ArraySetAsSeries(oneHourRate,true);           #define LEN 25       datetime daily_time = iTime(NULL,PERIOD_D1,actualBar);  //select the opening time of                                                            //the daily candle[_bar]       if(iClose(NULL,PERIOD_D1,_bar) - iOpen(NULL,PERIOD_D1,actualBar) >= 0)       Bullish = True;                                    //checking feature of candle    else       Bullish = False;       if(Bullish == True)    {       CopyLow(Symbol(),PERIOD_H1,daily_time,LEN,oneHourRate);  //saved 1H bars into oneHourRate[]       firstExtreme = ArrayMinimum(oneHourRate,WHOLE_ARRAY,0);  //1st lowest value in 1H TF       secondExtreme = ArrayMinimum(oneHourRate,LEN-firstExtreme,firstExtreme+1);//2nd lowest to the left    }    else    {       CopyHigh(Symbol(),PERIOD_H1,daily_time,LEN,oneHourRate);//saved 1H bars into oneHourRate[]       firstExtreme = ArrayMaximum(oneHourRate,WHOLE_ARRAY,0);  //1st highest value in 1H TF       secondExtreme = ArrayMaximum(oneHourRate,LEN-firstExtreme,firstExtreme+1);//2nd highest to the left    }          ObjectCreate("Quasimodo",OBJ_HLINE,0,0,oneHourRate[secondExtreme]);       Comment("time = ", daily_time); } //+------------------------------------------------------------------+

To add comments, please log in or register