Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLongLimit method - beginner

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

    EnterLongLimit method - beginner

    Hi everybody,
    i would like to ask you something...
    i have strategy where i want to buy when the price is higher than 100 for example. But I want to sell what i bought when the price fall down under 50.
    So 50 is my stoploss. But when the price is 100 (and i bought) and now is the price still growing up i want to move my stoploss to 80. So my question is:

    What kind of method can set the limit when my strategy has to buy?
    I found something like EnterLongLimit(100) and when is the bar (in chart) growing up the strategy will buy. But I don't know if the strategy bought something and I have to set stoploss.
    I just set EnterLongLimit(100) but it will not tell me when is the strategy buying something.. it just buy but i can't adequate answer for this action because i don't know it happend.

    #2
    Hi zooinek, thanks for your post, you have several options here - either you could use a trailing stop for your open position - http://www.ninjatrader-support.com/H...TrailStop.html

    Or you change your stoploss value to your desired value when you are in the long position, this reference sample will help you with sample code - http://www.ninjatrader-support2.com/...ead.php?t=3222

    Comment


      #3
      Uživatel PROGRAMMER z fóra FINANCNIK.CZ
      Kontakt na mě: [email protected]

      Je možné se dohodnout na programování strategií pro zájemce.

      Comment


        #4
        it doesn't work corrently... when I use EnterLong() (or EnterLongLimit(High[0])) and then SetTrialStop(Low[0]-1) it will halt the NinjaTrader and i have to restart NinjaTrader..
        I need any method which can set sometehing like "if the price will greater than 100 then buy".
        I am using "if (High[0]>100) {EnterLong();}" but the EnterLong will buy on the open price on next bar and that is not correnct. When is any bar growing up and the price is greater then 100 i have to buy right now and not to wait to close the bar and then buy.

        Also i need any method which can set somethig like "if i have bought something and the price is lower then 50 then sell".
        It will be somethig like "if (Position.MarketPosition == MarketPosition.Long) {SetSellLine(50)}" ....the SellLineMethod is my name, it doesn't exist but i illustrate what i am looking for. Any Method wich can set "if the price is falling down and fall down under 50 then sell and don't wait for closing current bar"

        Does it exist methods like this? What is their name? How to use them?

        Comment


          #5
          zooinek,

          All orders are placed processed at the open of the next bar if you are using CalculateOnBarClose = true. Turn this to false and you will execute as soon as the condition is true. Bear in mind that in a backtest you will always be running with CalculateOnBarClose = true.

          If you want to exit use ExitLong(). You already have the Positon.MarketPosition correct. Call ExitLong() when your price drops to a certain place.

          if (Close[0] < 50) or something like that.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            so i can use
            if (Close[0]<50) ExitLong();
            but I want to sell in the moment, when the price will touch the 50$ line and not to wait to closing bar and get the close price. The bar might be from 60$ to 30$ and with this way "if (Close[0]<50) ExitLong();" i would sell for 30$ and that is not correct. I want to sell for 50$

            Comment


              #7
              This will work intrabar if you set CalculateOnBarClose to false.

              Comment


                #8
                I tried that and it doesnt work.


                protected override void Initialize()
                {
                CalculateOnBarClose = false;
                ExitOnClose = false;
                }
                protected override void OnBarUpdate()
                {
                if (Close[0]>100)
                {
                EnterLong();
                }
                }


                there is bar, from 90 to 110 (that is Bar B1) and next bar is from 115 to 117 (B2).
                It should buy in bar B1 for price 100. But the reality is that the strategy will buy on B2 for open price, so 115.
                And I have set CalculateOnBarClose=false;
                What is wrong with that?
                Last edited by zooinek; 04-01-2009, 02:52 PM.

                Comment


                  #9
                  zooinek,

                  What bars are you looking at? You can't look at any historical bar and expect it to trade intrabar. Historical bars are always processed at the end of each bar. The setting Bertrand mentioned will help you in real-time and will trade intrabar in real-time.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    I was looking at historical bar. Because I have for example strategy where I want to buy if the price is greater or equal to 100$ and i dont wont to wait for closing the bar (because the closing price can be 5min later and much expensive you know) and I want to backtest this strategy.

                    So, the question is:
                    What technique can ensure that i will buy exactly in the time and price when the price is 100$ and it will be work in historical data..? Is that even possible?

                    Comment


                      #11
                      Not possible historically. On historical bars you always have OHLC. With the close value of that bar there are no more tradeable locations on that bar. All trades are placed at the open of the next bar.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        and what about this:




                        private double currentPrice=0;
                        Initialize() {
                        Add(PeriodType.Tick, 1);
                        }

                        OnBarUpdate() {
                        if (BarsInProgress==1)
                        {
                        currentPrice = Close[0];
                        }
                        }

                        ?? Could this idea work?
                        There has to be any way how to work intrabar in also in historical data

                        Comment


                          #13
                          Correct, to simluate intrabar fills on historical data you would need to place your orders on a finer datastream for execution, this reference sample will demonstrate the concept with sample code - http://www.ninjatrader-support2.com/...ead.php?t=6652

                          Comment


                            #14
                            Hi again
                            So I found new problem with this intrabar ordering in historical data...
                            When I want to simulate BUY LIMIT...
                            Imagine situation where I want to buy only for 100$ or less..
                            I just use:
                            Initialize() {
                            Add(PeriodType.Tick, 1);
                            }
                            OnBarUpdate() {
                            if (BarsInProgress==1) {
                            if (Close[0]<=100) {
                            EnterLong();
                            }
                            }
                            }

                            But it is not working correctly because when the price of the tick is 99$ my code will EnterLong() what means "buy on the next tick"........ but the next tick is 105$. So the strategy will buy for 105$. And 105 is too much. I want 100 or less.
                            So the question is:
                            How to simulate buy Limit on historical data?

                            Comment


                              #15
                              Hi, right now you just use a market order so this is expected. To specify your limit price, use the EnterLongLimit() method instead - http://www.ninjatrader-support.com/H...LongLimit.html

                              For backtesting you will also need to select the appropriate fill algorithm - please check this link under 'Historical Fill Processing' - http://www.ninjatrader-support.com/H...AStrategy.html

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              558 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              324 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              545 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              547 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X