• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help to code a simple strategy

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

    Help to code a simple strategy

    Can somebody help me and write a simple code to backtest the TSSupertrend indicator?

    http://ninjatrader.com/support/forum...&postcount=272

    Long = If close above TSSupertrend (5,1,10), buy at next day open.
    Exit Long = If low below TSSupertrend (5,1,10).

    (The opposite for short)

    I know this "strategy" is not profitable. I need just a Entry/Exit Tool if my fundamental condition match.

    Is there anything to note by backtesting Futures? How to set the merge policy?

    Thank you very much!

    #2
    Hello 7Maxx,

    This indicator has multiple plots.
    You will need to specify the plot you want to compare.

    If the name is TSSuperTrend using a set of brackets and a barsAgo value an index would access the most recent bar of that plot.
    TSSuperTrend(/*parameters*/)./*plot name here*/[0]

    Close is a variable that holds a data series of closes for each bar. This is also accessed with a set of brackets and a barsAgo index.
    Close[0]

    In c# you will need a if statement and in the parenthesis compare the indicator's plot value with the close value.
    Taking a peak at this indicator I see there is an UpTrend plot.
    if (Close[0] > TSSuperTrend(/*parameters here*/).UpTrend[0])

    if statements - http://ninjatrader.com/support/helpG...g_commands.htm
    Close - http://ninjatrader.com/support/helpGuides/nt7/close.htm
    Low - http://ninjatrader.com/support/helpGuides/nt7/low.htm

    If the primary data series is less than 1 day in interval, you can use Bars.FirstBarOfSession to know that a bar is the first bar of a session.
    http://ninjatrader.com/support/helpG...rofsession.htm

    To place an entry order such as a buy market order use the EnterLong() method call.
    http://ninjatrader.com/support/helpG.../enterlong.htm

    For an exit at a specific price, you can use a Stop or Stop Limit behind the order and a Limit ahead of the order.
    ExitLongStop - http://ninjatrader.com/support/helpG...itlongstop.htm
    ExitShortStop - http://ninjatrader.com/support/helpG...tshortstop.htm
    ExitLongStopLimit - http://ninjatrader.com/support/helpG...gstoplimit.htm
    ExitShortStopLimit - http://ninjatrader.com/support/helpG...tstoplimit.htm
    ExitLongLimit - http://ninjatrader.com/support/helpG...tlonglimit.htm
    ExitShortLimit - http://ninjatrader.com/support/helpG...shortlimit.htm


    Please also see the post below about getting started learning NinjaScript.
    http://ninjatrader.com/support/forum...ad.php?t=95842

    This thread will remain open for any community members that would like to build your script as a convenience to you.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB

      Thank you for the answer!

      I've tried to write the script with the strategy wizard, but I got a lot of error massages.

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      /// <summary>
      /// Backtest TSSupertrend
      /// </summary>
      [Description("Backtest TSSupertrend ")]
      public class TestSuperTrend : Strategy
      {
      #region Variables
      // Wizard generated variables
      private bool superTrend = true; // Default setting for SuperTrend
      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the strategy and is called once before any strategy method is called.
      /// </summary>
      protected override void Initialize()
      {
      Add(TSSuperTrend(5, TSSuperTrend.Utility.MovingAverageType.HMA, 1, 10, TSSuperTrend.Utility.SuperTrendMode.ATR));

      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (CrossAbove(Close, TSSuperTrend(5, TSSuperTrend.Utility.MovingAverageType.HMA, 1, 10, TSSuperTrend.Utility.SuperTrendMode.ATR).UpTrend, 1))
      {
      EnterLong(DefaultQuantity, "");
      }

      // Condition set 2
      if (CrossBelow(Close, TSSuperTrend(5, TSSuperTrend.Utility.MovingAverageType.HMA, 1, 10, TSSuperTrend.Utility.SuperTrendMode.ATR).DownTrend , 1))
      {
      EnterShort(DefaultQuantity, "");
      }
      }

      #region Properties
      [Description("")]
      [GridCategory("Parameters")]
      public bool SuperTrend
      {
      get { return superTrend; }
      set { superTrend = value; }
      }
      #endregion
      }
      }


      I don't need a stop loss or profit target, just buy and sell on the Supertrend indicator.

      Comment


        #4
        Hello 7Maxx,

        What is the error message you are receiving?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          erorr code : CS 0119

          Screenshot is in the attachment
          Attached Files

          Comment


            #6
            Hello 7Maxx,

            What is the full error message you are reading in the error column?
            (You will need to expand the error column)

            The error message is going to let you know what the issue is.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by dshalom9, Today, 08:36 AM
            9 responses
            8 views
            0 likes
            Last Post NinjaTrader_PatrickG  
            Started by stock_wizard_49, 07-11-2020, 06:57 PM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by asmmbillah, Yesterday, 03:03 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by AspenHiker, Today, 08:37 AM
            0 responses
            6 views
            0 likes
            Last Post AspenHiker  
            Started by StarTrader, 07-11-2020, 11:27 AM
            2 responses
            19 views
            0 likes
            Last Post StarTrader  
            Working...
            X