Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Long Positions entering correctly but Not Shorts?

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

    Long Positions entering correctly but Not Shorts?

    Hi,

    Long Positions are entering correctly on this strategy but not Shorts?
    Positions are supposed to enter at the desired time.

    Am I doing something incorrectly?


    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class Timetest : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // 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>
    protected override void Initialize()
    {
    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (ToTime(Time[0]) > ToTime(8, 0, 0)
    && ToTime(Time[0]) < ToTime(8, 20, 0))
    {
    EnterLong(100000, "Long");
    }

    // Condition set 2
    if (Position.Quantity > 0
    && ToTime(Time[0]) > ToTime(10, 20, 0))
    {
    ExitLong("", "");
    }

    // Condition set 3
    if (ToTime(Time[0]) > ToTime(11, 0, 0)
    && ToTime(Time[0]) < ToTime(11, 20, 0))
    {
    EnterShort(100000, "Short");
    }

    // Condition set 4
    if (Position.Quantity < 0
    && ToTime(Time[0]) > ToTime(11, 40, 0))
    {
    ExitShort("", "");
    }
    }
    Attached Files

    #2
    Set 4. Position quantity would never be < 0. It would be a positive number regardless if you are long or short. If you want to check against a short position you want to check for Position.MarketPosition == MarketPosition.Short.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      That's helpful. Thank You very much.

      Comment


        #4
        Is this what I should be using to exit a position based on the PNL from within the Strategy?



        // Condition set 3
        if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) >= 150
        && Position.MarketPosition == MarketPosition.Long)
        {
        ExitLong("Profit", "");
        }

        // Condition set 4
        if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) <= -300
        && Position.MarketPosition == MarketPosition.Long)
        {
        ExitLong("Stop Loss", "");
        }

        Comment


          #5
          Yes, that should do it tschalli27.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          630 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
          564 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