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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    59 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    143 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    161 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    97 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    276 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X