NexusFi: Find Your Edge


Home Menu

 





Why are we Stacking these Variables?


Discussion in Platforms and Indicators

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




 
Search this Thread

Why are we Stacking these Variables?

  #1 (permalink)
 
DonStar's Avatar
 DonStar 
Dallas, TX
 
Experience: Intermediate
Platform: ToS, TradeGuider, eSignal, AmiBroker
Broker: TD Ameritrade/eSignal
Trading: Stocks
Posts: 77 since Dec 2011
Thanks Given: 28
Thanks Received: 43

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

 
Code
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 NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #2 (permalink)
colion
Asheville, North Carolina
 
Posts: 24 since Sep 2010
Thanks Given: 1
Thanks Received: 15

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
Thanked by:




Last Updated on January 25, 2012


© 2024 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 - Privacy Policy - Downloads - Top
no new posts