Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Prevent strategy from executing trade at the same price level within a session

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

    Prevent strategy from executing trade at the same price level within a session

    I have been researching the following topic of saving a variable in NT for use within a strategy to prevent the strategy from executing at the same price more than once within a session and I'm having some trouble trying to get it to compile.

    Code:
    // 
    // Copyright (C) 2007, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Strategy;
    #endregion
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Sample strategy
        /// </summary>
        [Description("Sample strategy")]
        public class MyCustomStrategy : Strategy
        {
            #region Variables
            double myEntryOrder        =     Position.AvgPrice;
            #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()
            {
                SetStopLoss("", CalculationMode.Ticks, 6, false);
                SetProfitTarget("", CalculationMode.Ticks, 25);
    
                CalculateOnBarClose = false;
            }
            
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                
                // Condition set 1
                if (CurrentDayOHL().CurrentLow[0] >= IY().IU[0]
                    && Position.MarketPosition == MarketPosition.Flat
                    && BarsSinceExit() > 40 && myEntryOrder != IY().IU[0])
                {
                    myEntryOrder = EnterLongLimit(DefaultQuantity, IY().IU[0], "");
                    
                }
                
            }
            
            #region Properties
            #endregion
        }
    }
    If anyone one has the chance to review the code attached I would appreciate any help you can provide...
    Last edited by suprsnipes; 02-28-2010, 09:58 PM.

    #2
    suprsnipes, which exact compile error are you getting returned?

    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