Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PriceOs.cs expecting ","

Collapse
X
 
  • 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?

    #2
    Hello pplowman,

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

    Comment


      #3
      That was it! Thanks !!

      How do you reset SetStopLoss when MarketPosition.Flat?

      Comment


        #4
        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

        Comment


          #5
          Could you send some sample code by chance?

          Comment


            #6
            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.
            https://ninjatrader.com/support/help...rderupdate.htm

            This is especially noticeable in Market Replay.

            The NinjaTrader 7 versions can be found in the post linked below.
            https://ninjatrader.com/support/foru...604#post478604

            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)

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

            Comment


              #7
              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 ?

              Comment


                #8
                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

                Comment


                  #9
                  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.

                  Thanks

                  Futures Phantom

                  Comment


                    #10
                    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,
                    -ChrisL
                    Chris L.NinjaTrader Customer Service

                    Comment


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

                      Comment


                        #12
                        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.

                        Comment


                          #13
                          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

                          Comment


                            #14
                            NinjaTrader_ChelseaB


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

                            Per Guid.ToString Method (System) | Microsoft Docs

                            Parameters

                            formatString
                            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:

                            00000000000000000000000000000000
                            D 32 digits separated by hyphens:

                            00000000-0000-0000-0000-000000000000
                            Most excellent samples, my question is this?

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

                            Comment


                              #15
                              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,
                              -ChrisL
                              Chris L.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,603 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
                              12 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X