No announcement yet.

Partner 728x90


PriceOs.cs expecting ","

  • Filter
  • Time
  • Show
Clear All
new posts

    PriceOs.cs expecting ","

    EnterShort(Convert.ToInt32(DefaultQuantity), "");

    If (Position.MarketPosition == MarketPosition.Long)
    SetStopLoss(CalculationMode.Price, Low[2] - Ticksize);

    Error expecting "," after If (Position.MarketPosition == MarketPosition.Long)

    Any thoughts?

    Hello pplowman,

    Are you using a capital I on the if statement?
    Chelsea B.NinjaTrader Customer Service


      That was it! Thanks !!

      How do you reset SetStopLoss when MarketPosition.Flat?


        Hello pplowman,

        When using Set methods, these cannot be unset. This means it is important to set these before you place an entry order.

        Alternatively, use an Exit method instead of a Set method.
        Chelsea B.NinjaTrader Customer Service


          Could you send some sample code by chance?


            Hello Community,

            I've had to make changes to these scripts once again.

            With NinjaTrader 8, order objects returned from an order method may not be an equal object to the order object for the same order in OnOrderUpdate.

            From the help guide:
            // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
            // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting.

            Below is a publicly available link to the help guide.

            This is especially noticeable in Market Replay.

            The NinjaTrader 7 versions can be found in the post linked below.

            As a heads up, these scripts are just examples. Each approach has different aspects and limitations and may place orders at different times. These scripts are not designed to perfectly produce the same results. Instead, these are educational examples designed to show how one would move a stop and limit order with custom logic.

            (Update Sept 12th, 2018: Small change to ProfitChaseStopTrailUnmanagedExample logic cancelling stop and target to start flat. Changes to all three with prints.)

            (Update April 16th, 2020: Changed initial target placement price to use ProfitTargetDistance instead of hard coded 10)

            (Update Oct 28th, 2020: Added ProfitChaseStopTrailIndicatorExample)

            (Update Aug 3rd, 2021: Corrected ProfitChaseStopTrailUnmanagedExample line 215 to use StopLossDistance when calculating stop price instead of ProfitTargetDistance)

            Attached Files
            Last edited by NinjaTrader_ChelseaB; 02-02-2023, 07:26 AM.
            Chelsea B.NinjaTrader Customer Service


              I am learning from these examples. thanks

              Question: whats the benefits and drawbacks for using the SET methods vs ExitOrders in the context of trailing stops ?


                Hello dadarara,

                Ease of use.

                Set methods you can set before the script starts and not have to code for them.

                With exit methods you would need to write the code of when to submit them and if wanted design trailing logic.
                Chelsea B.NinjaTrader Customer Service


                  Could a Ninja Rep. let me know if its possible to use the difference between a previous bars High[1] & Low[1] for the stop loss calculation attached to the managed SetStopLoss(CalculationMode method?. The example in help is very limited in the help section for SetStopLoss. I can do this in the unmanaged approach ( totally differently )but I am tired of all the little intricacies in unmanaged that can be easily missed. I want to see if I can just use the SetStopLoss & SetProfitTarget for everything from now on.


                  Futures Phantom


                    Hi Futures Phantom,

                    The SetStopLoss method can be called in OnBarUpdate to change the stop loss while the strategy is running. You can set something like this:

                    SetStopLoss(CalculationMode.Currency, High[1] - Low[1]);

                    Kind regards,
                    Chris L.NinjaTrader Customer Service


                      sorry but I can´t figure out how to activate the strategy, in order to understand what does it does.
                      any help??
                      Thank you!!
             (4. 0 KB, 568 views)


                        I did a poor job at explaining what I was trying to calculate two posts above, If I wanted to use lets say for an example 60% of bar[1] (the prior bars) length as the initial SetStopLoss as I enter a long position with the (current bar) [0]. Could I use SetStopLoss(CalculationModePercent for this? Any help in with this calculation would be appreciated. Also would I need to include a 1 tick secondary bar series to be able to calculate the entire prior bars [1] length with wicks included ?

                        For example if I was using range bars and I wanted to use 110% of the ( calculated length = distance between its High and Low ) of a prior range bar, all my stops should be the same distance below my entry as range bars are all the same size. On a 5 minute chart all the stops should be random sizes based on the calculated length of each 5 minute [1] candle.

                        I probably over explained this but I am just trying to be clear... LOL

                        Thanks Futures Phantom
                        Last edited by FuturesPhantom; 08-22-2021, 04:21 PM.


                          Hi FuturesPhantom,

                          The CalculationMode.Percent is a percentage of the average entry price of the entry order. You would need to use CalculationMode.Price and then calculate an exact price to place your stop at. Allo price data can be found in the various Price series arrays documented here:

                          @efeuvejota01 Please start a new forum thread in the NinjaTrader 8 Strategy development section and describe your question in detail.

                          Kind regards.
                          Chris L.NinjaTrader Customer Service



                            ProfitChaseStopTrailUnmanagedExampleoco uses ocoString = Guid.NewGuid().ToString();
                            ProfitChaseStopTrailIndicatorExample uses string oco = Guid.NewGuid().ToString("N");

                            Per Guid.ToString Method (System) | Microsoft Docs


                            A single format specifier that indicates how to format the value of this Guid. The format parameter can be "N", "D", "B", "P", or "X". If format is null or an empty string (""), "D" is used.

                            N 32 digits:

                            D 32 digits separated by hyphens:

                            Most excellent samples, my question is this?

                            Does Ninja Care? When you Specify "N" it is not the default of "D"


                              Hi Bart, thanks for posting. The OCO ID is a String value, so it does not matter if the value is separated by hyphens or not.

                              Kind regards,
                              Chris L.NinjaTrader Customer Service


                              Latest Posts


                              Topics Statistics Last Post
                              Started by joanvanbeek9, Today, 05:10 PM
                              0 responses
                              Last Post joanvanbeek9  
                              Started by marco231, 03-20-2024, 03:56 PM
                              6 responses
                              Last Post marco231  
                              Started by samish18, Yesterday, 04:01 AM
                              4 responses
                              Last Post samish18  
                              Started by asd32, Today, 11:45 AM
                              2 responses
                              Last Post asd32
                              by asd32
                              Started by GonzaloTradingSystems, Today, 05:30 AM
                              1 response
                              Last Post GonzaloTradingSystems