Download MetaTrader 5
To add comments, please log in or register
Start making profit using the Market. Publish your product!
N22ko
49
N22ko 2015.06.22 01:43 
Hi, is it possible to get bar values (open,close,high,low) of a bar at which a position was opened.
Keith Watford
Moderator
7952
Keith Watford 2015.06.22 07:31  

Yes.

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

then get  the OHLC values

N22ko
49
N22ko 2015.06.25 05:38  

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
594
Keith Watford
Moderator
7952
Keith Watford 2015.06.25 22:21  
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 2015.06.26 02:40  

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
7952
Keith Watford 2015.06.26 02:50  

You don't use a string in iBarShift

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

 just use OrderOpenTime()

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