I think you probably mean . . .
iClose(NULL,0,1) and Close[1] iOpen(NULL,0,1) and Open[1]
I suspect that Close[1] will be quicker as it is simply accessing an array rather than calling a function. obviously iClose is more flexible . . . but if you never need to use it with a different Symbol or Period then I would use Close[1]
I suspect that the value of Close[0] is never correct, what you want if you want the correct value for "Close[0]" as soon as possible then you really want Close[1] on the first tick of the new bar 0.
I think you probably mean . . .
I suspect that Close[1] will be quicker as it is simply accessing an array rather than calling a function. obviously iClose is more flexible . . . but if you never need to use it with a different Symbol or Period then I would use Close[1]
I suspect that the value of Close[0] is never correct, what you want if you want the correct value for "Close[0]" as soon as possible then you really want Close[1] on the first tick of the new bar 0.
Close[0] gives you the acutal Bid price
I always use:
extern string Trading.Symbol="EURUSD" extern int Trading.Period=60; //H1 iOpen(Trading.Symbol,Trading.Period,1)
simply for the reason that you can switch by accident symbol or timeframe and you EA will still do it's work correctly. Speed is not a relevant thing with such functions
I think you probably mean . . .
I suspect that Close[1] will be quicker as it is simply accessing an array rather than calling a function. obviously iClose is more flexible . . . but if you never need to use it with a different Symbol or Period then I would use Close[1]
I suspect that the value of Close[0] is never correct, what you want if you want the correct value for "Close[0]" as soon as possible then you really want Close[1] on the first tick of the new bar 0.
Yes, that’s right iClose (NULL, 0, 1). I am not a programmer, but may you point me in the right direction what should I look for MQL4 code for new bar 0.
Thank you.
Close[0] gives you the acutal Bid price
I always use:
simply for the reason that you can switch by accident symbol or timeframe and you EA will still do it's work correctly. Speed is not a relevant thing with such functions
Interesting, Thank you.
but may you point me in the right direction what should I look for MQL4 code for new bar 0.
The current bar that is forming is always bar number 0, so if we are on a H1 chart and watching the 16:00 bar form and want to know it's correct Close value we have to wait until the first tick of the next "new bar 0" . . i.e. the first tick of the 17:00 bar . . . then read the Close value for bar 1 (16:00 bar). I did something like this yesterday . . let me see . .
datetime Bar1Time=Time[1]; double CloseOfBar0_ASAP; int start() { if (Bar1Time != Time[1]) // 1st tick of new bar { . . . // do stuff here that you want to do just on the first tick of a new bar, e.g. CloseOfBar0_ASAP = Close[1]; . . Bar1Time = Time[1]; }
The current bar that is forming is always bar number 0, so if we are on a H1 chart and watching the 16:00 bar form and want to know it's correct Close value we have to wait until the first tick of the next "new bar 0" . . i.e. the first tick of the 17:00 bar . . . then read the Close value for bar 1 (16:00 bar). I did something like this yesterday . . let me see . .
Wow, this was more than I expected. Thank you I can use the time to determine a new bar.
Wow, this was more than I expected. Thank you I can use the time to determine a new bar.
You'r welcome . . . . should really do this: Bar1Time=Time[1]; within init() otherwise if you change Time Frames things could go wrong ;-) but hopefully you get the idea . . .
Raptor,
May you please help me a lilttle more?
I am trying to close any open order at the first tick of a new bar. For example on an 1H or 4HR chart close any existing order on the first tick of the new bar.
if (Bar1Time != Time[1]) // 1st tick of new bar
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Gold); // close position
CloseOfBar0_ASAP = Close[1];
Bar1Time = Time[1];
return(0); // exit
}
Did I miss something? (Sorry I am not a programmer, just know enough to be dangerous)
Thank you in advance.
To use functions like OrderTicket() and OrderLots() you first have to select the order using OrderSelect() . . did you do that ? also, if you use OrderClosePrice() (instead of Bid) it will work for an OP_BUY or an OP_SELL
I thought I did.
//+------------------------------------------------------------------+
//|Trailing Stop |
//|Setup 1H or daily charts |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Global Variables / Includes |
//+------------------------------------------------------------------+
extern double StopLoss = 250; // StopLoss
extern double TrailingStop = 250; //Trailing Stop
extern double BreakPoiont = 100; // Breakout points
extern double TakeProfit = 350; //Take Profit
extern double TI = 60; //Short term Trading Indicator time frame
extern int MagicNumber = 602231220;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int cnt, total, tradecnt, ticket, err;
tradecnt=0;
total=OrdersTotal();
//=========================== Set Trading Criterias ==============================
double SL = StopLoss*Point; // StopLoss
double TP = TakeProfit*Point; // TakeProfit
double P = BreakPoiont*Point; // Breakout points
double TS = TrailingStop*Point; //Trailing Stop
double H=iHigh(NULL,TI,0);
double L=iLow(NULL,TI,0);
double C=iClose(NULL,TI,0);
double O=iOpen(NULL,TI,0);
datetime Bar1Time=Time[1];
double CloseOfBar0_ASAP;
//================= Close or Apply Trailing Stop Lost =====================
if (total> 0)
{
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol() && // check for symbol
OrderMagicNumber() == MagicNumber ) //check for EA Assing Number
{
// should it be closed?
if(OrderType()==OP_BUY) // long position is opened
{
// check for long position (BUY) possibility
// check for ZERO StopLoss
if(OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),C-TS,OrderTakeProfit(),0,Yellow);
return(0); // exit
}
else
{
if (Bar1Time != Time[1]) // 1st tick of new bar
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Gold); // close position
CloseOfBar0_ASAP = Close[1];
Bar1Time = Time[1];
return(0); // exit
}
else
{
if(OrderStopLoss()==(C-TS))
return(0); // exit
{
if(C-OrderStopLoss()>TS)
{
if(OrderStopLoss()<(C-TS))
{
OrderModify(OrderTicket(),OrderOpenPrice(),C-TS,OrderTakeProfit(),0,Yellow);
return(0);
}
}
}
}
}
}
else // go to short position
{
// check for short position (SELL) possibility
// check for ZERO StopLoss
if(OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),C+TS,OrderTakeProfit(),0,Yellow);
return(0); // exit
}
else
{
if (Bar1Time != Time[1]) // 1st tick of new bar
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Gold); // close position
CloseOfBar0_ASAP = Close[1];
Bar1Time = Time[1];
return(0); // exit
}
else
{
if(OrderStopLoss() == (C+TS))
return(0); // exit
{
// check for Long Trailing Stop
if((OrderStopLoss()-C)>(TS))
{
if(OrderStopLoss() > (C+TS))
{
OrderModify(OrderTicket(),OrderOpenPrice(),C+TS,OrderTakeProfit(),0,Yellow);
return(0);
}
}
}
}
}
}
}
}
}
return(0);
}
// the end.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Need help with two (2) questions with close price . Please help.
1st: Is there a difference on the followings:
iClose(NULL,NULL,1) and Close[1]
iOpen(NULL,NULL,1) and Open[1]
also on high & low....
If there is no difference, when its best to use one over the other?
2nd: Open, Low, & High are easy to determine. When does the close [0] is set on a present bar? Example Close[0] or iClose(NULL,NULL,0)
Thank you in advance.