NexusFi: Find Your Edge


Home Menu

 





Bars Ago in an indicator


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one patbateman with 8 posts (1 thanks)
    2. looks_two Tasker_182 with 7 posts (8 thanks)
    3. looks_3 Fat Tails with 3 posts (3 thanks)
    4. looks_4 cory with 1 posts (3 thanks)
      Best Posters
    1. looks_one cory with 3 thanks per post
    2. looks_two bobwest with 2 thanks per post
    3. looks_3 Tasker_182 with 1.1 thanks per post
    4. looks_4 Fat Tails with 1 thanks per post
    1. trending_up 11,108 views
    2. thumb_up 19 thanks given
    3. group 7 followers
    1. forum 22 posts
    2. attach_file 1 attachments




 
Search this Thread

Bars Ago in an indicator

  #11 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


patbateman View Post
The bars ago function does NOT work when creating ninjascript for indicators. It ONLY works for creating indicators for strategies.

In other words, if you make an indicator that is simply Close[10], it will not function. It will compile, but the compiler will not read it.

So, I'm trying to figure out a way to use something like bars ago that does not involve the traditional approach.

If I can get just Close[0] - Close[20] to work, I can go from there.

Hope this helps!

The method works for all indicators, but you can only access Close[20] for bars > 20. You need to add the following line in the beginning of OnBarUpdate()

 
Code
if (CurrentBar < 20)
 return;


and the code should run after compiling it.

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Increase in trading performance by 75%
The Elite Circle
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
18 thanks
GFIs1 1 DAX trade per day journal
16 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
  #12 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401

I think this clarifies it...

Abbott: You throw the ball to first base.
Costello: Then who gets it?
Abbott: Naturally.
Costello: Naturally.
Abbott: Now you've got it.
Costello: I throw the ball to Naturally.
Abbott: You don't! You throw it to Who!
Costello: Naturally.
Abbott: Well, that's it—say it that way.
Costello: That's what I said.
Abbott: You did not.
Costello: I said I throw the ball to Naturally.
Abbott: You don't! You throw it to Who!
Costello: Naturally.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
Thanked by:
  #13 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



Tasker_182 View Post
I think this clarifies it...

Abbott: You throw the ball to first base.
Costello: Then who gets it?
Abbott: Naturally.
Costello: Naturally.
Abbott: Now you've got it.
Costello: I throw the ball to Naturally.
Abbott: You don't! You throw it to Who!
Costello: Naturally.
Abbott: Well, that's it—say it that way.
Costello: That's what I said.
Abbott: You did not.
Costello: I said I throw the ball to Naturally.
Abbott: You don't! You throw it to Who!
Costello: Naturally.


I was not aware that Abbott and Costello were traders?

Reply With Quote
  #14 (permalink)
 
patbateman's Avatar
 patbateman 
NY, NY
 
Experience: None
Platform: T4, NinjaTrader
Trading: All!
Posts: 235 since Mar 2012
Thanks Given: 113
Thanks Received: 200


Tasker_182 View Post
Maybe I'm overthinking this. Lets use your example as an example, Close[0] - Close[20]

if you create a variable to put the results in, will that not meet your needs?

IE:

double diff = Close[0] - Close[20] ;

So the above code statement declares a variable called "diff" that is a double type. Next (on the other side of equals) the difference between Close[0] and Close[20] is put into diff. The ";" ends the C# statement.

Is that what you want?

Tried this, and it didn't work.

Also tried doing them in separate Ninjascript files... no go...

I confirmed with NT help, that bars ago does not work in indicators, only strategies.

"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote
  #15 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


Fat Tails View Post
I was not aware that Abbott and Costello were traders?

I believe they traded quips, quite frequently.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
Thanked by:
  #16 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


patbateman View Post
Tried this, and it didn't work.

Also tried doing them in separate Ninjascript files... no go...

I confirmed with NT help, that bars ago does not work in indicators, only strategies.

Maybe you need to share with us the whole thing you are trying to do because there is clearly misunderstanding of your needs.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
  #17 (permalink)
 
patbateman's Avatar
 patbateman 
NY, NY
 
Experience: None
Platform: T4, NinjaTrader
Trading: All!
Posts: 235 since Mar 2012
Thanks Given: 113
Thanks Received: 200

Not sure how much more clear I can get.

There are TWO types of ninjascripts: INDICATORS and STRATEGIES.

The BARS AGO function *ONLY* works for STRATEGIES.

So I need to write

Close[0]-Close[30]

in an alternate way WITHOUT using the [30]. That is all. No need to debate if this is true or not, since confusion on that part is irrelevant, since I've confirmed the issue with NT staff.



Again,

How can I write

Close[0]-Close[10]

in a way that does not use the [10]?

"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote
  #18 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


patbateman View Post
Not sure how much more clear I can get.

There are TWO types of ninjascripts: INDICATORS and STRATEGIES.

The BARS AGO function *ONLY* works for STRATEGIES.

So I need to write

Close[0]-Close[30]

in an alternate way WITHOUT using the [30]. That is all. No need to debate if this is true or not, since confusion on that part is irrelevant, since I've confirmed the issue with NT staff.



Again,

How can I write

Close[0]-Close[10]

in a way that does not use the [10]?


int barsAgo = 10;

double diff = Close[0] - Close[barsAgo];

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
Thanked by:
  #19 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,168 since Jan 2013
Thanks Given: 57,442
Thanks Received: 26,277


Fat Tails View Post
The method works for all indicators, but you can only access Close[20] for bars > 20. You need to add the following line in the beginning of OnBarUpdate()

 
Code
if (CurrentBar < 20)
 return;


and the code should run after compiling it.


patbateman View Post
Tried this, and it didn't work.

Also tried doing them in separate Ninjascript files... no go...

I confirmed with NT help, that bars ago does not work in indicators, only strategies.


patbateman View Post
Not sure how much more clear I can get.

There are TWO types of ninjascripts: INDICATORS and STRATEGIES.

The BARS AGO function *ONLY* works for STRATEGIES.

So I need to write

Close[0]-Close[30]

in an alternate way WITHOUT using the [30]. That is all. No need to debate if this is true or not, since confusion on that part is irrelevant, since I've confirmed the issue with NT staff.



Again,

How can I write

Close[0]-Close[10]

in a way that does not use the [10]?

Sorry, but everyone who is trying to help you writes indicators and uses the [bars ago] routinely in their indicators.

Close[0] - Close[10] works just fine in indicators; we all do this all the time. You just need to have the statement @Fat Tails mentioned to check that you have enough bars available to make the subtraction.

There may be a misunderstanding between you and NT support about what you are trying to accomplish, but, believe me, everyone who writes indicators uses the Close[bars ago] expression successfully. I do it and it works fine.

If you post the full code that is having a problem, I'm sure someone will help you fix it.

Bob.

When one door closes, another opens.
-- Cervantes, Don Quixote
Reply With Quote
Thanked by:
  #20 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


@patbateman: You can use barsAgo without limitations in indicators. The problem is that you do not disclose the information necessary to solve your problem. We cannot fix your bug, if you do not show us the code.

Please export the indicator with NinjaTrader and post it here. In a few minutes the bug will be identified and the discussion will be over.

Reply With Quote
Thanked by:




Last Updated on January 13, 2014


© 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