• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to print order info in output windows

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

    how to print order info in output windows

    Hi,
    I just need to print the following to output windows after every order in my automated strategy. None of the examples I found are very clear. Can someone please post the code.

    Entry Price :
    Exit Price :
    Gross P&L : Entry Price - Exit Price
    Total P&L :


    Thanks in Advance
    Bill

    #2
    Hello Bill,

    Thanks for your post.

    Code:
    if (Performance.AllTrades.Count > 1)
    Print("Entry Price: "+Performance.AllTrades[Performance.AllTrades.Count-1].Entry.Price+
    "\r\nExit Price: "+Performance.AllTrades[Performance.AllTrades.Count-1].Exit.Price+
    "\r\nGross P&L: "+Performance.AllTrades[Performance.AllTrades.Count-1].ProfitCurrency+
    "\r\nTotal P&L: "+(Performance.AllTrades.TradesPerformance.GrossProfit+Performance.AllTrades.TradesPerformance.GrossLoss));
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea.

      Comment


        #4
        Hi Chelsea,
        How come it show 25 profit in the following. Does it calculate it in $s ???

        Entry Price: 4179.75
        Exit Price: 4181
        Gross P&L: 25
        Total P&L: 10450

        Comment


          #5
          Hi billsingh,

          Yes, that should be the profit in currency.

          Were you looking for points or percent?

          Performance.AllTrades[Performance.AllTrades.Count-1].ProfitPoints

          or

          Performance.AllTrades[Performance.AllTrades.Count-1].ProfitPercent
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks Chelsea, one more question

            I am thinking of using the ATM with this. all the long and short positions has names like long1, long2 and short1 and short2. but if I want to close the all the positions at any given time can I use Exitlong("","") or Exitshort("","") ??? will it work ????

            Comment


              #7
              Hi billsingh,

              If you plan to use an Atm Strategy in your NinjaScript Strategy, you can no longer use EnterLong and ExitLong methods.

              Instead you will have to start using AtmStrategy methods such as AtmStrategyCreate().

              Below is a link to the help guide on AtmStrategy methods in a NinjaScript Strategy.
              http://www.ninjatrader.com/support/h...gy_methods.htm
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                What about if I do the following code, will it work without createing ATMmethods() etc.... and later I want to check on each bar if I should close the position or not.

                protected override void Initialize()
                {
                SetProfitTarget("Entry2", CalculationMode.Ticks, 4);
                SetTrailStop("Entry1", CalculationMode.Ticks, 6, false);


                CalculateOnBarClose = true;
                }

                Comment


                  #9
                  Here is the whole code. I like it to Entry2 only take 4 tick profit and Entry1 to do the training stop. If they are not met or position go backwards before these condition then I exit by exitlong(). will this work ????

                  protected override void Initialize()
                  {
                  SetProfitTarget("Entry2", CalculationMode.Ticks, 4);
                  SetTrailStop("Entry1", CalculationMode.Ticks, 6, false);
                  CalculateOnBarClose = true;
                  }


                  protected override void OnBarUpdate()
                  {

                  if (Position.MarketPosition == MarketPosition.Flat

                  EnterLong(1, "Entry1");
                  EnterLong(1, "Entry2");

                  // Condition set 2
                  if ( Condition)

                  ExitLong("", "");

                  }

                  Comment


                    #10
                    Hi billsingh,

                    That is correct.

                    An exit order with no signal name will exit all orders including entries that used a signal name.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      But for some reason this code is not working.

                      Comment


                        #12
                        It never execute entry2.

                        Comment


                          #13
                          Hi billsingh,

                          I have created an example script to demonstrate that an exit with no signal name will indeed exit entry orders that are using signal names.

                          Let me know if this script does not exit both entry orders on your end.
                          Attached Files
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi billsingh,

                            If the second entry is not being submitted then your Entries per direction is set to 1 in the Strategy Parameters.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by billsingh View Post
                              It never execute entry2.
                              What is your EntriesPerDirection value set at?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by imalil, Today, 09:46 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post imalil
                              by imalil
                               
                              Started by SAITON, Today, 09:03 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post SAITON
                              by SAITON
                               
                              Started by suprsnipes, Today, 08:26 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post suprsnipes  
                              Started by RobertoPaez, Today, 06:47 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post RobertoPaez  
                              Started by catinabag, Today, 06:45 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post catinabag  
                              Working...
                              X