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,860 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?
$4.5M Floods Russia Nuclear Contract in 24 Hours -- Krem …
Prediction Markets & Event Contracts
Fabrication or Framework? Irans Denied MOU Explains the …
Prediction Markets & Event Contracts
Al Arabiya: US-Iran Draft Deal Within Hours Contains Hor …
Prediction Markets & Event Contracts
$500M Riding on World Cup 2026: France/Spain Co-Favored …
Prediction Markets & Event Contracts
Iran Airspace Collapses 18 Points to 15.5% While Hormuz …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
1 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