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

Enter by limit order

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

    Enter by limit order

    On a cross above a specific level I would like to enter a limit order to sell below price.So when price comes back it fills for a short entry.

    The problem I'm having is that in replay the orders are getting filled right away on the crossover. Also I'm unable to add a stop. I'd like for the stop to go above the high of the entry candle.


    if (CrossAbove(xyzLevel))

    {
    EnterShortLimit(DefaultQuantity, xyzLevel, "S1");
    }






    The stops are also hundreds of points away from the market with this..

    if (Position.MarketPosition == MarketPosition.Long)
    {
    SetStopLoss("L1",CalculationMode.Ticks, Low[0] -5*TickSize,false);
    }

    if (Position.MarketPosition == MarketPosition.Short)
    {
    SetStopLoss("S1",CalculationMode.Ticks, High[0] +5*TickSize,false);
    }


    Not sure what is wrong, thanks.
    Last edited by brucelevy; 04-17-2016, 05:52 PM.

    #2
    Hello brucelevy,

    Thanks for your post.

    If you use EnterShortLimit() below price it will fill immediately because a limit order will fill at the specified price or better and in this case as price is above the entry when going short it would be considered better. You can see this on a superdom by left clicking in the sell column at a price below the current price.

    If you want price to come down, hit your limit and be in a short position, then you would need to use EnterShortStopLimit(): https://ninjatrader.com/support/help...tstoplimit.htm

    Regarding the stops and profit targets, you are specifying the mode of CalculationMode.Ticks. This means that whatever value you enter will be converted to ticks. The issue here is that you are entering price and the mode of Ticks will cause the price (Low[0]) to be divided by the tick size of the instrument resulting in as you observed, hundreds of ticks.

    When using CalculationMode.Ticks typically you would be entering a value like 10 or 20, etc to specify the number of ticks away from the entry price.

    As you are using price for the targets you would want to use CalculationMode.Price

    Please set your profit and stop before the entry. The reason to do this is that when using the Set methods, they retain the last used value and as soon as an entry is made those prior set values are used. In your example you are setting them after the entry and likely will have some issues. From the helpguide for SetStopLoss(): Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position Ref: https://ninjatrader.com/support/help...etstoploss.htm

    The same statement will be found in SetProfitTarget as well.

    Example of setting stop before entry:

    if (CrossAbove(xyzLevel))

    {
    SetStopLoss("S1",CalculationMode.Price, High[0] +5*TickSize,false); // set stop level first
    EnterShortLimit(DefaultQuantity, xyzLevel, "S1");
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks that solved it, I see where I made mistakes.

      Are these limit orders to enter and exit back-testable?

      Thanks.

      Comment


        #4
        Hello brucelevy,

        Thanks for your reply, glad that helped.

        Yes, you can backtest with limit orders.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Belfortbucks, Today, 09:29 PM
        0 responses
        6 views
        0 likes
        Last Post Belfortbucks  
        Started by zstheorist, Today, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        151 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        6 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Working...
        X