NexusFi: Find Your Edge


Home Menu

 





Higher high since event?


Discussion in NinjaTrader

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




 
Search this Thread

Higher high since event?

  #1 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

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

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Exit Strategy
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
27 thanks
Diary of a simple price action trader
26 thanks
Tao te Trade: way of the WLD
23 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
9 thanks
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,440 since Jun 2009
Thanks Given: 33,207
Thanks Received: 101,599



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 the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

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:	208
Size:	33.5 KB
ID:	9548  
Started this thread Reply With Quote
  #5 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,440 since Jun 2009
Thanks Given: 33,207
Thanks Received: 101,599


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 the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

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
  #7 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,440 since Jun 2009
Thanks Given: 33,207
Thanks Received: 101,599

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 the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #8 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

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
  #9 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,440 since Jun 2009
Thanks Given: 33,207
Thanks Received: 101,599

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 the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #10 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


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




Last Updated on March 13, 2010


© 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