Conditions true a varying number of bars back - NinjaTrader Programming | futures io social day trading
futures io futures trading


Conditions true a varying number of bars back
Updated: Views / Replies:233 / 9
Created: by DavidBodhi Attachments:1

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
 

Conditions true a varying number of bars back

  #1 (permalink)
Elite Member
Milwaukee, WI, USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: TF
 
DavidBodhi's Avatar
 
Posts: 41 since Oct 2014
Thanks: 1 given, 5 received

Conditions true a varying number of bars back

Can anyone suggest code that would allow a strategy to check whether conditions were true for the previous X number of bars, where X is a user-input parameter?

I'm not even sure how to clearly ask a search engine, so I thought I'd post here.

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
London UK
 
Futures Experience: Beginner
Platform: CQG
Favorite Futures: Futures
 
xplorer's Avatar
 
Posts: 2,923 since Sep 2015
Thanks: 6,287 given, 4,509 received
Forum Reputation: Legendary



DavidBodhi View Post
Can anyone suggest code that would allow a strategy to check whether conditions were true for the previous X number of bars, where X is a user-input parameter?

I'm not even sure how to clearly ask a search engine, so I thought I'd post here.

It's relatively simple - for example on NT7 it can be driven by the "new strategy" wizard.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


The screenshot shows where your user-defined parameter is. You can set a default there, which you can then change when you activate the strategy.

This is how I would do it, although there's probably other ways to do it.

Reply With Quote
 
  #4 (permalink)
Elite Member
Milwaukee, WI, USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: TF
 
DavidBodhi's Avatar
 
Posts: 41 since Oct 2014
Thanks: 1 given, 5 received


xplorer View Post
It's relatively simple - for example on NT7 it can be driven by the "new strategy" wizard.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


The screenshot shows where your user-defined parameter is. You can set a default there, which you can then change when you activate the strategy.

This is how I would do it, although there's probably other ways to do it.

Thanks for the reply, xplorer.

I'm aware of how to set a user-defined parameter. What I don't know how to do is use that parameter as a variable number of bar numbers.

For example, I can code:

if (Close[2] < KeltnerChannel(1.5, 10).Midline[2]
&& Close[1] < KeltnerChannel(1.5, 10).Midline[1]
&& Close[0] < KeltnerChannel(1.5, 10).Midline[0])
{ DO SOMETHING}

But I want one line that will do the same as the above when I input 3 as the user parameter, and do the equivalent of 4 or 5 or 25 lines like the above as I change that parameter.

