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

NT exiting on stop loss at the same price???

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

    NT exiting on stop loss at the same price???

    I used the strategy wizard to generate the following code:

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Using 2 EMAs, Stochastics and Momentum as Entry
    /// </summary>
    [Description("Using 2 EMAs, Stochastics and Momentum as Entry")]
    public class MyCustomTIStrategy : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int eMAFast = 8; // Default setting for EMAFast
    private int eMASlow = 20; // Default setting for EMASlow
    private int adxPedriod = 14; // Default setting for AdxPedriod
    private int adxValue = 30; // Default setting for AdxValue
    private int momentumPara = 14; // Default setting for MomentumPara
    // 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(EMA(EMASlow));
    Add(EMA(EMAFast));
    Add(ADX(14));
    Add(Momentum(14));
    Add(EMA(EMASlow));
    Add(EMA(EMAFast));
    Add(ADX(14));
    Add(Momentum(14));
    SetProfitTarget("LongTI", CalculationMode.Percent, 0.01);
    SetProfitTarget("ShortTI", CalculationMode.Percent, 0.01);
    SetStopLoss("LongTI", CalculationMode.Price, 10, false);
    SetStopLoss("ShortTI", CalculationMode.Price, 10, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(EMA(EMASlow), EMA(EMAFast), 1)
    && ADX(14)[0] > ADX(14)[1]
    && ADX(14)[0] > 20
    && Momentum(14)[0] > Momentum(14)[1])
    {
    EnterLong(100, "LongTI");
    DrawDiamond("My diamond" + CurrentBar, false, 0, 1, Color.LimeGreen);
    }

    // Condition set 2
    if (CrossBelow(EMA(EMASlow), EMA(EMAFast), 1)
    && ADX(14)[0] < ADX(14)[1]
    && ADX(14)[0] > 20
    && Momentum(14)[0] < Momentum(14)[1])
    {
    EnterShort(100, "ShortTI");
    DrawDiamond("My diamond" + CurrentBar, false, 0, 1, Color.Red);
    }
    }



    When I backtested this strategy, it kept exiting right at the same price on the same bar on stoploss order. Can you guys help me?
    Last edited by Avn_0903; 04-06-2010, 09:02 AM.

    #2
    Hello Avn_0903,

    You have your stop loss set in mode price at value 10. This means it will submit a stop loss order at $10, regardless of where it's currently trading.
    If the instrument you're trading is higher than $10, this is what is most likely happening:

    Stop Loss orders are submitted upon execution.
    The stop loss will be less than the current traded price. This results in an invalid order. Strategy is then canceled.

    Alternatively you could try calculation mode ticks, percent, or currency. Let us know what you're looking for in your stop loss.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      If I want to put a stop loss order 1$ away from my entry price then what mode do I choose? Tick or percent?

      Comment


        #4
        If you're trading stocks, they have a TickSize of .01

        $1 = 100 Ticks so you could use CalculationMode.Ticks and a value of 100.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by agclub, 04-21-2024, 08:57 PM
        5 responses
        32 views
        0 likes
        Last Post agclub
        by agclub
         
        Started by ESHunter, Today, 08:06 PM
        2 responses
        15 views
        0 likes
        Last Post ESHunter  
        Started by ETFVoyageur, 05-07-2024, 07:05 PM
        19 responses
        150 views
        0 likes
        Last Post ETFVoyageur  
        Started by ETFVoyageur, Yesterday, 10:13 PM
        3 responses
        26 views
        0 likes
        Last Post ETFVoyageur  
        Started by ETFVoyageur, Yesterday, 12:52 AM
        3 responses
        33 views
        0 likes
        Last Post ETFVoyageur  
        Working...
        X