NexusFi: Find Your Edge


Home Menu

 





Help Interpreting a Line of NT Code


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one BTR411 with 4 posts (0 thanks)
    2. looks_two cory with 2 posts (1 thanks)
    3. looks_3 Fat Tails with 2 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 1,403 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 8 posts
    2. attach_file 0 attachments




 
Search this Thread

Help Interpreting a Line of NT Code

  #1 (permalink)
 
BTR411's Avatar
 BTR411 
NY, NY/USA
 
Experience: Advanced
Platform: Investor/RT and TT XT
Broker: DTN IQFeed, Rthmic, TT-NET
Trading: Energy Futures
Posts: 222 since Mar 2013
Thanks Given: 196
Thanks Received: 1,179

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 nexusfi.com (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
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
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
23 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #3 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


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

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.


Reply With Quote
Thanked by:
  #4 (permalink)
 
BTR411's Avatar
 BTR411 
NY, NY/USA
 
Experience: Advanced
Platform: Investor/RT and TT XT
Broker: DTN IQFeed, Rthmic, TT-NET
Trading: Energy Futures
Posts: 222 since Mar 2013
Thanks Given: 196
Thanks Received: 1,179

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
Started this thread Reply With Quote
  #5 (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


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)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


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)
 
BTR411's Avatar
 BTR411 
NY, NY/USA
 
Experience: Advanced
Platform: Investor/RT and TT XT
Broker: DTN IQFeed, Rthmic, TT-NET
Trading: Energy Futures
Posts: 222 since Mar 2013
Thanks Given: 196
Thanks Received: 1,179


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
Started this thread Reply With Quote
  #8 (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


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)
 
BTR411's Avatar
 BTR411 
NY, NY/USA
 
Experience: Advanced
Platform: Investor/RT and TT XT
Broker: DTN IQFeed, Rthmic, TT-NET
Trading: Energy Futures
Posts: 222 since Mar 2013
Thanks Given: 196
Thanks Received: 1,179

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
Started this thread Reply With Quote




Last Updated on January 21, 2015


© 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