Intraday data. Coding limit order buy bound to first bar price?

I have been struggling with

  • getting the close price on the very first bar in the day (1-minute data)
  • set a limit buy order at certain points/ percentage below this price from the first bar.

I read through the manual as well as this forum, but I did not find any answer.

can anybody help?
thank you in advance, MirkaLinda

The code I use, but generates too many inputs each day

SetTradeDelays (1,1,1,1);

LimitPrice = (Ref(O,-1)-0.2);
//Buy = Open;
Buy = Cross (Limitprice, o);

Sell =0;
ApplyStop (stopTypeProfit, stopModepoint, XXX);
ApplyStop (stopTypeLoss, stopModePoint, XXX);


Point 1:
Would this thread help you out? Price at specific date and time problem. (ValueWhen() and DateTimeDiff())

Point 2:
Your calculation for the limit price? Would it not be if any of the OHLC cross below the limit price?

@MirkaLinda how to determine the values of the first bar have been posted many times on this forum, using the analysis in the time frame you want (in your case 1 minute)

dn = Day();
// dn = DateNum(); // alternate method
newDay = dn != Ref( dn, -1 );

FirstBarOpen  = ValueWhen( newDay, Open );
FirstBarHigh  = ValueWhen( newDay, High);
FirstBarLow   = ValueWhen( newDay, Low );
FirstBarClose = ValueWhen( newDay, Close);

For limit orders study the Knowledge Base article (and other similar posts on the forum),


Thank you,
it seems logical, but does not resolve the first bar after market opening. Here it produces data from overnight corrections (I use intraday data from IB).
Sorry, I was not specific on that. Even if I use time such as 093000, it does not work..

Ad limit orders - I know you have been directing me to a thread about limit buy, but it works only on percentage, if I want to subtract certain number of points, I get lost..

Thank you all! Now it works.
after reading and combining, I found probably what I needed:
the code is now (if somebody is searching for the same):

tn = TimeNum();

StartTime = 93000;
Endtime = 153000;

StartBar = tn == StartTime;

MyL = ValueWhen( StartBar, L );

Buy = Cross ((MyL-0.2), o) AND tn >=StartTime AND tn <=EndTime ;