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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    68 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 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
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X