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

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 Aviram Y, Today, 05:29 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Aviram Y  
                              Started by quantismo, 04-17-2024, 05:13 PM
                              3 responses
                              27 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              7 responses
                              34 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cls71, Today, 04:45 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post cls71
                              by cls71
                               
                              Started by mjairg, 07-20-2023, 11:57 PM
                              3 responses
                              218 views
                              1 like
                              Last Post PaulMohn  
                              Working...
                              X