Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stops don't work in backtest

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

    Stops don't work in backtest

    Just a quick question on getting stops to work while back testing. I'm testing an oscillator I wrote and the back test seems to work to all my parameters in the strategy wizard except for the stops.

    Of course I assume stops can be tested in back testing. I have had a quick look around the forum but didn't find what I was after.

    I have had a quick look around the forum but didn't find what I was after. I generated the code using the wizard and I just want a simple 10 point profit target and 10 point stop loss.

    Bet I'm missing something simple lol.

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class TSRSTrategy : Strategy
    {
    #region Variables
    // Wizard generated variables
    private double cheap = -0.5; // Default setting for Cheap
    private double expensive = 0.5; // Default setting for Expensive
    // 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()
    {
    SetProfitTarget("10", CalculationMode.Ticks, 0);
    SetStopLoss("10", CalculationMode.Ticks, 0, true);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(TSR(21), Cheap, 1))
    {
    EnterLong(1, "");
    }

    // Condition set 2
    if (CrossBelow(TSR(21), Expensive, 1))
    {
    EnterShort(1, "");
    }
    }

    #region Properties
    [Description("")]
    [Category("Parameters")]
    public double Cheap
    {
    get { return cheap; }
    set { cheap = Math.Max(-1.000, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public double Expensive
    {
    get { return expensive; }
    set { expensive = Math.Max(0, value); }
    }
    #endregion
    }
    }

    #2
    Treggs, thanks for the post - of course setting stops and targets can be backtested, however you have set both at 0 -

    Code:
     
    SetProfitTarget("10", CalculationMode.Ticks, [COLOR=red][B]0[/B][/COLOR]);
    SetStopLoss("10", CalculationMode.Ticks, [COLOR=red][B]0[/B][/COLOR], true);
    Also your 'from Entry signal' string will prevent those from getting picked up correctly, either set to an empty string ("") or name your entries the same way ("10")
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for that. I knew I was missing something simple. Just got the value in the wrong spot.

      Cheers

      Comment


        #4
        Hello Bertrand

        Hope all good. The TSR which appears in the code is the TSR signal line indicator? I found it only for MT. Would you know if there exists an NT version? I looked at some way of using it and its very interesting as well as effective.

        Regards

        Comment


          #5
          Sorry Michael, I would not know, best would be if you asked Treggs who was working with that one.
          BertrandNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          0 views
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          2 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,262 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X