Why are we Stacking these Variables? - futures io
futures io futures trading

Why are we Stacking these Variables?

Discussion in Platforms and Indicators

Updated by colion
    1. trending_up 1,938 views
    2. thumb_up 3 thanks given
    3. group 1 followers
    1. forum 1 replies
    2. attach_file 0 attachments

Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

Search this Thread

Why are we Stacking these Variables?

(login for full post details)
  #1 (permalink)
Dallas, TX
Experience: Intermediate
Platform: ToS, TradeGuider, eSignal, AmiBroker
Broker: TD Ameritrade/eSignal
Trading: Stocks
DonStar's Avatar
Posts: 68 since Dec 2011
Thanks: 28 given, 41 received

Hi ALL: I have a piece of code written in AmiBroker AFL that I am trying to unserstand.

xBarIndex= BarIndex();
x= xBarIndex;
xLastValue= LastValue( x );
This is the output I get from the debug window:
Last value of x = 520
Bar Index = 511

Okay, 520 is the last bar of data. No matter which bar I select the LastValue is always 520. BarIndex in this example is 511, but it changes to a different number when I select a different bar.

So my question is: why put BarIndex() into the variable (xBarIndex)?

And then why put xBarIndex into another variable (x)?

And finally, whay use x to compute LastValue? Why not just do this:
xLastValue( BarIndex() )

I'm sure there is a reason behind this and I would like to understand the logic.

Can anyone help me understand this?

Visit my futures io Trade Journal Reply With Quote

Can you help answer these questions
from other members on futures io?
Scan by comparing SMAs within 5 mins
Tradestation behind Firewall
TOS Custom Implied Volatility Rank Watchlist/Scanner Column
portfolio maestro manage my strategies
Calendar Spread on Weekly Options
The Elite Circle
(login for full post details)
  #2 (permalink)
Asheville, North Carolina
Posts: 24 since Sep 2010
Thanks: 1 given, 15 received

You are dealing with poorly written code. BarIndex() returns an array in which the first bar is 0 in contrast to Barcount which is the number of bars (a single number) starting at 1. If this makes no sense, read the section of the Users Guide regarding arrays. So for the last bar BarIndex() = BarCount - 1.

All you need is one line: xBarIndex = LastValue(BarInddex();

You should read the Help and Users Guide for a full description of both and also look at the "Common Errors" section which discusses common errors using them.

In addition to reading Help and User Guide, put this little piece of code in a blank window and it will help you understand the difference as you click on different bars.

xBarIndex= BarIndex();
x= xBarIndex;
xLastValue= LastValue(BarIndex());//LastValue( x );
Title = "xbarindex=" + xbarindex + " x=" + x + " xlastvalue=" + LastValue(x) + " barcount = " + BarCount;

Reply With Quote
The following 3 users say Thank You to colion for this post:

futures io Trading Community Platforms and Indicators > Why are we Stacking these Variables?

January 25, 2012

Upcoming Webinars and Events

Relative Rotation Graphs w/Julius de Kempenaer

Elite only

Every journal equals ten meals for the hungry


Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts