NexusFi: Find Your Edge


Home Menu

 





Assign value to the close price at a specific time


Discussion in Platforms and Indicators

Updated
    1. trending_up 2,774 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
sunsun
hong kong
 
Posts: 6 since May 2013
Thanks Given: 1
Thanks Received: 1

Hi, I would like to assign the close of a specific time to a variable but I still couldn't figure out. I really appreciate if someone can give me a hand. The logic is as follows,

if time = 093000 then
refprice = close;


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Day 96 Missiles Hit Kuwait and Bahrain: June 15 Peace at …
Prediction Markets & Event Contracts
Kalshi Sets $4.13B All-Time Weekly Record as Polymarket …
Prediction Markets & Event Contracts
Victory Day Delivers: Russia-Ukraine Ceasefire Market Cl …
Prediction Markets & Event Contracts
The Confluence Meter: A Multi-Layered Signal Framework B …
The Elite Circle
Orban Crashes to 21pct on Record Turnout -- McIlroy Drop …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #2 (permalink)
 prouser 
Zurich/Switzerland
 
Posts: 79 since Oct 2014


sunsun View Post
Hi, I would like to assign the close of a specific time to a variable but I still couldn't figure out. I really appreciate if someone can give me a hand. The logic is as follows,

if time = 093000 then
refprice = close;

Not sure what you wanna do with it but here you can see the difference between using ValueWhen and Iif.
See the help description of those two functions

 
Code
timecondition = TimeNum() == 093000;
iifclose = IIf( timecondition, Close, Null );
valclose = ValueWhen( timecondition, Close );

// Plot
SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
Plot( iifclose, "iifclose", colorRed, styleHistogram, Null, Null, 0, 0, width = -60 );
Plot( valclose, "valclose", colorOrange, styleLine, Null, Null, 0, 0, width = -20 );
If you wanna calculate some average or other calculations based on those specific time close prices only then you have to use different function(s). SparseCompress and SparseExpand. 5.91 has built-in functions of those ones, for older AB versions you have to use AFL functions. See AmiBroker 5.91.0 BETA Read Me


Reply With Quote
  #3 (permalink)
 prouser 
Zurich/Switzerland
 
Posts: 79 since Oct 2014



prouser View Post
If you wanna calculate some average or other calculations based on those specific time close prices only then you have to use different function(s). SparseCompress and SparseExpand. 5.91 has built-in functions of those ones, for older AB versions you have to use AFL functions. See AmiBroker 5.91.0 BETA Read Me


 
Code
// for versions lower than 5.91 use AFL functions of sparsecompress/expand
//http://www.amibroker.com/devlog/wp-content/uploads/2015/02/readme5910.html

Version( 5.91 );

SetBarsRequired( 10000, 10000 );

timecondition = TimeNum() == 093000;
only_when = timecondition; // only when condition
x = SparseCompress( only_when, Ref( Close, -1 ) ); // compact sparse data, Close of 09:29:59.999
y = MA( x, 10 ); // regular calculation
y = SparseExpand( only_when, y ); // expand sparse data

// Plot
SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
Plot( C, "Price", colorDefault, styleBar, Null, Null, 0, 0, width = -20 );
Plot( ValueWhen( timecondition, y ), "Sparse MA from time condition", colorRed );

// exploration
Filter = timecondition;
AddColumn( Ref( Close, -1 ), "Close of 09:29:59.999", 1.5 );


Reply With Quote




Last Updated on March 3, 2015


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts