- 189 All Categories
- 1 Getting Started with Forums
- 48 General Discussion
- 1 Tips and Tricks
- 17 CQG Integrated Client
- 18 CQG QTrader
- 36 CQG Desktop
- 7 CQG Mobile
- 1 CQG to Microsoft Excel
- 3 Microsoft Excel to CQG
- 5 Microsoft Excel Toolkit Add-ins
- 1 CQG T
- 1 CAST
- 12 API
- 6 Historical Data
- 11 Trading
- 12 Charting
- 5 Trade Systems and Backtesting

Copyright © 2019 CQG, Inc. All rights reserved worldwide. CQG®, DOMTrader®, TFlow®, and Data Factory™ are trademarks of CQG, Inc.

## Comments

To start, you will want to make use of the Hour(@) and Minute(@) functions to get the current time. You will multiply the Hour(@) by 60 and add it to the minute to get the current day's time integer. In a custom study, you will create four parameters for the example you propose, such as "hour1," "minute1," "hour2," and "minute2."

Then you might code the formula as follows:

a1:= Hour(@)*60 + Minute(@);

b1:= hour2 *60 + minute2;

c1:= hour1*60 + minute1;

d1:= (Close(@),D)[-1];

e1:= a1 xabove b1;

price:= IF(a1 >=b1, g1, f2);

f1:= a1 xabove c1;

f2:= IF(a1 >= c1, h1, d1) ;

g1:= Close(@) When e1;

h1:= Close(@) When f1;

price

I used variables because that usually makes my studies easier to follow, but in this case, it might have been easier to just write it as a large "nested if" statement. Basically, it checks to see if the current time is equal to or greater than the latest time parameter. If it is, then it returns "g1" which is the price of the instrument when that condition became true, and if not, checks for the earlier time parameter. Finally, if it is earlier in the day than either time parameter, I told it to give me the previous day's close ("d1").