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.
Cheers
int 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; }
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); } //+------------------------------------------------------------------+
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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):
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