Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Not working: SetTrailStop CalculationMode.Percent

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

    Not working: SetTrailStop CalculationMode.Percent

    Percent trailing stops are not working when I am backtesting. Tick trailing stops are working. You can search for SetTrailStop and see the commented and uncommented occurances. They are not working. Pls let me know what to do next.
    Thx
    =====================
    #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 pbMultiPivot : Strategy
    {
    #region Variables
    // Wizard generated variables
    private string i1 = @"SPY"; // Default setting for I1
    private string i2 = @"QQQ"; // Default setting for I2
    private string i3 = @"FXE"; // Default setting for I3
    private string i4 = @"UUP"; // Default setting for I4
    private string i5 = @"VXX"; // Default setting for I5
    // 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 an MSFT 1 minute Bars object to the strategy
    Add(i1, PeriodType.Day, 1);
    //SetTrailStop(CalculationMode.Ticks, 20);
    // SetTrailStop("From_init", CalculationMode.Percent, 5, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
    // We only want to process events on our primary Bars object (main instrument) (index = 0) which
    // is set when adding the strategy to a chart
    if (BarsInProgress != 0)
    return;
    // Condition set 1
    if (Close[0] <= Pivots(PivotRange.Weekly, HLCCalculationMode.DailyBars, 0, 0, 0, 20).S2[0])
    {
    // SetTrailStop("From_init", CalculationMode.Percent, 5, false);
    //SetTrailStop(CalculationMode.Ticks, 100);
    SetTrailStop(CalculationMode.Percent, 3);
    EnterLong(DefaultQuantity, "In_S3");

    }

    // Condition set 2
    if (Close[0] >= Pivots(PivotRange.Weekly, HLCCalculationMode.DailyBars, 0, 0, 0, 20).R2[0])
    {
    SetTrailStop("Out_R3", CalculationMode.Percent, 2, false);
    //ExitLong("Out_R3", "");
    }

    // Condition set 3
    if (BarsArray[1].GetClose(0) >= Pivots(BarsArray[1], PivotRange.Weekly, HLCCalculationMode.DailyBars, 0, 0, 0, 20).R2[0])
    {
    SetTrailStop("Out_SPY_R3", CalculationMode.Percent, 2, false);
    //ExitLong("Out_SPY_R3", "In_S3");
    }
    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public string I1
    {
    get { return i1; }
    set { i1 = value; }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public string I2
    {
    get { return i2; }
    set { i2 = value; }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public string I3
    {
    get { return i3; }
    set { i3 = value; }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public string I4
    {
    get { return i4; }
    set { i4 = value; }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public string I5
    {
    get { return i5; }
    set { i5 = value; }
    }
    #endregion
    }
    }

    #2
    pivtrd, you likely see this as the percentage double figure in incorrectly entered in your code, try for example 0.05 for a 5% trailstop.

    Thanks,
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    55 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    35 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    7 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    19 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    7 views
    0 likes
    Last Post cre8able  
    Working...
    X