Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variation om SampleMAsCrossOver

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

    Variation om SampleMAsCrossOver

    Hi,

    I am trying to develop (using the strategy wizard) a variation on the SampleMAsCrossOver so that the Long trade will only be entered if and when the high of the crossover bar is touched (and, in the case of a Short, if and when the low of the crossover bar is touched).

    Below is the code that I expected to work, but it doesn't. I also tried a number of other variations of trade types but non operated correctly.


    Thanks

    #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 MFMAsCrossOver2 : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int mASlow = 4; // Default setting for MASlow
    private int mAFast = 2; // Default setting for MAFast
    private double sL = 0.001; // Default setting for SL
    private double sLMove = 0.001; // Default setting for SLMove
    // 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(SMA(MAFast));
    Add(SMA(MASlow));
    Add(SMA(MAFast));
    Add(SMA(MASlow));

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(SMA(MAFast), SMA(MASlow), 1))
    {
    EnterLongStop(DefaultQuantity, High[0], "Enter Long");
    }

    // Condition set 2
    if (CrossBelow(SMA(MAFast), SMA(MASlow), 1))
    {
    EnterShortLimit(DefaultQuantity, Low[0], "Enter Short");
    }

    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MASlow
    {
    get { return mASlow; }
    set { mASlow = Math.Max(2, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int MAFast
    {
    get { return mAFast; }
    set { mAFast = Math.Max(2, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public double SL
    {
    get { return sL; }
    set { sL = Math.Max(0.000, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public double SLMove
    {
    get { return sLMove; }
    set { sLMove = Math.Max(0.000, value); }
    }
    #endregion
    }
    }

    #2
    Hello,

    Do these orders work if you change them to Market Orders using Enter() long?

    It's most likely that the Stop orders are submitting, but do not fill. The default behavior is the cancel an order once the condition is no longer true, however it is possible to change this behavior through your code.

    Please see our Reference Sample on Keeping Orders Alive for more information:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks Matthew,

      yes, this looks fine with market orders. When I said "it doesn't work" I meant that the strategy performance (back testing) does not show the entries and exits that I expect. I am yet to test it with a price feed or replay.

      But I think that you are confirming that I am using the correct stop and limit order, is that so?

      Thanks

      Comment


        #4
        Hello,

        The order methods you are using are correct, however I do not know where you expect the entries to be. A Sell Limit order at the low of the current bar would be difficult to fill.

        You will want to use plenty of Print() statements to verify values are what you expect.


        Add TraceOrders = true to your Initialize method and you can then view output related to strategy submitted orders through Tools > Output window.


        It may also help to add drawing objects to your chart for signal confirmation. Additional help for these items is available at the following links:

        Debugging your NinjaScript code.
        TraceOrders
        Drawing Objects.
        MatthewNinjaTrader Product Management

        Comment


          #5
          thanks Matthew, I'll have a go at what you've suggested.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by fitspressoburnfat, Today, 04:25 AM
          0 responses
          2 views
          0 likes
          Last Post fitspressoburnfat  
          Started by Skifree, Today, 03:41 AM
          1 response
          4 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Started by usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          604 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          23 views
          0 likes
          Last Post xiinteractive  
          Working...
          X