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

Commission per round trip trade per currently selected instrument on the chart.

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

    Commission per round trip trade per currently selected instrument on the chart.

    How to call it?

    I can use Instrument.MasterInstrument.PointValue for price,
    but I need to dynamically call the commission price for the current instrument for stats.

    I've been through the forum and tried lots of different codes and no joy so far.

    Thank you.

    #2
    First off, commissions are not an Instrument thing.

    Commissions are associated with an Account.

    You need to use AccountItem.Commission.

    For Indicator, look here.
    For Strategy, look here.

    The idea is you subscribe using your own callback,
    and when your callback is called with AccountItem
    set to AccountItem.Commission, you save the
    associated value somewhere in your own variable
    for your future use.

    Make sense?

    Comment


      #3
      bltdavid,

      thank you for your reply.

      I followed the link you provided and did this:

      Print("Commission = $" + AccountItem.Commission);
      and got the result:
      Commission = $Commission

      If it was an NQ chart, I was after $2.09 as the result.

      The goal being that I can print profit - (stops + (total number of setups * (2.09 * 2)))

      If you get what I mean.

      Comment


        #4
        Originally posted by davydhnz View Post
        I followed the link you provided and did this:

        Print("Commission = $" + AccountItem.Commission);
        and got the result:
        Commission = $Commission
        Yep, for that code, that would be the expected outcome.

        Originally posted by davydhnz View Post
        If it was an NQ chart, I was after $2.09 as the result.

        The goal being that I can print profit - (stops + (total number of setups * (2.09 * 2)))​
        Then your above code is wrong.

        Those links I provided clearly show enough code
        examples on how to get the value you are looking
        for.

        It pains me to suggest that you have failed to
        comprehend the C# code in those examples.

        -=o=-

        AccountItem is an enumerated type.
        AccountItem.Commission is a value of that type.

        Your code is horribly wrong if you think the value of
        the commission is AccountItem.Commission itself.

        How well do you know C#?

        -=o=-

        I know it's a bit hairy, but I ask this in a very serious
        way: what part of my previous reply,

        "The idea is you subscribe using your own callback,
        and when your callback is called with AccountItem
        set to AccountItem.Commission, you save the
        associated value somewhere in your own variable
        for your future use.​"

        Did not make sense?

        -=o=-

        Please post all your code, including your callback.

        Did you subscribe to the AccountItemUpdate stream​?

        Comment


          #5
          Hello davydhnz,

          Thank you for your post. Thank you bltdavid for your input as well.

          I would like to chime in and ask some clarifying questions; davydhnz are you working in a strategy script, an indicator script, or looking for this information in general? The Account class and OnAccountItemUpdate() are definitely helpful suggestions. If you are working with a strategy specifically, you could access the TradesPerformance.TotalCommission property as well:


          If you are not seeing commissions values, please be sure to check that you are using a commissions template on the account being used:


          I look forward to your reply.
          Emily C.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Emily View Post
            If you are working with a strategy specifically, you could access the TradesPerformance.TotalCommission property as well:


            If you are not seeing commissions values, please be sure to check that you are using a commissions template on the account being used:
            Good points ... very good.

            This is the Indicator forum, so I assumed the OP
            was asking about how to do this from an indicator.

            Without enough code, we're always blind out here
            as we try to read people's minds and guess what
            their code is doing ... always the back and forth to
            clarify, if OPs would just post working code examples
            all these questions would be answered from the get go.

            That would be a nice present indeed.

            Sigh ...

            Merry Christmas everyone!



            Comment


              #7
              First of all,

              apologise if I was not clear in my communication.

              To answer bltdavid's question. My knowledge of C# is quite patchy. While I've written over 30 indicators, some of them from scratch,
              the first time I started was less than 2 years ago, but in all that time, I've never used AccountItem.

              I know if I want to get the current Instrument the chart is on, I use: Instrument.MasterInstrument.Name
              If I want to get the type and amount, I use: BarsPeriod.BarsPeriodType and BarsPeriod.Value

              But I don't know what single line to write which will return the commission price per trade for the currently selected instrument on the chart.

              Could anyone please provide that single line?

              The sim and playback accounts are set to:
              Click image for larger version

Name:	image.png
Views:	97
Size:	3.1 KB
ID:	1283794

              Click image for larger version

Name:	image.png
Views:	61
Size:	2.8 KB
ID:	1283795

              I obviously have written the commission line incorrectly.

              Since bltdavid asked me to send what the code is now, here it is:

              if (CurrentBar < Bars.Count - 1)
              {
              return;
              }

              // Print("Last Bar Of Chart. ");
              Print("\n" + Instrument.MasterInstrument.Name + " " + MyChartBarTime + " Stats");
              Print("Profit after Stops = $" + String.Format("{0:N0}", (dProfitHit - dStopHit)));
              Print("Risk:Reward = 1:" + Math.Round(((dProfitHit) / dStopHit), 2));
              Print("Total Profit = $" + String.Format("{0:N0}", dProfitHit));
              Print("Total Stop Hit = $" + String.Format("{0:N0}", dStopHit));
              Print("Commission = $" + AccountItem.Commission);

              Thank you


              ​​

              Comment


                #8
                Originally posted by davydhnz View Post
                First of all,

                apologise if I was not clear in my communication.

                To answer bltdavid's question. My knowledge of C# is quite patchy. While I've written over 30 indicators, some of them from scratch,
                the first time I started was less than 2 years ago, but in all that time, I've never used AccountItem.

                I know if I want to get the current Instrument the chart is on, I use: Instrument.MasterInstrument.Name
                If I want to get the type and amount, I use: BarsPeriod.BarsPeriodType and BarsPeriod.Value

                But I don't know what single line to write which will return the commission price per trade for the currently selected instrument on the chart.

                Could anyone please provide that single line?

                The sim and playback accounts are set to:
                Click image for larger version

