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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    50 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    22 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    16 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    22 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X