Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sell at opening with profit

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

    Sell at opening with profit

    I am pretty newbie, trying to develope my first script, and find problems trying to write:
    " exit long at the firsts open price with profit"
    Any clue?
    Thanks a lot!

    #2
    You can do this by running a check against the PnL of your current position. If it is positive then you can do a ExitLong() or ExitLongLimit().

    To check your unrealized PnL you can use this: GetProfitLoss()
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Josh View Post
      You can do this by running a check against the PnL of your current position. If it is positive then you can do a ExitLong() or ExitLongLimit().

      To check your unrealized PnL you can use this: GetProfitLoss()
      Thank you very much for your help.
      I did this:
      Code:
      // Condition set 2
      if (Position.GetProfitLoss(Open[0], PerformanceUnit.Percent) > 0);
      {
      ExitLong("", "");
      }
      But I am afraid all long positions are exited at the Open, no matter if I get a profit or loss exit...

      Thanks!

      Comment


        #4
        I would use Close[0] instead of Open[0]. This is the case because when the new bar starts, the Close[0] price would reflect the latest change in price. Especially when running with CalculateOnBarClose = false.

        You may need to debug your code a little. Try some prints to see what value you are getting out of GetProfitLoss. This will help you better determine the behavior you are experiencing.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by Josh View Post
          I would use Close[0] instead of Open[0]. This is the case because when the new bar starts, the Close[0] price would reflect the latest change in price. Especially when running with CalculateOnBarClose = false.

          You may need to debug your code a little. Try some prints to see what value you are getting out of GetProfitLoss. This will help you better determine the behavior you are experiencing.
          Thank you very much for your help.
          I started again from zero, and tried to understand how the systrem works, and followed your suggestion of printing the outputs.
          I am using 1 day bars, and try this simple order:
          If today's open value is above yesterday close, then buy.
          I wrote:
          Code:
          if (Open[0] > Close[1])
                      {
            EnterLong(DefaultQuantity, "");
          }
          As you can imagine, it didn't work: the check is ok, but the EnterLong order is excecuted not today after checking the opening but tomorrow.
          Aha! it must be the CalculateOnBarClose, I thought...
          Ok, then I set: CalculateOnBarClose = false
          But the behavior is exactly the same.
          At this point I exactly don't understand the following:
          1. Is there any way to simulate within the bar, instead of "in following bar"?
          2. What exactly "CalculateOnBarClose" means?
          I read the Ninjatrader Help Guide but couldn't get it clear: probably there are some language missunderstandings from my part, sorry.
          Thank you very much for your patience.

          jm

          PS: by the way, I could't find the way to print the bar date (or time) in the output, in order to easilly check the calculations...
          Last edited by eswap0; 06-04-2008, 10:30 AM.

          Comment


            #6
            Josh will follow up on this later today.
            RayNinjaTrader Customer Service

            Comment


              #7
              Hi eswap0,

              The first thing you would need to do is debug your code as per these tips: http://www.ninjatrader-support.com/v...ead.php?t=3418
              http://www.ninjatrader-support.com/v...ead.php?t=3627

              I also suspect you may be running into this issue: http://www.ninjatrader-support.com/v...ead.php?t=3170

              Please check the error log in the Control Center for anything fishy.

              In regards to CalculateOnBarClose, historical data will always be assessed as if CalculateOnBarClose = true. This is the nature of backtesting because you cannot look into the future thus you cannot place trades on the same bar since you already know the closing price of that bar. You can only place a trade on the next bar. In realtime it is a different story.

              Please read this article from the Help Guide: http://www.ninjatrader-support.com/H...sBacktest.html

              To print time you can use Time[0].
              Code:
              Print(Time[0] + " Enter Long Here");
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Thank you very much for your help!
                Now everything is clear.
                I assume then that I will never be able to backtest a rule like "buy if today's open is higher than yesterday's close), as the order should be executed in the same day's bar.
                Thanks so much!
                ----------------------------------------
                Edited: I think this is what I need:
                http://www.ninjatrader-support.com/v...ead.php?t=6652
                Last edited by eswap0; 06-05-2008, 12:40 PM.

                Comment


                  #9
                  Yes, the example you found will "alleviate" what you need to some degree. It will still not be perfect since you are not going down to the tick level.

                  This is generally why people will go into forward testing their strategy with Market Replays or just simulating on live data after they do some preliminary backtests. These forward tests provide more conclusive results that are more accurate than backtests, but take more time to conduct.
                  Josh P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by vantojo, Today, 01:39 PM
                  0 responses
                  15 views
                  0 likes
                  Last Post vantojo
                  by vantojo
                   
                  Started by Rubens_2020, Today, 01:48 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Kate  
                  Started by kempotrader, Today, 01:34 PM
                  1 response
                  23 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by bc24fl, Today, 01:50 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by bosajin, 01-21-2021, 09:15 AM
                  7 responses
                  59 views
                  0 likes
                  Last Post NinjaTrader_PaulH  
                  Working...
                  X