Name:	image.png
Views:	97
Size:	3.1 KB
ID:	1283794

                Click image for larger version

Name:	image.png
Views:	61
Size:	2.8 KB
ID:	1283795

                I obviously have written the commission line incorrectly.

                Since bltdavid asked me to send what the code is now, here it is:

                if (CurrentBar < Bars.Count - 1)
                {
                return;
                }

                // Print("Last Bar Of Chart. ");
                Print("\n" + Instrument.MasterInstrument.Name + " " + MyChartBarTime + " Stats");
                Print("Profit after Stops = $" + String.Format("{0:N0}", (dProfitHit - dStopHit)));
                Print("Risk:Reward = 1:" + Math.Round(((dProfitHit) / dStopHit), 2));
                Print("Total Profit = $" + String.Format("{0:N0}", dProfitHit));
                Print("Total Stop Hit = $" + String.Format("{0:N0}", dStopHit));
                Print("Commission = $" + AccountItem.Commission);

                Thank you


                ​​
                The AccountItem.Commission value is not exactly what you are looking for, as it is not a commission value per contract on an instrument. As David mentioned, you could check for the account item update for commission and save that value somewhere. Otherwise, what you are asking for is not documented nor supported, though it seems as if some users have found some ways to get these values as discussed in the following thread:
                Hi, It has been probably asked before, but just to be sure I ask again. Is it possible to access an Instrument's Commission value? Screenshot attached.


                Please note that any unsupported methods/properties are subject to change at any time without notice. Use them at your own risk.

                Please let us know if we may be of further assistance.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  NinjaTrader_Emily

                  Thanks Emily!

                  I had it took me a few tries, then finally got it to work. Much appreciated!

                  Code:
                  public class IndicatorExample : Indicator
                  {
                  private Account myAccount;
                  
                  protected override void OnStateChange()
                  {
                  if (State == State.Configure)
                  {
                  myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
                  }
                  }
                  
                  protected override void OnBarUpdate()
                  {
                  if (Time != null && CurrentBars[0] < 1)
                  {
                  return;
                  }
                  
                  if (CurrentBar < Bars.Count - 1)
                  ​{
                  return;
                  }
                  
                  Print($"Commission = ${myAccount.Commission.ByMasterInstrument[Bars.Instrument.MasterInstrument].PerUnit * 2}");
                  }
                  }
                  ​

                  Comment


                    #10
                    NinjaTrader_Emily

                    My ninja has been crashing and getting corrupted sometimes lately and I've had to reinstall a few times.
                    That's not why I'm posting. But when I reinstalled my settings weren't setup for NinjaTrader Broker Timelife, but was set to blank.
                    And as a result the indicator wouldn't load.
                    Is there a command to see if Sim101 has any commissions set for it? Because if there was,
                    I could update my code to not try to calculate commissions in such an event and the indicator would load anyway.

                    Any advice appreciated. Worse case scenario, I'll make a bool for it. Calculate Commissions.

                    Thanks!

                    Comment


                      #11
                      Originally posted by davydhnz View Post
                      NinjaTrader_Emily

                      My ninja has been crashing and getting corrupted sometimes lately and I've had to reinstall a few times.
                      That's not why I'm posting. But when I reinstalled my settings weren't setup for NinjaTrader Broker Timelife, but was set to blank.
                      And as a result the indicator wouldn't load.
                      Is there a command to see if Sim101 has any commissions set for it? Because if there was,
                      I could update my code to not try to calculate commissions in such an event and the indicator would load anyway.

                      Any advice appreciated. Worse case scenario, I'll make a bool for it. Calculate Commissions.

                      Thanks!
                      As the code in the provided link is undocumented and unsupported, I can't provide anything specific. I suggest maybe adding a null reference check to check if the commission value exists before trying to access its value:


                      Thanks for your time and patience.
                      Emily C.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by fx.practic, 10-15-2013, 12:53 AM
                      5 responses
                      5,406 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Started by Shai Samuel, 07-02-2022, 02:46 PM
                      4 responses
                      98 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Started by DJ888, Yesterday, 10:57 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by MacDad, 02-25-2024, 11:48 PM
                      7 responses
                      160 views
                      0 likes
                      Last Post loganjarosz123  
                      Started by Belfortbucks, Yesterday, 09:29 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post Belfortbucks  
                      Working...
                      X