NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-28-2008, 09:37 PM   #1
paco99
Member
 
Join Date: Jul 2008
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default Need help looking at this Strategy that was converted from TS

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
paco99 is offline  
Reply With Quote
Old 07-28-2008, 10:38 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

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
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-28-2008, 10:54 PM   #3
paco99
Member
 
Join Date: Jul 2008
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

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:
Originally Posted by Josh View Post
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
paco99 is offline  
Reply With Quote
Old 07-28-2008, 11:56 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

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
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-29-2008, 12:09 AM   #5
paco99
Member
 
Join Date: Jul 2008
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

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:
Originally Posted by Josh View Post
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
paco99 is offline  
Reply With Quote
Old 07-29-2008, 12:52 AM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

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.
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 03:45 PM.