Why are we Stacking these Variables? - AmiBroker | futures.io
futures.io futures trading

Go Back   futures.io

> Futures Trading, News, Charts and Platforms > Platforms and Indicators > AmiBroker

Why are we Stacking these Variables?
Started:January 24th, 2012 (04:56 PM) by DonStar Views / Replies:1,307 / 1
Last Reply:January 25th, 2012 (09:18 AM) Attachments:0

Welcome to futures.io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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, and we will never resell your private information.

-- Big Mike

Thread Tools Search this Thread

Why are we Stacking these Variables?

Old January 24th, 2012, 04:56 PM   #1 (permalink)
Elite Member
Dallas, TX
Futures Experience: Intermediate
Platform: ToS, TradeGuider, eSignal, AmiBroker
Broker/Data: TD Ameritrade/eSignal
Favorite Futures: Stocks
DonStar's Avatar
Posts: 68 since Dec 2011
Thanks: 28 given, 40 received

Why are we Stacking these Variables?

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?

Reply With Quote

Old January 25th, 2012, 09:18 AM   #2 (permalink)
Trading Apprentice
Asheville, North Carolina
Futures Experience: Advanced
Platform: AmiBroker, Dynamic Trader, Metastock, FreeStockCharts, TradingView
Favorite Futures: stocks, options
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;

Last edited by colion; January 25th, 2012 at 09:23 AM.
Reply With Quote
The following 3 users say Thank You to colion for this post:


futures.io > Futures Trading, News, Charts and Platforms > Platforms and Indicators > AmiBroker > Why are we Stacking these Variables?

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Upcoming Webinars and Events (4:30PM ET unless noted)

NinjaTrader 8: Programming Profitable Trading Edges w/Scott Hodson

Elite only

Anthony Drager: Executing on Intermarket Correlations & Order Flow, Part 2

Elite only

Adam Grimes: Five critically important keys to professional trading

Elite only

Machine Learning Concepts w/FIO member NJAMC

Elite only

MarketDelta Cloud Platform: Announcing new mobile features

Dec 1

NinjaTrader 8: Features and Enhancements

Dec 6

Similar Threads
Thread Thread Starter Forum Replies Last Post
Global Variables In TS c12345 EasyLanguage Programming 6 July 23rd, 2012 04:48 AM
Exposing variables kaywai NinjaTrader Programming 4 April 14th, 2011 11:58 AM
Set Profit and Loss Variables brightredmegaphone NinjaTrader Programming 20 December 10th, 2010 06:21 PM
Global Variables and Strategies in Ninja 6.5 TonyA NinjaTrader Programming 3 November 6th, 2010 07:50 AM
Print format for Forex variables arjfca EasyLanguage Programming 2 October 3rd, 2010 09:57 AM

All times are GMT -4. The time now is 06:55 AM.

Copyright © 2016 by 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

Page generated 2016-10-27 in 0.08 seconds with 19 queries on phoenix via your IP