Help Interpreting a Line of NT Code - NinjaTrader Programming | futures io social day trading
futures io futures trading


Help Interpreting a Line of NT Code
Updated: Views / Replies:513 / 8
Created: by BTR411 Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • 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.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Help Interpreting a Line of NT Code

  #1 (permalink)
Elite Member
NY, NY/USA
 
Futures Experience: Advanced
Platform: Investor/RT and TT XT
Broker/Data: DTN IQFeed, Rthmic, TT-NET
Favorite Futures: Energy Futures
 
BTR411's Avatar
 
Posts: 222 since Mar 2013
Thanks: 196 given, 1,176 received

Help Interpreting a Line of NT Code

All,

I am a non-programmer and am trying to understand the logic behind a portion of NT code from a VSA (VPA) indicator that has been posted on futures.io (formerly BMT).

The line of code in question is as follows:

x1 = (Close[0] - Low[0] == 0.00 ? avgSpread : (spread[0] / (Close[0] - Low[0])));

Is this considered it be an "If Then" statement? So IF the Close minus the Low was equal to zero, we would then use the (spread[0] / (Close[0] - Low[0]) to define x1?

At the same time, if the Close minus the Low does not equal zero, do we use the Close minus Low value then to define x1?

Any help or feedback on this is appreciated.

The code in its entirety was posted here https://futures.io/download/ninjatrader-7/indicators/623-download.html
BTR

If you can keep your wits about you while all others are losing theirs, and blaming you....The world will be yours and everything in it, what's more, you'll be a man, my son. - Kipling
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Market Wizard
virginia
 
Futures Experience: Intermediate
Platform: ninja
Favorite Futures: ES
 
cory's Avatar
 
Posts: 5,215 since Jun 2009
Thanks: 628 given, 6,311 received


.....................

Quoting 
C-like languages[edit]
C and C-like languages has a special ternary operator (? for conditional expressions with a function that may be described by a template like this:

condition ? evaluated-when-true : evaluated-when-false
This means that it can be inlined into expressions, unlike if-statements, in C-like languages:

my_variable = (x > 10) ? "foo" : "bar"; // In C-like languages
which can be compared to the Algol-family if-then-else expressions (and similar in Ruby and Scala, among others).

To accomplish the same using an if-statement, this would take more than one line of code (under typical layout conventions):

if (x > 10)
my_variable = 'foo';
else
my_variable = 'bar';
Some argue that the explicit if/then statement is easier to read and that it may compile to more efficient code than the ternary operator,[3] while others argue that concise expressions are easier to read than statements spread over several lines.



Last edited by cory; January 21st, 2015 at 05:23 PM.
Reply With Quote
The following user says Thank You to cory for this post:
 
  #4 (permalink)
Elite Member
NY, NY/USA
 
Futures Experience: Advanced
Platform: Investor/RT and TT XT
Broker/Data: DTN IQFeed, Rthmic, TT-NET
Favorite Futures: Energy Futures
 
BTR411's Avatar
 
Posts: 222 since Mar 2013
Thanks: 196 given, 1,176 received

Thanks Cory answering my post!

Just to make sure I understand this correctly, looking at the example line of code:

x1 = (Close[0] - Low[0] == 0.00 ? avgSpread : (spread[0] / (Close[0] - Low[0])));

So if I were to write it out in layman's terms:

x1 = (Close[0] - Low[0] == 0.00 THEN USE THE avgSpread; ELSE USE (spread[0] / (Close[0] - Low[0])));

Is this correct?

If you can keep your wits about you while all others are losing theirs, and blaming you....The world will be yours and everything in it, what's more, you'll be a man, my son. - Kipling
Reply With Quote
 
  #5 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,597 received
Forum Reputation: Legendary


BTR411 View Post
Thanks Cory answering my post!

Just to make sure I understand this correctly, looking at the example line of code:

x1 = (Close[0] - Low[0] == 0.00 ? avgSpread : (spread[0] / (Close[0] - Low[0])));

So if I were to write it out in layman's terms:

x1 = (Close[0] - Low[0] == 0.00 THEN USE THE avgSpread; ELSE USE (spread[0] / (Close[0] - Low[0])));

Is this correct?


I think that your understanding is correct.

But at the same time that line of code does not seem to make sense.

Let me explain why there is a problem.


Standard case (bar closes above the low): x1 holds a ratio > 1

Special case (shaven bottom, bar closes at the low): x1 holds the average spread

For example if you look at a 1 min chart for crude oil, the average spread of a few bars could be 0.05, that is much lower than the number used for the ratio, which is always larger than 1.

On the other hand, if you take a daily chart for YM, the average spread could we 200 points, much more than the ratio.

I think that there is a logical problem, as the values do have the same dimension.

Reply With Quote
 
  #6 (permalink)
Market Wizard
virginia
 
Futures Experience: Intermediate
Platform: ninja
Favorite Futures: ES
 
cory's Avatar
 
Posts: 5,215 since Jun 2009
Thanks: 628 given, 6,311 received


BTR411 View Post
Thanks Cory answering my post!

Just to make sure I understand this correctly, looking at the example line of code:

x1 = (Close[0] - Low[0] == 0.00 ? avgSpread : (spread[0] / (Close[0] - Low[0])));

So if I were to write it out in layman's terms:

x1 = (Close[0] - Low[0] == 0.00 THEN USE THE avgSpread; ELSE USE (spread[0] / (Close[0] - Low[0])));

Is this correct?

this is how it goes in my mind;

Either x1 = avgSpread OR x1 = spread[0] / (Close[0] - Low[0]) depending on Close[0] - Low[0] == 0.00 (True OR False).

Reply With Quote
 
  #7 (permalink)
Elite Member
NY, NY/USA
 
Futures Experience: Advanced
Platform: Investor/RT and TT XT
Broker/Data: DTN IQFeed, Rthmic, TT-NET
Favorite Futures: Energy Futures
 
BTR411's Avatar
 
Posts: 222 since Mar 2013
Thanks: 196 given, 1,176 received


Fat Tails View Post
I think that your understanding is correct.

But at the same time that line of code does not seem to make sense.

Let me explain why there is a problem.


Standard case (bar closes above the low): x1 holds a ratio > 1

Special case (shaven bottom, bar closes at the low): x1 holds the average spread

For example if you look at a 1 min chart for crude oil, the average spread of a few bars could be 0.05, that is much lower than the number used for the ratio, which is always larger than 1.

On the other hand, if you take a daily chart for YM, the average spread could we 200 points, much more than the ratio.

I think that there is a logical problem, as the values do have the same dimension.

Harry ,I see your point. I checked the Amibroker code that the NT version was developed from and the logic appears to be the same.

x1 is being used to determine where the close is in relation to the rest of the candle (clearly there are other ways to go about doing this). So following the line where x1 was defined, we have the following:

isUpCloseBar = (x1 < 2);
isDownCloseBar = (x1 > 2);
isMidCloseBar = (x1 < 2.2 && x1 > 1.8);
isVeryHighCloseBar = (x1 < 1.35);


Again, to a layman, I would think it is simpler to define the where the close is in relation to the rest of the candle using a percentage of the range. For example, a close in the top 30% of the range would be an up close bar, close in the lower 30% of the range is a down close bar, etc.

Any thoughts?

If you can keep your wits about you while all others are losing theirs, and blaming you....The world will be yours and everything in it, what's more, you'll be a man, my son. - Kipling
Reply With Quote
 
  #8 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,597 received
Forum Reputation: Legendary


BTR411 View Post
Harry ,I see your point. I checked the Amibroker code that the NT version was developed from and the logic appears to be the same.

x1 is being used to determine where the close is in relation to the rest of the candle (clearly there are other ways to go about doing this). So following the line where x1 was defined, we have the following:

isUpCloseBar = (x1 < 2);
isDownCloseBar = (x1 > 2);
isMidCloseBar = (x1 < 2.2 && x1 > 1.8);
isVeryHighCloseBar = (x1 < 1.35);


Again, to a layman, I would think it is simpler to define the where the close is in relation to the rest of the candle using a percentage of the range. For example, a close in the top 30% of the range would be an up close bar, close in the lower 30% of the range is a down close bar, etc.

Any thoughts?

If the bar closes 1 tick above the low, you would have x1 = Range[0]/TickSize, which is a pretty high value. If the bar closes at the bottom, a higher value should be selected. The indicator as it coded does not correctly address this problem.

If I had to code that indicator, I would replace the range with the extended tick range.

Range -> replace with -> 1 + (high-low)/ticksize
close - low -> replace with -> 1 + (close - low) / ticksize

Both are integer numbers. If you follow this idea, you get the folloing value

bar closes at the high: (x1 = 1)
bar closes at the midpoint: (x1 = 2)
bar closes at the low: (x1 = 1 + (high-low) / ticksize)

In that case the minimum value for the ratio is 1 (as expected) and the maximum value depends on the range of the bar.

The logic as shown in the NinjaTrader code seems to be flawed, as it does not offer an appropriate solution for the case where the bar closes at its low.

Reply With Quote
 
  #9 (permalink)
Elite Member
NY, NY/USA
 
Futures Experience: Advanced
Platform: Investor/RT and TT XT
Broker/Data: DTN IQFeed, Rthmic, TT-NET
Favorite Futures: Energy Futures
 
BTR411's Avatar
 
Posts: 222 since Mar 2013
Thanks: 196 given, 1,176 received

Thanks FatTails and Cory for all the input and help with this

If you can keep your wits about you while all others are losing theirs, and blaming you....The world will be yours and everything in it, what's more, you'll be a man, my son. - Kipling
Reply With Quote

Reply



futures io > > > > > Help Interpreting a Line of NT Code

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Line Break Code wizardremix NinjaTrader Programming 3 July 1st, 2014 02:12 AM
NT - How to set ATM Quantity via NT script code Adfra The Elite Circle 1 November 11th, 2013 04:00 AM
interpreting cumulative delta MarpleTrading Traders Hideout 4 December 18th, 2012 04:56 PM
Automated entries, exits, stops and targets..Without a single line of code! Alex91320 NinjaTrader 0 August 14th, 2012 05:29 PM
line won't go away in NT GaryD NinjaTrader 5 June 7th, 2012 05:07 AM


All times are GMT -4. The time now is 02:11 AM.

Copyright © 2017 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
Page generated 2017-12-11 in 0.15 seconds with 19 queries on phoenix via your IP 54.226.34.209