highest bar close occuring within the last X number of bars . . . . - NinjaTrader Programming | futures io social day trading
futures io futures trading


highest bar close occuring within the last X number of bars . . . .
Updated: Views / Replies:11,802 / 37
Created: by jmejedi Attachments:5

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
 5  
 
Thread Tools Search this Thread
 

highest bar close occuring within the last X number of bars . . . .

  #11 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

Thanks forrestang,

I am trying to create a condition to enter "Long" when the current "Close" price "CrossAbove" the highest price from the previous 5 highs. I done this with two different ways, by creating a New Dataseries and also as a Double value but it seems that it is not working. Do you have any ideas why is not working? Thanks

1. double HighW=Math.Max(High[0],5);
if (CrossAbove(Close,HighWk1))
{...

2. HighWeekly.Set(Math.Max(High[0],5));
if (CrossAbove(Close,HighWeekly,1))
{...

Reply With Quote
 
  #12 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received


Loukas View Post
Thanks forrestang,

I am trying to create a condition to enter "Long" when the current "Close" price "CrossAbove" the highest price from the previous 5 highs. I done this with two different ways, by creating a New Dataseries and also as a Double value but it seems that it is not working. Do you have any ideas why is not working? Thanks

1. double HighW=Math.Max(High[0],5);
if (CrossAbove(Close,HighWk1))
{...

2. HighWeekly.Set(Math.Max(High[0],5));
if (CrossAbove(Close,HighWeekly,1))
{...

Did you not like the solution I posted? I think it does exactly what you where asking for. Just wondering if there was some reason you didn't go with that? There are dozens of ways to do what you want, what I posted was just one possible way of doing it.

The two examples you posted above will not accomplish what you want. You are referencing a C# function when you are using "Math.Max," and that function returns the HIGHEST of two values you pass it.

So for example when you pass it the value of "High[0]" and "5", it will simply return the highest value of those two numbers. In this case, you are passing it the HIGH of the current bar, and the number 5. So if you are using an instrument like EurUsd which is commonly 1.xxxx, the statement......... Math.Max(High[0],5) will ALWAYS return 5, cause the EurUsd doesn't trade that high. If you were applying that to say the TF which is currently trading above 600s, it will always return whatever 'High[0]' is. Does that make sense?

So if say you pass "Math.Max" two numbers, say 3 and 5, it will return 5. More examples.......

Math.Max( 3, 5) = 5
Math.Max( 5, 3) = 5
Math.Max( 20,2) = 20
Math.Max( 2, 20) = 20

Math.Min( 20,2) = 2
Math.Min( 3, 5) = 3


If you want to reference the highest value of a few bars ago, you will want to use the Ninjatrader Function "MAX()" as opposed to "Math.Max." I made this mistake a few weeks ago myself

Reply With Quote
 
  #13 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received


Hi forrestang,

thanks for your input. I applied your suggestion but it is not complited.
HighWeekly.Set(Max(High,5)[0]);
if (CrossAbove(Close,HighWeek,1))

or as double variable
double HighWeek=MAX(High,5)[0];
if (CrossAbove(Close,HighWeek,1))

Do you have any ideas how can I solve his issue?

Reply With Quote
 
  #14 (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,601 received
Forum Reputation: Legendary


Loukas View Post
Hi forrestang,

thanks for your input. I applied your suggestion but it is not complited.
HighWeekly.Set(Max(High,5)[0]);
if (CrossAbove(Close,HighWeek,1))

or as double variable
double HighWeek=MAX(High,5)[0];
if (CrossAbove(Close,HighWeek,1))

Do you have any ideas how can I solve his issue?

If you save your .cs file as it is and post it here, somebody will review and modify it. A common mistake is accessing bars with a negative index, that is looking back 5 bars from the first bar of the bar series. To avoid this problem, you would need to insert

 
Code
if(CurrentBar < 5)
return;
at the beginning of OnBarUpdate. But as long as I cannot see what you have coded, this is mere speculation.

Reply With Quote
The following user says Thank You to Fat Tails for this post:
 
  #15 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

Here is the file

Attached Files
Register to download File Type: cs AtrendtoTrendSample.cs (2.9 KB, 53 views)
Reply With Quote
 
  #16 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received


Loukas View Post
Here is the file

Ok, looks like you are creating an indicator, but trying to use things you would put into a strategy. This is why you couldn't compile.

What I usually do if I am wanting to do a strategy, start with an indicator first, then modify it to perform as a strategy. As most of the logic you create for your indie will work on a strategy depending on how you write it. In fact I usually just copy the entire script and paste it in my strategy and make minor changes.

When you want to create a strategy, you will want to go to Tools -> NewNinjaScript -> Strategy. Strategies are used to create an ATS(auto-trade strategy).

If you just want visual aids on your chart, you will want to go Tools -> NewNinjaScript -> Indicator. Indicators just are used to plot various visuals on your chart. So there is some difference between the two.

In either case, go through the editor, get to the last step then hit generate/unlock, and we'll start from there with the new .cs file you post in here.

Reply With Quote
 
  #17 (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,601 received
Forum Reputation: Legendary


Loukas View Post
Here is the file

In NinjaScript there is no such thing as Plot0, you just invented it. As it is a variable which is not declared, the compiler cannot read it. Try to replace Plot0[0] with Values[0][0].

Reply With Quote
 
  #18 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

""Ok, looks like you are creating an indicator, but trying to use things you would put into a strategy. This is why you couldn't compile.""

The problem is not there because I have done the same think from the beging with a simple condition EMA10 > EMA 20 and it is not make a trade because of the CrossAbove.

I change the condition with the statment below and it is working. The problem is this the CrossAbove and I cannot understad why.

if (Close[0]>=MAX(High,Weekly)[1])
{if ( EMA(5)[0]>EMA(24)[0]
enter long

Reply With Quote
 
  #19 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

I am trying something simple just to improve my skills, I have tried 3 ways but no one look to working eventhough they are compiled.
1. if (CurrentBar < Weekly )
return;
double HighWeek=MAX(High,Weekly)[0];
if (Close[0]>HighWeek)
{
EnterLong(DefaultQuantity, "");
}
2. HighWeek.Set(MAX(High,Weekly)[0]); if (CrossAbove(Close,HighWeek,1))
{
EnterLong(DefaultQuantity, "");
}
3.
if (Close[0]>MAX(High,Weekly)[0])
{
EnterLong(DefaultQuantity, "");
}
I dont thing so this is something sophisticated, I just cannot understand why is not working. Can someone guide me how to solve this .

Reply With Quote
 
  #20 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received

This is a STRATEGY not an Indicator


@Loukas

Start with this. Simple strategy that buys the breakout if CLOSE above the highest high of the past 5 bars. Conversely, it SELLS the breakout if CLOSE below lowest low of prior 5 bars.

It has set in it an arbitrary 8 tic profit target, with a 16 tic stoploss.

--EDIT---
Initially put the wrong file up there. It is correct now though if you downloaded before I typed this.

Attached Thumbnails
highest bar close occuring within the last X number of bars . . . .-prime2011-09-10_192358.jpg  
Attached Files
Register to download File Type: zip LoukasBarBreakout.zip (4.8 KB, 107 views)

Last edited by forrestang; September 10th, 2011 at 09:44 PM.
Reply With Quote
The following 3 users say Thank You to forrestang for this post:

Reply



futures io > > > > > highest bar close occuring within the last X number of bars . . . .

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
number of ticks in a bar/ms timestamp ? sam028 NinjaTrader Programming 15 September 21st, 2012 08:50 AM
How to program price cross below a number of previous bars Twiddle NinjaTrader Programming 8 May 17th, 2011 05:58 PM
how to count in nt7 the number of bars that have closed? anniebee321 NinjaTrader 9 April 26th, 2011 12:27 PM
How do I access the bar number under the cursor? koganam NinjaTrader Programming 3 September 6th, 2010 10:25 AM
Close[0] not waiting until bar close dsraider NinjaTrader Programming 4 February 11th, 2010 06:49 PM


All times are GMT -4. The time now is 01:57 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-13 in 0.13 seconds with 20 queries on phoenix via your IP 54.92.201.232