Higher high since event? - NinjaTrader Programming | futures io social day trading
futures io futures trading


Higher high since event?
Updated: Views / Replies:1,998 / 10
Created: by MXASJ 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
 1  
 
Thread Tools Search this Thread
 

Higher high since event?

  #1 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

Higher high since event?

Hi all,

I'm trying to code something in Ninja based on a paper I read. It's all straight forward to me except for one rule:

If the Close is above the MA, that is the setup bar. The next close above the MA that is higher than the close of that first setup bar is your long entry point.

Sounds simple but I'm scratching my head on this one. My fear is that it needs something like the ZigZag code.

Am I missing a simple way to do this?

Thanks!

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)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,214 received



MXASJ View Post
Hi all,

I'm trying to code something in Ninja based on a paper I read. It's all straight forward to me except for one rule:

If the Close is above the MA, that is the setup bar. The next close above the MA that is higher than the close of that first setup bar is your long entry point.

Sounds simple but I'm scratching my head on this one. My fear is that it needs something like the ZigZag code.

Am I missing a simple way to do this?

Thanks!

Perhaps just a flag would do it

 
Code
                            

#var
private int flagbar;

#onbarupdate
if (Close[0] > ma[0] and flagbar == 0)  flagbar CurrentBar;
else
flagbar 0;

if (
flagbar && Close[0] > Close[CurrentBar flagbar] and Close[0] > ma[0])
DoYourThing(); 
You'll need to reset flagbar back to 0 somewhere too, like once in a position or once a setup fails, whatever...

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #4 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

Thanks Mike!

I think I'm lost at the reset thing. This is where I am now:

 
Code
                            
private void HhLl()
{
if (
Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0] && flagbarlong == 0flagbarlong CurrentBar;
else
{
flagbarlong 0
}
if (
Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0] && flagbarshort == 0flagbarshort CurrentBar;
else
{
flagbarshort 0

}
 
protected 
override void OnBarUpdate()/////////////////////////////////////////////////////////////////
{
HhLl();
 
if (
Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0]
&& 
flagbarlong 0
)
GoLong();
 
if (
Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0]
&& 
flagbarshort 0
)
GoShort(); 
If I get a close above/below the the two MAs, it will enter on the next bar even if that bar below/above the two MAs. Ideas?

Attached Thumbnails
Higher high since event?-photo1.jpg  
Reply With Quote
 
  #5 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,214 received


MXASJ View Post
Thanks Mike!

I think I'm lost at the reset thing. This is where I am now:

 
Code
                            
private void HhLl()
{
if (
Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0] && flagbarlong == 0flagbarlong CurrentBar;
else
{
flagbarlong 0
}
if (
Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0] && flagbarshort == 0flagbarshort CurrentBar;
else
{
flagbarshort 0

}
 
protected 
override void OnBarUpdate()/////////////////////////////////////////////////////////////////
{
HhLl();
 
if (
Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0]
&& 
flagbarlong 0
)
GoLong();
 
if (
Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0]
&& 
flagbarshort 0
)
GoShort(); 
If I get a close above/below the the two MAs, it will enter on the next bar even if that bar below/above the two MAs. Ideas?

Yes, you must remember:

 
Code
                            
