Download MetaTrader 5

Bar values

To add comments, please log in or register
N22ko
49
N22ko  
Hi, is it possible to get bar values (open,close,high,low) of a bar at which a position was opened.
Keith Watford
Moderator
10359
Keith Watford  

Yes.

iBarshift with OrderOpenTime() will give you the shift of the bar

then get  the OHLC values

N22ko
49
N22ko  

Thanks for the response GumRai. I have another question is there a way to change the value of the date to be comprehendible instead of (in this example) 1424690100 when using OrderOpenTime(). I was able to use the OrderOpenPrice() successfully but I am having issues with OrderOpenTime().

ydrol
593
Keith Watford
Moderator
10359
Keith Watford  
N22:

Thanks for the response GumRai. I have another question is there a way to change the value of the date to be comprehendible instead of (in this example) 1424690100 when using OrderOpenTime(). I was able to use the OrderOpenPrice() successfully but I am having issues with OrderOpenTime().

I believe that if you use #property strict all prints of a datetime variable will be readable as a date, not an integer.

Otherwise, use TimeToStr() 

N22ko
49
N22ko  

Ok , I was able to sort out the date issue , but now as seen on the attached images of my Journal  and chart window, my iBarShift doesn’t correspond with my Date. Is there any solution for this? 

{
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_BUYSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists)
    {
        Print("Index of the bar for the time ",TimeToStr(OrderOpenTime(),TIME_DATE|TIME_SECONDS)," is ",iBarShift(0,0,TimeToStr(OrderOpenTime(),TIME_DATE|TIME_SECONDS)));
        
    }
}

 

 

  

 

Keith Watford
Moderator
10359
Keith Watford  

You don't use a string in iBarShift

iBarShift(Symbol(),0,OrderOpenTime())

 just use OrderOpenTime()

N22ko
49
N22ko  
ydrol and GumRai thanks for your time and information it was helpful. 
To add comments, please log in or register