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 have an idea regarding trading the YM. I am having a difficult time with the
coding of the stops. I think I know how to take the stop loss stop and turn
it into a breakeven stop. Unfortunately I don't know how to move the breakeven
up with each upward (downward) tick of the YM.
If the YM is above the breakeven by 10 points that is fine.
If the YM goes up one point I would need the breakeven to turn into a trailing
stop, with the YM still above the stop (in this case trailing) by 10 points.
Someone at another forum gave me some code, and some of that is here:
First the coding might be wrong, but besides that there would have to
be a few hundred lines of code (just for a bull move) as the YM moves
up. A little block something like the above for every tick up. What if
the YM moves up 50 points?!
Anyway I was hoping that someone already had this problem and had it
answered, or at least maybe someone has an idea to create a loop
(or equivalent) with NinjaScript to avoid writing such a long program.
(Back tomorrow if possible.)
- Stephen
Can you help answer these questions from other members on NexusFi?
This code was written by a consultant for another project of mine. I have parsed out specifics for stops: perhaps it might be useful as you develop your code. Sorry, I cant support it as I am barely at the point of understanding what parts of the strategy go where, but I am trying!
I also tried for weeks to have a trail code "functioning" in my strategies. Can certainly understand the stress and frustration when days and nights were spent and nothing seemed working.
Just got the enclosed sample and hope it may help you. Good Luck!
Sorry to throw in another idea here which is opposite to yours. I learned the following from a more experienced member:
Quote
Due to its inherent design, Ninja forces limitations upon your strategy. As an example, Ninja requires that you set OnBarClose to true in order to have any chance at success. That alone limits your design tremendously.
Unquote
Based on my experiences, when I had CalculateOnBarClose @false, sim-trade and Market Replay results had looping trades, ie 1 smooth short trade became choppy trades in-and-out within a second. Not able to identify the cause for sure though with CalculateOnBarClose @true there're no looping trades.
Sorry, I don't mean to burst your bubble, but this is just not true.
There are two models that you have to choose between. You can either process data at the end of each bar (which is really the beginning of the next bar depending on the bar type) or on each incoming tick. The former is when CalcOnBarClose=true and the latter is when CalcOnBarClose=false.
With either model, you need to understand what Ninja is actually doing behind the scenes when you are calling the enter/exit/setStop/etc routines. Sadly, the doc almost helps (all of the little warnings that this is advanced coding should be a red flag).
Unfortunately, it is pretty easy to write code that works well in backtests, but fails when you run live. This is usually a problem in the strategy coding, not some limitation in Ninja. If you want to be accurate, you need to use COBC=false, but that means you need to dig in and really understand what is going on.
Thanks aslan. That's good news that CalculateOnBarClose @ false will work IF one knows what's going on! Unfortunately not me as for some unknown reasons seemed it might have triggered looping trades PLUS for weeks now I still have a super-mega big head trying to make a simple strategy with a trail code to work!!