Close[0] > Close[CurrentBar flagbar
</span></span>In other words, remember to compare to [CurrentBar - flagbar], so we look xx bars back for that closing price. You are looking at 'now' (0).

As for reset, the thing is that if flagbar != 0 then the condition will never again reset the flagbar itself. So if it happened on bar 500, then it would never happen again past bar 500.

What you need to do is create a situation where flagbar is reset to 0 so it can start evaluating again. That could either be a failure of some sort, or it could be taking a position. If you only do it when you take a position just keep in mind there could be a bunch of bars between the flag bar and the position bar, so much so it could be irrelevant. I would probably recommend something like a 'max conditional bars' reference, something like:

 
Code
                            
if (flagbar 10 CurrentBarflagbar 0
This means that if 10 bars passed since the flagbar, we'll give up and start looking for a new setup.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #6 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

I'm still scratching my head on this one. Tried a few different variants, and the only thing that comes close is neither elegant nor 100% correct in following the original trading rule. Here is where I am. Commented out code is various things I tried in various combinations. FWIW I'm trying to code and reproduce the the results of the low-frequency macro strategy outlined by Klienman in his 2005 book "Trading Commodities and Financial Futures." I'll post it in the Elite methods section if I can reproduce his results.

 
Code
                            
private void HhLl()
{
if (
Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0] && flagbarlong == 0flagbarlong CurrentBar;
//if (flagbarlong + 10 > CurrentBar) flagbarlong = 0; 
else
{
flagbarlong 0
}
if (
Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0] && flagbarshort == 0flagbarshort CurrentBar;
//if (flagbarshort + 10 > CurrentBar) flagbarshort = 0;
else
{
flagbarshort 0

}
 
protected 
override void OnBarUpdate()/////////////////////////////////////////////////////////////////
{
//HhLl();
 
if (Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0]
&& 
Close[1] > EMA(fastMA)[1] && Close[1] > EMA(slowMA)[1]
//&& Close[2] > EMA(fastMA)[2] && Close[2] > EMA(slowMA)[2]
&& Close[0] > Close [1]// || Close[0] > Close [2]
//&& Close[0] > Close[CurrentBar-flagbarlong]
//&& flagbarlong > 0
)
GoLong();
 
if (
Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0]
&& 
Close[1] < EMA(fastMA)[1] && Close[1] < EMA(slowMA)[1]
//&& Close[2] < EMA(fastMA)[2] && Close[2] < EMA(slowMA)[2]
&& Close[0] < Close [1]// || Close[0] < Close [2]
//&& Close[0] < Close[CurrentBar-flagbarshort]
//&& flagbarshort > 0
)
GoShort(); 

Reply With Quote
 
  #7 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,214 received

You still aren't checking for a higher close against the flagbar.

 
Code
                            
if (Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0]
&& 
Close[1] > EMA(fastMA)[1] && Close[1] > EMA(slowMA)[1]
&& 
Close[0] > Close [1]
)
GoLong(); 
There is nothing there for the flagbar, so it's like the flagbar doesn't exist.

I don't understand the rules you need exactly, so I will keep it simple:

 
Code
                            
if (Close[0] > Close[CurrentBar flagbar] && flagbar 0)
GoLong(); 
This is the same thing I've said before Let me know if it doesn't work. Let me make it clear --- Close[CurrentBar - flagbar] .... very important...

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #8 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

Mike thanks for your input. I'm feeling very thick as I can't get this to trade. Feel free to give up on me, but this is where it stands:

 
Code
                            
private void HhLl()
{
if (
Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0] && flagbarlong == 0flagbarlong CurrentBar;
//if (flagbarlong + 10 > CurrentBar) flagbarlong = 0; 
else flagbarlong 0
 
if (
Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0] && flagbarshort == 0flagbarshort CurrentBar;
//if (flagbarshort + 10 > CurrentBar) flagbarshort = 0;
else flagbarshort 0;
 
if (
flagbarlong 10 CurrentBarflagbarlong 0;
if (
flagbarshort 10 CurrentBarflagbarshort 0;
}
 
protected 
override void OnBarUpdate()/////////////////////////////////////////////////////////////////

 
HhLl();
 
 
if (
//Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0]
//&& Close[1] > EMA(fastMA)[1] && Close[1] > EMA(slowMA)[1]
//&& 
Close[0] > Close[CurrentBar-flagbarlong] && flagbarlong 0
)
GoLong();
 
if (
//Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0]
//&& Close[1] < EMA(fastMA)[1] && Close[1] < EMA(slowMA)[1]
//&&
Close[0] < Close[CurrentBar-flagbarshort] && flagbarshort 0
)
GoShort();

The trade logic is as follows:

 
Code
                            
public class Kleinman Strategy
//Notes: Klienman refers to this strategy in Chapter 10. It has two basic rules:
//Using daily charts, a close above the 23 and 30 day SMA is the long set-up signal. If the market excedes the 
//high of the set-up bar, enter long. Opposite for shorts. The example in the book is "always in"... you are either
//long or short the market. There is a suggestion that identifying range-bound markets and sitting on the sidelines will reduce losses.
//Revisions: 
It's that "exceding the high of the setup bar" while it's still above/below the SMA that is giving me the agro. The closest I get using more brute-force coding (whats been commented out above) makes me want to pursue getting this right as it has some interesting results in backtesting.

Reply With Quote
 
  #9 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,214 received

MX,

The code you provided is not taking trades?

If so, please add some Print(Time[0] + " (" + CurrentBar + "): flagbar = " + flagbarlong) code and paste results.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #10 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received


OK. Since it is not taking trades I commented/uncommented out some code so it would take trades and Print() accordingly, as follows:

 
Code
                            
private void HhLl()
{
if (
Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0] && flagbarlong == 0flagbarlong CurrentBar;
//if (flagbarlong + 10 > CurrentBar) flagbarlong = 0; 
else flagbarlong 0

if (
Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0] && flagbarshort == 0flagbarshort CurrentBar;
//if (flagbarshort + 10 > CurrentBar) flagbarshort = 0;
else flagbarshort 0;

if (
flagbarlong 10 CurrentBarflagbarlong 0;
if (
flagbarshort 10 CurrentBarflagbarshort 0;
}

protected 
override void OnBarUpdate()/////////////////////////////////////////////////////////////////


HhLl();


if (
Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0]
&& 
Close[1] > EMA(fastMA)[1] && Close[1] > EMA(slowMA)[1]
//&& 
//Close[0] > Close[CurrentBar-flagbarlong] && flagbarlong > 0
)
GoLong();
Print(
Time[0] + " (" CurrentBar "): flagbar = " flagbarlong); 
if (
Close[0] < EMA(fastMA)[0] && Close[0] < EMA(slowMA)[0]
&& 
Close[1] < EMA(fastMA)[1] && Close[1] < EMA(slowMA)[1]
//&&
//Close[0] < Close[CurrentBar-flagbarshort] && flagbarshort > 0
)
GoShort();
Print(
Time[0] + " (" CurrentBar "): flagbar = " flagbarshort);

All of the print statements in the look like this (but with different date and time stamps:

2010-03-12 04:00:00 (695): flagbar = 0

None of the printed flagbar values != 0. The first one was (20) and the last (695).

Reply With Quote

Reply



futures io > > > > > Higher high since event?

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
In the trade before a scheduled news event cw30000 Traders Hideout 19 February 16th, 2016 04:46 PM
Millisecond timer event arjfca EasyLanguage Programming 5 July 3rd, 2011 07:37 AM
Need help with an event ghoti NinjaTrader Programming 1 March 14th, 2011 02:44 PM
event handling and calling a method kaywai NinjaTrader Programming 2 April 25th, 2010 02:21 PM
HH HL Higher highs, Higher lows emini_Holy_Grail Traders Hideout 3 January 22nd, 2010 05:10 PM


All times are GMT -4. The time now is 07:50 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.12 seconds with 20 queries on phoenix via your IP 54.226.132.197