Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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!
Can you help answer these questions from other members on NexusFi?
</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:
if (flagbar + 10 > CurrentBar) flagbar = 0;
This means that if 10 bars passed since the flagbar, we'll give up and start looking for a new setup.
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.
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.