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 fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,406 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    98 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    8 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    160 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    9 views
    0 likes
    Last Post Belfortbucks  
    Working...
    X