Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Based on Ask Price

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

    Strategy Based on Ask Price

    I want to develop a strategy based on Ask price. The strategy will have a Trail Stop and I want Trail Stop to be based on Ask price drop.

    I open a new chart with "Price based on Ask". Then I set up the strategy with CalculateOnBarClose = false to make sure that OnBarUpdate is called on each incoming tick. I also use SetTrailStop(currency) in the script.

    Now I have this question:

    If the price of the chart is based on Ask and CalculateOnBarClose = false, does it mean that all methods - EnterLong(), SetTrailStop(), etc - will use Ask price?

    Thanks,

    Valentin

    #2
    Hello Valentin,

    Thank you for your note.

    Correct, unless you add any other underlying data series to the script, the strategy will use only the ask prices from the chart.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thank you, Cal.

      It will be a multi-timeframe strategy, with primary Minute bars and supplementary Minute bars. The instrument will be the same, only period will be different.

      Will it use Ask price for orders and trail stops in this case?

      Will I have access to Closes, Opens, etc?

      Comment


        #4
        Valentin,

        You would want to have the underlying data series use Ask data for this then. Using just -
        Code:
        Add(PeriodType.Minute, 1);
        will use Last price data.


        Use this syntax instead -
        Code:
        Add(Instrument.FullName, PeriodType.Minute, 1, MarketDataType.Ask);
        Let me know if I can be of further assistance.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Thank you, Cal.

          I would like Ask data for the primary bars only, so something like

          Code:
          Add(PeriodType.Minute, 1);
          should be enough.

          I have other questions about changing parameters 'at run time'.

          I see that I have to disable the strategy and to enable it again after I change parameters. Is it always like this?

          Does it mean that there will be two completely different sessions - before disabling and after enabling the strategy?

          What will happen if I have open position when I disable the strategy? Will the position be closed automatically?

          Comment


            #6
            Valentin,

            Correct you have to disable and re-enable for the changes to be calculated in this case.

            The position will still be active on the account and not be closed by the strategy being disabled.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Thank you, Cal.

              So I could change for example Trail Stop and when I enable the strategy, the new Trail Stop will be applied?

              Does it work with SetTrailStop() in Initialize() or I have to use SetTrailStop() in OnBarUpdate()?

              Comment


                #8
                Valentin,

                Yes, you could effectively do this.

                Please note that your strategy has its own position tracking for this purpose and will not get the actual account's position.

                When you disable and re-enable it will re-calculate the data like a backtest and report the most recent position. If the conditions are still active for the recently position it will report this.

                You will want to have a couple settings in place for this as well.

                Tools -> Options -> Strategies -> NinjaScript -> Use Immediately submit working historical orders

                Additionally, when you start the strategy you will want to set your Sync Account position property.
                If you set this to false with the above setting, it will start submitting and orders that it needs. This scenario is only if you are sure that your account position is in relation with your strategy position

                There are other scenarios available and can be read from the page below-
                http://www.ninjatrader.com/support/h..._positions.htm

                We also have a video on this process that shows what will happen -
                https://www.youtube.com/watch?v=US9c...A140D7&index=7
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Cal View Post
                  ...
                  Please note that your strategy has its own position tracking for this purpose and will not get the actual account's position.

                  When you disable and re-enable it will re-calculate the data like a backtest and report the most recent position. If the conditions are still active for the recently position it will report this.

                  You will want to have a couple settings in place for this as well.

                  Tools -> Options -> Strategies -> NinjaScript -> Use Immediately submit working historical orders

                  Additionally, when you start the strategy you will want to set your Sync Account position property.
                  If you set this to false with the above setting, it will start submitting and orders that it needs. This scenario is only if you are sure that your account position is in relation with your strategy position
                  Thanks, Cal.

                  I set up 'Immediately submit working historical orders'.

                  Only this strategy will submit orders in the account, but I should set Sync Account position to be true, because of following scenario:

                  For example Trail Stop is set to 3 and a Long position is open. I could disable the strategy and set up Trail Stop to 1, and then enable the strategy. The strategy will recalculate all historical positions. If the new Trail Stop condition is met with historical data, the strategy position will be Flat while Account position will be Long. That is why I need Sync Account position to be true.
                  On the first incoming tick (with CalculateOnBarClose = false), if new Trail Stop condition is met, the stop order will be submitted. Is it correct?

                  Can I use SetTrailStop() in Initialize() to be able to change it? Is Initialize() method called each time when I enable the strategy or I have to use SetTrailStop() in OnBarUpdate()?
                  Last edited by Valyo; 03-12-2015, 09:01 AM.

                  Comment


                    #10
                    Valentin,

                    Yes, correct. When you start the strategy, if it is flat and the account is long, the strategy will submit an order to have the account match the strategy position, meaning making the account flat.

                    Initialize() is called once when the strategy is enabled.
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      OK, thank you.

                      Now I cannot enable the strategy, because my Trail Stop is rejected. I get a message "Sell Stop or sell stop limit orders can't be placed above the market"

                      I use either

                      Code:
                      SetTrailStop(double currency)
                      or

                      Code:
                      SetTrailStop(CalculationMode mode, double value) with CalculationMode.Percent
                      and every time it is the same.

                      When I check orders, the stop is the same as Buy average price. But is should be lower, because I use currency = 0.5. How could I fix it?

                      Orders are placed on each incoming tick. I attach screenshot.
                      Attached Files

                      Comment


                        #12
                        Valentin,

                        This is because curreny mode is irrelevant for Trail Stop.

                        You would want to use Ticks or Percentage for this and set the value that way.

                        Let me know if I can be of further assistance.
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          Cal,

                          As I read in NinjaTrader help

                          Note: CalculationMode.Price is irrelevant for trail stops
                          Do you mean that

                          Code:
                          SetTrailStop(double currency)
                          is also irrelevant for Trail Stop?

                          Then why it is provided (and accepted) as syntax for SetTrailStop()? And how can I set Trail Stop with a fixed amount, $5 loss for example?

                          Thanks,

                          Comment


                            #14
                            Hello Valyo,

                            With SetStopLoss you are able to set a price for the stop. With SetTrailStop you cannot use a price, you must use an amount of ticks to trail or a percentage to trail.

                            This is so that the trail knows how many ticks away from the stop it should stay should the price reverse for a while and then return.

                            Instead for a trail stop, use an amount of ticks, or use a percentage for the CalculationMode.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Thank you, Chelsea.

                              I tried CalculationMode.Ticks and it worked.

                              So, CalculationMode.Percent and CalculationMode.Ticks work for SetTrailStop() and SetTrailStop(double currency) doesn't work, no matter that it is provided as valid syntax in NinjaTrader help.

                              However there is still something strange.

                              I tried first CalculationMode.Ticks with value 2 ticks and got the same error - "Sell Stop or sell stop limit orders can't be placed above the market", and Trail Stop was rejected.

                              Then I tried CalculationMode.Ticks with value 100 ticks and Stop price was exactly $0.01 lower than Buy price (Instrument was $AUDUSD). This time the Trail Stop was accepted.

                              It seems that offset in ticks should be at least $0.01, otherwise the price is considered to be "above the market". Is it true?

                              And another question - if I want to use currency amount for Trail Stop, can I use CalculationMode.Ticks with Tick Value = Currency Amount / Tick Size ?

                              Thanks,

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              599 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              344 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              558 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              557 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X