Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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



    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 traderqz, Yesterday, 04:32 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by f.saeidi, Today, 05:56 AM
    1 response
    4 views
    0 likes
    Last Post Jltarrau  
    Started by Jltarrau, Today, 05:57 AM
    0 responses
    4 views
    0 likes
    Last Post Jltarrau  
    Started by Stanfillirenfro, Yesterday, 09:19 AM
    7 responses
    51 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by TraderCro, 04-12-2024, 11:36 AM
    4 responses
    71 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X