Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Immediately Submit being weird.

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

    Immediately Submit being weird.

    New user: testing a basic strategy.

    When i hit "Immediately Submit" i expect the algo to wait for buy conditons and then execute the code without waiting for the virtual orders to be flat.

    But when i turn on the strategy and hit "Immediately submit" the computer says "Order Placed" and places two stop limits, without submitting a working order.

    The weirdest part is sometimes it works the way i think it should and sometimes it does this weird thing.

    I have tried it on two different computers with the same result. Sometimes it works like i think it should and sometimes it places two limit orders where the stops should be in the strategy.

    is there something wrong with my code? I dont think so because it worked earlier this week, but now i'm having problems.

    I'm using 8.1.2

    I have had the same issue in playback and in a live enviorment, and i have updated NinjaTrader on my other PC with the same results.

    Here's a video of whats happening: https://streamable.com/g43by4

    And heres the code i'm testing incase i'm missing something.

    Thanks!

    region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class Alex13325 : Strategy
    {
    private EMA emaFast1;
    private EMA emaSlow1;

    private EMA emaFast5;
    private EMA emaSlow5;

    private EMA emaFast15;
    private EMA emaSlow15;

    private int takeProfitTicks = 400; // Adjust this value for your desired Take Profit in ticks
    private int stopLossTicks = 200; // Adjust this value for your desired Stop Loss in ticks

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMACrossOver;
    Name = "MULTIEMA";
    Fast1 = 10;
    Slow1 = 50;

    Fast5 = 50;
    Slow5 = 100;

    Fast15 = 100;
    Slow15 = 200;


    }
    else if (State == State.DataLoaded)
    {
    emaFast1 = EMA(Fast1);
    emaSlow1 = EMA(Slow1);

    emaFast5 = EMA(Fast5);
    emaSlow5 = EMA(Slow5);

    emaFast15 = EMA(Fast15);
    emaSlow15 = EMA(Slow15);

    emaFast1.Plots[0].Brush = Brushes.Goldenrod;
    emaFast1.Plots[0].Width = 4;
    emaSlow1.Plots[0].Brush = Brushes.Red; // Adjust the color as needed
    emaSlow1.Plots[0].Width = 4;

    emaFast5.Plots[0].Brush = Brushes.Pink;
    emaFast5.Plots[0].Width = 4;
    emaSlow5.Plots[0].Brush = Brushes.Red; // Adjust the color as needed
    emaSlow5.Plots[0].Width = 4;

    emaFast15.Plots[0].Brush = Brushes.SeaGreen;
    emaFast15.Plots[0].Width = 4;
    emaSlow15.Plots[0].Brush = Brushes.Red; // Adjust the color as needed
    emaSlow15.Plots[0].Width = 4;

    AddChartIndicator(emaFast1);
    AddChartIndicator(emaSlow1);

    AddChartIndicator(emaFast5);
    AddChartIndicator(emaSlow5);

    AddChartIndicator(emaFast15);
    AddChartIndicator(emaSlow15);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < BarsRequiredToTrade)
    return;


    if (emaFast1[0] > emaSlow1[0] && emaFast5[0] > emaSlow5[0] && emaFast15[0] > emaSlow15[0])
    {
    EnterLong(1);
    SetProfitTarget(CalculationMode.Ticks, takeProfitTicks);
    SetStopLoss(CalculationMode.Ticks, stopLossTicks);
    }


    }

    region Properties
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(Name = "Fast1", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
    public int Fast1 { get; set; }

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(Name = "Slow1", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
    public int Slow1 { get; set; }

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(Name = "Fast5", GroupName = "NinjaScriptStrategyParameters", Order = 2)]
    public int Fast5 { get; set; }

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(Name = "Slow5", GroupName = "NinjaScriptStrategyParameters", Order = 3)]
    public int Slow5 { get; set; }

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(Name = "Fast15", GroupName = "NinjaScriptStrategyParameters", Order = 4)]
    public int Fast15 { get; set; }

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(Name = "Slow15", GroupName = "NinjaScriptStrategyParameters", Order = 5)]
    public int Slow15 { get; set; }

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(Name = "takeProfitTicks", GroupName = "NinjaScriptStrategyParameters", Order = 6)]
    public int TakeProfitTicks
    {
    get { return takeProfitTicks; }
    set { takeProfitTicks = value; }
    }

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(Name = "StopLossTicks", GroupName = "NinjaScriptStrategyParameters", Order = 7)]
    public int StopLossTicks
    {
    get { return stopLossTicks; }
    set { stopLossTicks = value; }
    }
    #endregion
    }
    }​

    #2
    Hello tusktooth,

    Thanks for your post and welcome to the Forums.

    When a strategy is enabled, it processes historical data to determine trades that the strategy would have made on the data that is already on the PC/chart and to determine what position the strategy is in. (Strategy positions are separate from actual Account positions.)

    Immediately Submit automatically submits working orders from when the strategy processed historical data, and assumes the strategy position and account position are where you want it when you enable the strategy. This is typically used to have a strategy resume a position after disabling/enabling.

    If the strategy already had live orders running, the orders will resume with the new enablement of the strategy if they match the historically calculated orders. If the orders calculated from historical data do not match the live working orders, the live working orders will be cancelled and replaced by those calculated from historical data.

    Sync Account Positions is an additional option that has NinjaTrader submit an order to sync the account position to the position calculated by the strategy. (Not the other way around.)

    ​Strategy vs. Account Position — https://ninjatrader.com/support/help..._account_p.htm

    Start Behaviors — https://ninjatrader.com/support/help..._positions.htm

    Further, I see you are calling Set methods after the Enter method. Set methods prep NinjaTrader to submit protective orders when an execution occurs. The Set methods should be called before the Enter method.

    For example:

    SetStopLoss();
    SetProfitTarget();
    EnterLong();

    From the help guide:

    "Since they are submitted upon receiving an execution, the Set method should be called prior to submitting the associated entry order to ensure an initial level is set."

    SetProfitTarget(): https://ninjatrader.com/support/help...ofittarget.htm
    SetStopLoss(): https://ninjatrader.com/support/help...oss.htm​
    Last edited by NinjaTrader_BrandonH; 02-04-2024, 05:16 PM.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks for the prompt reply,

      Which option should i select, if i want the algo to execute an order, as soon as the conditions are met?

      I have a very high stoploss, so i dont want to wait for the virutal / historical position to become flat before looking for an entry.

      I just want to enable the algo, and then as soon as the buy conditions are met for it to take an order.

      Comment


        #4
        Hello tusktooth,

        Thanks for your notes.

        If you want the strategy to place orders when the conditions are met, you could use the Start Behavior "Wait Until Flat".

        You could add logic to your strategy to exit the position on the last historical bar so that the strategy will start in a flat position when real-time data starts processing.

        There is sample code on the forum thread linked below that you could view demonstrating how to find the last historical bar and submit an exit order for a long or short position.

        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        52 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        48 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X