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

CalculationMode in AddOns

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

    CalculationMode in AddOns

    Is it possible to take advantage of the CalculationMode types in AddOns, such that by providing an Account, Instrument and reference Price, using any of the (non-Price) CalculationModes will return the Price which the given parameters would produce if used in SetStopLoss, for example? Essentially, decomposing the SetStopLoss method.

    This would allow one to quickly calculate from Ticks, Pips, Points or Currency, the resulting Price relative to the specified Price (not necessarily the current real-time Price) that represents the move of the specified amount in the specified Account for the specified Instrument.

    Similarly, given an Account, Instrument and a Price differential (the amount of price movement), it would be great for the inverse calculations to be available; i.e. a Price movement amount could be returned as a specific change in Ticks, Pips, Points or Currency.

    Thanks.
    Last edited by jeronymite; 10-04-2020, 03:21 AM.
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    #2
    Hello jeronymite,

    Addons do not have native Series and thus does not update a native OnBarUpdate method.

    A BarsRequest is used to get data and this will only update for every tick.
    https://ninjatrader.com/support/help...arsrequest.htm

    You could use a variable to look at the price of the updated tick and compare this to the saved price to see if the price has changed.
    Your custom logic would need to do this.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      All understood, Chelsea.

      I'm not trying to use native series data, simply trying to access the logic of the CalculationMode calculations.

      For example, if I have two Prices for a specific Instrument, I would like to be able to use the underlying CalculationMode calculations to determine what the difference between the two Prices is in Ticks, Pips and Points. In the context of a specific Account, I would also like to use the underlying CalculationMode calculations to determine what the difference between the two Prices is in Percent and Currency.

      Conversely, if I have one Price for a specific Instrument, I would like to be able to use the underlying CalculationMode calculations to determine what the Price would be that was a given number of Ticks, Pips or Points distant from the given Price. In the context of a specific Account, I would also like to use the underlying CalculationMode calculations to determine what the Price would be for a given Percent or Currency change.

      I do not expect that these calculations are currently available for use (although it would be great if they were), but having a simple interface to them that would accept a Price and a delta of some sort, or two Prices, and return the appropriate result, in like manner to what is returned in a Strategy when using SetStopLoss, would be extremely useful.

      Example pseudo-code usage of the CalculationMode logic:
      Code:
      GetPriceDelta(Instrument ThisInstrument, double Price1, double Price2, CalculationMode.Points)
      GetPriceDelta(Account ThisAccount, Instrument ThisInstrument, double Price1, double Price2, CalculationMode.Percent)
      
      GetPrice(Instrument ThisInstrument, double Price, double PriceDelta, CalculationMode.Points)
      GetPrice(Account ThisAccount, Instrument ThisInstrument, double Price, double PriceDelta, CalculationMode.Percent)
      The CalculationMode could be any of the supported modes appropriate for the pseudo-methods above.

      Thanks.
      Multi-Dimensional Managed Trading
      jeronymite
      NinjaTrader Ecosystem Vendor - Mizpah Software

      Comment


        #4
        Hello jeronymite,

        I miss understood that you are wanting the CalculationMode for SetStopLoss().

        You would need to calculate this based on price.

        For example CalculationMode.Ticks could be calculated by dividing the price by the Instrument.MasterInstrument.TickSize.

        CalculationMode.Currency could be calculated using the Instrument.MasterInstrument.PointValue.
        Last edited by NinjaTrader_ChelseaB; 10-05-2020, 07:59 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Understood, Chelsea. And thanks for responding. Yes, I can do all those calculations. It would, however, be very convenient if the underlying CalculationMode logic could be exposed in a way that made all that "manual" calculation superfluous. One could simply call the relevant methods with the appropriate parameters and have the correct results. It would be rather like having SetStopLoss, but instead it could be GetStopLoss using the appropriate metric. This would be particularly useful when wanting to calculate a StopLoss in percent or Currency. Similarly for "GetProfitTarget". Hope that makes sense.

          Thanks.
          Multi-Dimensional Managed Trading
          jeronymite
          NinjaTrader Ecosystem Vendor - Mizpah Software

          Comment


            #6
            Hello jeronymite,

            Set methods, which have internal logic made by NinjaTrader to control, cannot be used in addons, which is more of an area for you to design what you want without NinjaScript Strategy tools.

            This is something specific to NinjaScript Strategies which may be more suitable for what you are wanting.

            For an addon, my suggestion would be to submit an order with atm strategy which has a stop loss controlled with logic and you can set the calculation mode with the template.
            Below is a link to an example.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Understood, Chelsea. Thanks for the reference. My comments relate to making the logic available more generally, not to using the specific Strategy methods in AddOns. I already have written appropriate AddOn code. But having this logic available more generally would mean the identical logic could be used in a variety of NinjaTrader objects with consistency and convenience.

              Thanks.
              Last edited by jeronymite; 10-05-2020, 07:21 PM.
              Multi-Dimensional Managed Trading
              jeronymite
              NinjaTrader Ecosystem Vendor - Mizpah Software

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,604 views
              0 likes
              Last Post aligator  
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              8 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              4 views
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              13 views
              0 likes
              Last Post Javierw.ok  
              Working...
              X