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.
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!
The following user says Thank You to Trader.Jon for this post:
Sorry to throw in another idea here which is opposite to yours. I learned the following from a more experienced member:
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.
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.
The following 3 users say Thank You to aslan for this post:
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!!