Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

place a market oder when the market opens

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

    place a market oder when the market opens

    I want a code to place an order long at a specified time, and then close the order when profit target reaches 1 point.

    This is what I have, it's probably entirely incorrect, but I tried.


    #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.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Quick Tick
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class MyCustomStrategy4 : 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 = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()

    {
    if (ToTime(Time[0]) == ToTime( 09, 29, 59))
    {
    AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0 ,
    TimeInForce.Day, GetAtmStrategyUniqueId(), "Quick" ,
    GetAtmStrategyUniqueId());
    }

    protected override void Initialize()
    // Submits a profit target order 4 ticks away from the avg entry price
    SetProfitTarget(CalculationMode.Ticks,4;
    }


    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Hello cmach123,

    Thank you for your post.

    The following in unecessary if your ATM Strategy already uses a 1 Point Profit Target.
    Code:
    protected override void Initialize()
    // Submits a profit target order 4 ticks away from the avg entry price
    SetProfitTarget(CalculationMode.Ticks,4;
    }

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    84 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    47 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    29 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    32 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    66 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X