![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Member
Join Date: Jul 2008
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
I converted a strategy from TS to NT. The 7 year back test in TS
was very good - it averaged around a 1.40 profit factor. After converted it to NT, I can't get it to break even using the exact same data. NinjaTrader is showing a .25 profit factor. I'm obviously missing something. Can someone please help me? Here is the TradeStation code: Inputs: avgLength(40), atrLength(40); Vars: upBand(0), dnBand(0), liquidPoint(0), movAvgVal(0), movAvgVal2(0); movAvgVal = average(((High + Low + Close)/3),40); movAvgVal2 = average(((High + Low + Close)/3),40); upBand = movAvgVal + AvgTrueRange(atrLength); dnBand = movAvgVal - AvgTrueRAnge(atrLength); if (movAvgVal > movAvgVal[1]) then Buy ("KKBuy") next bar at upBand stop; if (movAvgVal < movAvgVal[1]) then Sell Short ("KKSel") next bar at dnBand stop; liquidPoint = movAvgVal2; If(MarketPosition = 1) then Sell next bar at liquidPoint stop; If(MarketPosition = -1) then Buy To Cover next bar at liquidPoint stop; Here is the NinjaTrader code: protected override void OnBarUpdate() { if (SMA(40)[0] > SMA(40)[1]) EnterLongLimit(DefaultQuantity, (SMA(40)[0] + ATR(40)[0]), ""); if (Close[0] > SMA(40)[0]) ExitLong(); if (SMA(40)[0] < SMA(40)[1]) EnterShortLimit(DefaultQuantity, (SMA(40)[0] - ATR(40)[0]), ""); if (Close[0] < SMA(40)[0]) ExitShort(); }
Last edited by paco99; 07-28-2008 at 09:45 PM.
Reason: made mistake
|
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Well first of all you would need to run your backtest on the Typical price not Close price.
In your code you also have no translation for the liquidpoint stuff. Your exit orders are completely different then the TS ones. Sorry we are not TS experts here, but hopefully that can get you going. You may also want to try contacting a NinjaScript Consultant here: http://www.ninjatrader.com/webnew/pa...injaScript.htm
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Member
Join Date: Jul 2008
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
Josh,
The exit with the TradeStation code is to exit when the price reaches the moving average. LiquidPoint is just a variable for the moving average. My code should match that though. Can you please confirm? Also, I'm new to NT and I'm still evaluating if I want to switch. Can you confirm that the trades in a backtest wont match the real trades like they would have happened in a live account? I'm hoping this is the case. Thanks! Quote:
|
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
No your current exit order does not behave the way your TS code behaves.
This is your exit condition: If(MarketPosition = 1) then Sell next bar at liquidPoint stop; liquidPoint is the value you are selling at and your MarketPosition is your condition to exit. You are essentially exiting right after you enter. In NT you would program it like this instead: if (Position.MarketPosition == MarketPosition.Short) or whichever one applies to "1" in TS. Please also review this article for realtime vs backtesting: http://www.ninjatrader-support.com/H...sBacktest.html
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Member
Join Date: Jul 2008
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
Josh,
Thanks again for your help and sticking with me on this. I made the modifications you described below to look at Position.MarketPosition, and it didn't change the results any. I closed NT, tried it again, and the results were identical. I read the link you sent me. I understand the results will vary. But, this strategy should be a 1.4, and instead I'm getting a 0.14 in NT. I also changed it to Typical[0] as you suggested. Any other ideas? Here is my updated code: protected override void OnBarUpdate() { if (SMA(40)[0] > SMA(40)[1]) EnterLongLimit(DefaultQuantity, (SMA(40)[0] + ATR(40)[0]), ""); if ((Position.MarketPosition == MarketPosition.Long) && (Typical[0] > SMA(20)[0])) ExitLong(); if (SMA(40)[0] < SMA(40)[1]) EnterShortLimit(DefaultQuantity, (SMA(40)[0] - ATR(40)[0]), ""); if ((Position.MarketPosition == MarketPosition.Short) && (Typical[0] < SMA(40)[0])) ExitShort(); } Quote:
|
|
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
By Typical I meant in the SMA().
SMA(Typical, 40)[0] Also I don't think this is part of your exit condition: && (Typical[0] < SMA(40)[0])) Your exit condition is solely the MarketPosition. Then it uses a limit or a stop order to exit instead of a market order. You exit at the liquidpoint value which is the value of an MA somewhere.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|