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

EnterLongLimit only if price hit or above X.

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

    EnterLongLimit only if price hit or above X.

    I am developing a strategy, where it will enter long limit, when the price hit above X. However, if price at that moment is below X, EnterLongLimit will just take the X price (expensive price), which is not what I intended.


    This is my code snippet:

    Code:
    protected override void OnBarUpdate()
    {
    	EnterLongLimit(54.2, "");
    	SetProfitTarget(CalculationMode.Price, 54.36);
    }
    I am testing on CL 04-15 from 1st January 2015 till 20th January 2015, and this is the bar chart I got, see attachment. I don't want it to enter position, if the price is below X.

    So, m question is, how to let the strategy to enter market, only when the price is higher than or equal to X? I tried if Close[0] >= X, but in backtest, the Close[0] is referring to the close of bar, instead of the price at that moment.

    Thanks, and sorry if my question is not clear enough. I will provide more info and explanation if needed.
    Attached Files

    #2
    Hello vhanded,

    Limit orders fill at the specified price or better.

    If you place a buy limit order way above the market it fills immediately. This is true even of manual orders that you place (try placing a buy limit order way above market on the SuperDOM).

    If you want to ensure that the order is not placed unless the price is below a certain amount, make this a condtion.

    If (Close[0] < 50.1)
    {
    EnterLongLimit(54.2, "");
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I just found out about EnterLongStop and EnterShortStop. Why can't we use these?

      Comment


        #4
        Hello vhanded,
        Yes you could absolutely use EnterLongStop or EnterShortStop if you are wanting to place a predefined market order before the price reaches that point.

        An example of how you could use this is below:
        if (Close[0] > 50.1)
        {
        EnterLongStop(54.2 "')
        }
        In addition you could use EnterLongStopLimit() or EnterShortStopLimit as an order method.
        I have provided a link on EnterLongStopLimit() here, http://www.ninjatrader.com/support/h...gstoplimit.htm
        In addition here is alink on EnterShortStopLimit() http://www.ninjatrader.com/support/h...tstoplimit.htm
        Cody B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by giulyko00, Yesterday, 11:49 AM
        3 responses
        20 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by ttrader23, Yesterday, 09:04 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by ETFVoyageur, 05-07-2024, 07:05 PM
        6 responses
        50 views
        0 likes
        Last Post ETFVoyageur  
        Started by Klaus Hengher, Yesterday, 03:13 AM
        2 responses
        15 views
        0 likes
        Last Post Klaus Hengher  
        Started by Sebastian - TwinPeaks, Yesterday, 01:31 PM
        2 responses
        13 views
        0 likes
        Last Post Sebastian - TwinPeaks  
        Working...
        X