• 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

Reversing position

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

    Reversing position

    Hello.
    This strategy generates right orders when I am flat,
    but if I have an open position and I get opposite signal it is ignored.
    So is it possible to reverse open position?
    I am a complete newbie.
    thank you.



    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 EMA10 : Strategy
    {
    #region Variables
    // Wizard generated variables
    // 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("", CalculationMode.Ticks, 50);
    SetTrailStop("", CalculationMode.Ticks, 50, false);

    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if(FirstTickOfBar)
    {
    // Condition set 1
    if (Close[1] <= Open[1]
    && High[1] > EMA(50)[1]
    && Low[1] < EMA(50)[1])
    {
    EnterLongStop(DefaultQuantity, Close[1] + 10 * TickSize, "");
    }

    // Condition set 2
    if (Close[1] >= Open[1]
    && High[1] > EMA(50)[1]
    && Low[1] < EMA(50)[1])
    {
    EnterShortStop(DefaultQuantity, Close[1] + -10 * TickSize, "");
    }
    }
    }

    #region Properties
    #endregion
    }
    }

    #2
    Hello teenoppa, and thank you for your question.

    While you can use methods at the price, such as EnterLong and EnterShort to reverse, what you are attempting to do violates the IOH (Internal Order Handling) Rules.

    Originally posted by http://ninjatrader.com/support/helpGuides/nt7/managed_approach.htm
    Methods that generate orders to enter a position will be ignored if:
    • A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
    • A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
    • The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
    • The entry signal name is not unique
    If you would like to enter a "reversal" away from the price, you will need to use the unmanaged approach, documented here

    http://ninjatrader.com/support/helpG...d_approach.htm

    and implement an OnOrderUpdate handler which cancels existing short orders. You can use the OrderAction to tell them apart.

    Given all of this, I would recommend entering the market with regular Market orders using EnterLong and EnterShort, especially if you are a beginning programmer.

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by digibob, Today, 10:01 PM
    0 responses
    1 view
    0 likes
    Last Post digibob
    by digibob
     
    Started by ptertich, Today, 09:59 PM
    0 responses
    1 view
    0 likes
    Last Post ptertich  
    Started by sledge, Today, 06:11 PM
    1 response
    9 views
    0 likes
    Last Post sledge
    by sledge
     
    Started by Bionian, Today, 02:46 PM
    2 responses
    9 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by rwilliam, Today, 01:54 PM
    1 response
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X