Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Returning ticks from entry

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

    #16
    Here is all the pertinent code:

    publicclass NewTrendTrades : Strategy
    {
    #region Variables
    // Wizard generated variables
    privateint contracts = 2; // Default setting for Contracts
    privateint stop = 6; // Default setting for Stop 1st contract
    privateint trlTrigger = 6; //Default setting for number of ticks profit which will move the stop to b/e
    privateint t1 = 8; // Default setting for T1
    privateint t2 = 16; // Default setting for T2
    // User defined variables (add any user defined variables below)
    #endregion
    ///<summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    EntriesPerDirection =
    1; //For uniquely named entries which are required for scaling out
    EntryHandling = EntryHandling.UniqueEntries;

    CalculateOnBarClose =
    true;
    SetStopLoss(
    "Long 1a", CalculationMode.Ticks, Stop, true);
    SetStopLoss(
    "Long 1b", CalculationMode.Ticks, Stop, true);
    SetProfitTarget(
    "Long 1a", CalculationMode.Ticks, T1);
    SetProfitTarget(
    "Long 1b", CalculationMode.Ticks, T2);
    SetStopLoss(
    "Short 1a", CalculationMode.Ticks, Stop, true);
    SetStopLoss(
    "Short 1b", CalculationMode.Ticks, Stop, true);
    SetProfitTarget(
    "Short 1a", CalculationMode.Ticks, T1);
    SetProfitTarget(
    "Short 1b", CalculationMode.Ticks, T2);

    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Here we reset the stop to its original value in the case we trailed during the last trade.
    if (Position.MarketPosition==MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, Stop);
    }
    //Here we will move the stoploss to b/e if the market has moved enough in our direction
    elseif (Position.MarketPosition==MarketPosition.Long)
    {
    if (Close[0]>1.2948) //this didn't effect my stops at all??!!!
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    }
    }
    elseif (Position.MarketPosition==MarketPosition.Short)
    {
    if (Close[0]<(Position.AvgPrice-trlTrigger*TickSize))
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);

    Comment


      #17
      The lines you have in Initialize() will be run once. The rest of your code does modify it on every single OnBarUpdate(). Your condition is simply if you are long/flat/short you will modify the stop loss.

      Since you already are tying specific stops to specific entries you may want to continue this and also specify entrySignals throughout the rest of your code.

      How are you determining your price is even greater than 1.2948? You need to add print functions inside that if-statement to determine if you ever entered that segment of code.
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        Since you already are tying specific stops to specific entries you may want to continue this and also specify entrySignals throughout the rest of your code.

        "How are you determining your price is even greater than 1.2948?"

        I used this value in order to observe a specific entry where the 1st target was hit, but then the market turned around and took out the stop. This was to check to make sure that my problem was not in calcluating the b/e stop value.


        You need to add print functions inside that if-statement to determine if you ever entered that segment of code.

        Done--Where do I find this "output window"?

        Thanks.
        __________________

        Comment


          #19
          Control Center->Tools->Output Window
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            Change Stop Value at Profit Trigger-Resolved

            OK, I needed to add the specific entry name in order for the stop change to stick.
            The following code works: (thank you!)

            [Description("This strategy tests the new trend trades")]
            publicclass NewTrendTrades : Strategy
            {
            #region Variables
            // Wizard generated variables
            privateint contracts = 2; // Default setting for Contracts
            privateint stop = 6; // Default setting for Stop 1st contract
            privateint trlTrigger = 6; //Default setting for number of ticks profit which will move the stop to b/e
            privateint t1 = 8; // Default setting for T1
            privateint t2 = 16; // Default setting for T2

            #endregion
            ///<summary>
            protectedoverridevoid Initialize()
            {
            EntriesPerDirection = 1; //For uniquely named entries which are required for scaling out
            EntryHandling = EntryHandling.UniqueEntries;

            CalculateOnBarClose = true;
            SetStopLoss("Long 1a", CalculationMode.Ticks, Stop, true);
            SetStopLoss("Long 1b", CalculationMode.Ticks, Stop, true);
            SetProfitTarget("Long 1a", CalculationMode.Ticks, T1);
            SetProfitTarget("Long 1b", CalculationMode.Ticks, T2);
            SetStopLoss("Short 1a", CalculationMode.Ticks, Stop, true);
            SetStopLoss("Short 1b", CalculationMode.Ticks, Stop, true);
            SetProfitTarget("Short 1a", CalculationMode.Ticks, T1);
            SetProfitTarget("Short 1b", CalculationMode.Ticks, T2);
            }
            /// Called on each bar update event (incoming tick)
            protectedoverridevoid OnBarUpdate()
            {
            // Here we reset the stop to its original value in the case we trailed during the last trade.
            if (Position.MarketPosition==MarketPosition.Flat)
            {
            SetStopLoss("Long 1b", CalculationMode.Ticks, Stop, true);
            SetStopLoss("Short 1b", CalculationMode.Ticks, Stop, true);
            }
            //Here we will move the stoploss to b/e if the market has moved enough in our direction
            elseif (Position.MarketPosition==MarketPosition.Long)
            {
            if (Close[0]>Position.AvgPrice+TrlTrigger*TickSize)
            {
            SetStopLoss("Long 1b", CalculationMode.Price, Position.AvgPrice, true);
            }
            }
            elseif (Position.MarketPosition==MarketPosition.Short)
            {
            if (Close[0]<(Position.AvgPrice-trlTrigger*TickSize))
            {
            SetStopLoss("Short 1b", CalculationMode.Price, Position.AvgPrice, true);
            }
            }

            Comment


              #21
              Originally posted by NinjaTrader_Josh View Post
              TickSize gives you the tick size of your instrument as defined in the Instrument Manager.
              How to view the volume of one tick (not only the last one)? What will be the function?

              Comment


                #22
                Hello,

                You would enter need to access tick data or store the volume per tick in an array for access later.
                DenNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                633 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                364 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                567 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                568 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X