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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    64 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    35 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    59 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    51 views
    0 likes
    Last Post CarlTrading  
    Working...
    X