(I *knew* I wasn't explaining clearly what I wanted...)

Reply With Quote
The following user says Thank You to DavidBodhi for this post:
 
  #5 (permalink)
Market Wizard
London UK
 
Futures Experience: Beginner
Platform: CQG
Favorite Futures: Futures
 
xplorer's Avatar
 
Posts: 2,923 since Sep 2015
Thanks: 6,287 given, 4,509 received
Forum Reputation: Legendary


DavidBodhi View Post
Thanks for the reply, xplorer.

I'm aware of how to set a user-defined parameter. What I don't know how to do is use that parameter as a variable number of bar numbers.

For example, I can code:

if (Close[2] < KeltnerChannel(1.5, 10).Midline[2]
&& Close[1] < KeltnerChannel(1.5, 10).Midline[1]
&& Close[0] < KeltnerChannel(1.5, 10).Midline[0])
{ DO SOMETHING}

But I want one line that will do the same as the above when I input 3 as the user parameter, and do the equivalent of 4 or 5 or 25 lines like the above as I change that parameter.

(I *knew* I wasn't explaining clearly what I wanted...)

Assuming I understand correctly now, it would be a matter of replacing (just taking one line of code as example)
if (Close[2] < KeltnerChannel(1.5, 10).Midline[2]

with

if (Close[MyInput0] < KeltnerChannel(1.5, 10).Midline[2]

unless I misunderstood again?

Reply With Quote
 
  #6 (permalink)
Elite Member
Milwaukee, WI, USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: TF
 
DavidBodhi's Avatar
 
Posts: 41 since Oct 2014
Thanks: 1 given, 5 received


xplorer View Post
Assuming I understand correctly now, it would be a matter of replacing (just taking one line of code as example)
if (Close[2] < KeltnerChannel(1.5, 10).Midline[2]

with

if (Close[MyInput0] < KeltnerChannel(1.5, 10).Midline[2]

unless I misunderstood again?

I'm afraid this won't work, either. If the input number was 25, it'd check if the 25th bar back was lower than Keltner Channel's midline 2 bars ago. Though changing the midline's [2] to [MyInput0] would compare Close[25] to midline[25], which is incrementally closer to what I want.
I need it to check whether all the last 25 bars were lower than the Keltner midline's values for those same bars.


Last edited by DavidBodhi; June 22nd, 2017 at 11:30 AM. Reason: HTML symbol confused me
Reply With Quote
 
  #7 (permalink)
Seth
Salt Lake City, Utah
 
Futures Experience: Beginner
Platform: Jigsaw, NinjaTrader8
Favorite Futures: ZB
 
Posts: 335 since Apr 2016
Thanks: 13 given, 270 received

You need some sort of loop. Here's a loop that I use to calculate how long we've been in a range for.

 
Code
int current = 0;
double high = High[current];
double low = Low[current];

do
{
  high = Math.Max(high, High[current]);
  low = Math.Min(low, Low[current]);
  current++;
}
while(high - low <= Width * TickSize && current < CurrentBar);

Reply With Quote
The following user says Thank You to TWDsje for this post:
 
  #8 (permalink)
Elite Member
Milwaukee, WI, USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: TF
 
DavidBodhi's Avatar
 
Posts: 41 since Oct 2014
Thanks: 1 given, 5 received


TWDsje View Post
You need some sort of loop. Here's a loop that I use to calculate how long we've been in a range for.

 
Code
int current = 0;
double high = High[current];
double low = Low[current];

do
{
  high = Math.Max(high, High[current]);
  low = Math.Min(low, Low[current]);
  current++;
}
while(high - low <= Width * TickSize && current < CurrentBar);

Ahhh... I get it. You use variables to track your conditions and then count how many times it's true.
Perfect. I can certainly use this concept for what I'm trying to do. Thank you!

But, I've never seen do/while before.
Does that mean keep doing the 'do' as long as the 'while' condition is true?

Reply With Quote
 
  #9 (permalink)
Seth
Salt Lake City, Utah
 
Futures Experience: Beginner
Platform: Jigsaw, NinjaTrader8
Favorite Futures: ZB
 
Posts: 335 since Apr 2016
Thanks: 13 given, 270 received


DavidBodhi View Post
Ahhh... I get it. You use variables to track your conditions and then count how many times it's true.
Perfect. I can certainly use this concept for what I'm trying to do. Thank you!

But, I've never seen do/while before.
Does that mean keep doing the 'do' as long as the 'while' condition is true?

A do while loop always executes the code in the block first, and then checks the variable. So in this instance I'm using the do while loop to ensure that it always executes at least once for bar 0. So a do while might not always be the right solution, but the same idea would apply to a foreach or while loop. Keep iterating back in bars until the condition is no longer true.


Last edited by TWDsje; June 22nd, 2017 at 02:13 PM.
Reply With Quote
The following user says Thank You to TWDsje for this post:
 
  #10 (permalink)
Elite Member
Milwaukee, WI, USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: TF
 
DavidBodhi's Avatar
 
Posts: 41 since Oct 2014
Thanks: 1 given, 5 received



TWDsje View Post
A do while loop always executes the code in the block first, and then checks the variable. So in this instance I'm using the do while loop to ensure that it always executes at least once for bar 0. So a do while might not always be the right solution, but the same idea would apply to a foreach or while loop. Keep iterating back in bars until the condition is no longer true.


Thank you. Much appreciated.

Reply With Quote

Reply



futures io > > > > > Conditions true a varying number of bars back

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Opening Breakouts and Reversals w/Al Brooks

Elite only
 

Introducing daytradr by Jigsaw, new stand-alone platform

Oct 19
 

RandBots: AutoTrading Bots to diversify your trading

Oct 24
 

TopstepTrader: Profiting Without Risking Your Own Money

Oct 26

Building Open Source Indicators for NT8 w/Fat Tails @ Lizard Indicators

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to color bars given certain conditions joegsr Beginners and Introductions 3 May 12th, 2017 04:58 AM
ATR Average True Range indicator expressed as a number? w00dmann NinjaTrader 5 March 17th, 2015 05:03 PM
Average True Range is Number billsingh NinjaTrader 2 January 30th, 2015 06:25 PM
Bars since last true Custom Column in Watchlist kamisyed ThinkOrSwim 1 October 12th, 2014 02:01 PM
True No Gap Range Bars? Techfan1128 NinjaTrader Programming 18 June 6th, 2012 01:31 AM


All times are GMT -4. The time now is 06:37 PM.

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-10-17 in 0.12 seconds with 20 queries on phoenix via your IP 54.81.178.153