Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Need help looking at this Strategy that was converted from TS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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, 09:45 PM. Reason: made mistake

    #2
    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 P.NinjaTrader Customer Service

    Comment


      #3
      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!

      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

      Comment


        #4
        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 P.NinjaTrader Customer Service

        Comment


          #5
          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();

          }

          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

          Comment


            #6
            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 P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sidlercom80, 10-28-2023, 08:49 AM
            170 responses
            2,271 views
            0 likes
            Last Post sidlercom80  
            Started by Irukandji, Yesterday, 02:53 AM
            2 responses
            17 views
            0 likes
            Last Post Irukandji  
            Started by adeelshahzad, Today, 03:54 AM
            0 responses
            3 views
            0 likes
            Last Post adeelshahzad  
            Started by CortexZenUSA, Today, 12:53 AM
            0 responses
            3 views
            0 likes
            Last Post CortexZenUSA  
            Started by CortexZenUSA, Today, 12:46 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Working...
            X