Higher high since event? - futures io
futures io futures trading



Higher high since event?


Discussion in NinjaTrader

Updated
    1. trending_up 3,323 views
    2. thumb_up 1 thanks given
    3. group 0 followers
    1. forum 10 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
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

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

 
Search this Thread
 

Higher high since event?

(login for full post details)
  #1 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

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!

Started this thread Reply With Quote

Journal Challenge February 2021 results (so far):
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(166 thanks from 30 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(114 thanks from 32 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(31 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #3 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,745 since Jun 2009
Thanks: 32,292 given, 97,494 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

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Big Mike for this post:
 
(login for full post details)
  #4 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 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
Click image for larger version

Name:	Photo1.JPG
Views:	79
Size:	33.5 KB
ID:	9548  
Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,745 since Jun 2009
Thanks: 32,292 given, 97,494 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

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #6 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 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(); 

Started this thread Reply With Quote
 
(login for full post details)
  #7 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,745 since Jun 2009
Thanks: 32,292 given, 97,494 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

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #8 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 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.

Started this thread Reply With Quote
 
(login for full post details)
  #9 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,745 since Jun 2009
Thanks: 32,292 given, 97,494 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

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #10 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 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).

Started this thread Reply With Quote
 
(login for full post details)
  #11 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,745 since Jun 2009
Thanks: 32,292 given, 97,494 received

Ok so the problem is here

 
Code
                            
if (Close[0] > EMA(fastMA)[0] && Close[0] > EMA(slowMA)[0] && flagbarlong == 0flagbarlong CurrentBar;
//if (flagbarlong + 10 > CurrentBar) flagbarlong = 0; 
else flagbarlong 0
</span></span>
That is not evaluating to true, ever.

When you defined flagbarlong in #var, you defined it as an int and set it to 0 yes?

Try removing the && flagbarlong == 0 from above, just to make sure the condition starts working.

Sorry I can't just run the code on my side, but I haven't even opened NinjaTrader in 2 weeks and it feels good

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Higher high since event?


Last Updated on March 13, 2010


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
     



Copyright © 2021 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