int iTBT = iBarShift(NULL,PERIOD_D1, triggerBarTime, true); iHH = iHigh(NULL,PERIOD_D1,iTBT + 1);
Wouldn't this work?
To get yesterdays high.
double YesterdayHigh=iHigh(NULL,PERIOD_D1,1); // Yesterday high
double YesterdayOpenTime=iTime(NULL,PERIOD_D1,1); // yesterday open time
string YesterdayDate=TimeToStr(YesterdayOpenTime,TIME_DATE|TIME_MINUTES); // yesterday's date
To get yesterdays high.
Wouldn't this work?
I'm not 100% sure - I'm going to test this in a moment with what I need it for. It looks good to me at the moment. Thanks - Ill confirm in a moment.
I'm not 100% sure - I'm going to test this in a moment with what I need it for. It looks good to me at the moment. Thanks - Ill confirm in a moment.
int iTBT = iBarShift(NULL,PERIOD_D1, triggerBarTime, true); iHH = iHigh(NULL,PERIOD_D1,iTBT + 1);
Just remember that there may be errors due to updating a different time-frame from the current chart.
I am always a bit nervous about using possible endless loops and so I am not sure if this would be an improvement or not
int iTBT = -1 while (iTBT == -1) { int iTBT = iBarShift(NULL,PERIOD_D1, triggerBarTime, true); } iHH = iHigh(NULL,PERIOD_D1,iTBT + 1);
The idea being that the code will not progress from the while loop until the D1 data has updated.
Ok brilliant thanks - So I've had a little play about (not with the while loop as of yet though) and I am having a completely brain lapse moment on how to properly write this (sorry I'm sorry in advance for being a complete moron!).
This is the code I am using and I know I am doing it wrong... I'm simply wanting to compare where I am already successfully putting my pending order entry price, with the DAY BEFORE THAT'S (triggerbartime) HIGH / LOW (depending on buy / sell).
Thing is, iLLD is returning a "0"?
double ATR = iATR(NULL,60,14,1); double MA = iMA(NULL,60,MA_Period,0,1,0,1); double ATR_Pad = iATR(NULL,60,14,1)/2; //+---------------------------------------------------------------------------------------+ //|Order Sell Function | //+---------------------------------------------------------------------------------------+ if(direction==1) {//--Sell--// double Sell_Pad = NormalizeDouble(ATR_Pad,Digits); int iTBT_1 = iBarShift(NULL, 60, triggerBarTime, true), iLL = iLowest(NULL, 60, MODE_LOW, iTBT_1 + CandlesBeforeBiasObtained, 0); int iTBD_1 = iBarShift(NULL, PERIOD_D1, triggerBarTime, true), iLLD = iLow(NULL, PERIOD_D1, iTBD_1 + 1); // << This is returning a "0"? Print(" iLLD is iHigh price : ", iLLD ); double sellPrice ; // << Stores the sell price used in the pending order. if( triggerBarTime > 0 ) { if( iLLD - iLL > Point / 2. ) // << if Yesterdays Low is > than triggerbartime Low. { double Sell_Here1 = Low[iLL] - Sell_Pad; sellPrice = NormalizeDouble(Sell_Here1,Digits); Print(" Yesterdays Low is > Low of triggerbartime. Sell_Here1 is Yesterdays low price. Formula is: Low[",iLLD,"] - ", Sell_Pad, " = ", sellPrice); } if( iLL - iLLD > Point / 2. )// << if triggerbartime Low > Yesterdays Low. { double Sell_Here = Low[iLLD] - Sell_Pad; sellPrice = NormalizeDouble(Sell_Here,Digits); Print(" Low of triggerbartime > Yesterdays Low is. Sell_Here is triggerbartime low price. Formula is: Low[",iLLD,"] - ", Sell_Pad, " = ", sellPrice); } }
2013.10.09 16:28:31 2001.01.26 05:00 TF - Testing EURUSD,H1: Low of triggerbartime > Yesterdays Low is. Sell_Here is triggerbartime low price. Formula is: Low[0] - 0.0009 = 0.9217 2013.10.09 16:28:31 2001.01.26 05:00 TF - Testing EURUSD,H1: iLLD is iHigh price : 0
Ok brilliant thanks - So I've had a little play about (not with the while loop as of yet though) and I am having a completely brain lapse moment on how to properly write this (sorry I'm sorry in advance for being a complete moron!).
This is the code I am using and I know I am doing it wrong... I'm simply wanting to compare where I am already successfully putting my pending order entry price, with the DAY BEFORE THAT'S (triggerbartime) HIGH / LOW (depending on buy / sell).
Thing is, iLLD is returning a "0"?
You don't show the declaration of iLLD in your code. It needs to be a double, are you declaring it as an integer ?
if( iLLD - iLL > Point / 2. ) // << if Yesterdays Low is > than triggerbartime Low. // iLLD is a price, iLL is a shift index, you obviously intend to compare 2 prices. if( iLL - iLLD > Point / 2. ) // Same here. double Sell_Here = Low[iLLD] - Sell_Pad; // iLLD is a price, not a shift index.
Yup - You've highlighted how blind I am :P - My mistake... I had been looking at my code for far too long today, and missed these obvious areas. When I came back to it earlier on I realised, then read your post lol. Thank you for your time and help! Appreciate it a lot :)!!
//+---------------------------------------------------------------------------------------+ //|Order Sell Function | //+---------------------------------------------------------------------------------------+ if(direction==1) {//--Sell--// double Sell_Pad = NormalizeDouble(ATR_Pad,Digits); int iTBT_1 = iBarShift(NULL, 60, triggerBarTime, true), iLL = iLowest(NULL, 60, MODE_LOW, iTBT_1 + CandlesBeforeBiasObtained, 0); //Print(" iLL is Low[iLL]: ", Low[iLL]); int iTBD_1 = iBarShift(NULL, PERIOD_D1, triggerBarTime, true); double iLLD = iLow(NULL, PERIOD_D1, iTBD_1 + 1); double sellPrice ; // << Stores the sell price used in the pending order. if( triggerBarTime > 0 ) { if( iLLD - Low[iLL] > Point / 2. ) // << if Yesterdays Low is > than triggerbartime Low. { double Sell_Here1 = Low[iLL] - Sell_Pad; sellPrice = NormalizeDouble(Sell_Here1,Digits); } if( Low[iLL] - iLLD > Point / 2. )// << if triggerbartime Low > Yesterdays Low. { double Sell_Here = iLLD - Sell_Pad; sellPrice = NormalizeDouble(Sell_Here,Digits); } }
Yup - You've highlighted how blind I am :P - My mistake... I had been looking at my code for far too long today, and missed these obvious areas. When I came back to it earlier on I realised, then read your post lol. Thank you for your time and help! Appreciate it a lot :)!!
I would not suggest using D1 bars to determine yesterdays prices. I use a New York and London based broker that have different server times, thus D1 bars are different between the two brokers. You would be better off to use H1 bars and normalize your concept of a day to always be relative to UTC.
I am working on a similar problem to you at the moment. As mentioned I am testing against two brokers in different time zones. And to complicate matters I only want to trade during equity market open times. My concept of a day is the six hours the equity market is open, relative to the server time. To complicate matters, DST messes things up too. I want to work out the OHLC of the previous trading day and will be coding something generic to handle this.
You can find some handy time functions here: https://www.mql5.com/en/articles/1502
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use