Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unexpected buy orders

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

    Unexpected buy orders

    I'm writing my first custom strategy and encountered some unexpected buy orders:

    The strategy logic is quite simple: Enter the market if a custom indicator holds true, and exit after 10 bars (or stop loss at 10%)

    However, I found some orders entered the market even the indicator is false (Please refer to screen cap)

    In the screen cap, the green box denoted a correct order: indicator (shown as small blue triangle) holds true and entering the market

    the red box denoted a wrong order: indicator is false but still entered the market.

    Both custom indicator and strategy code is attached below.

    Any idea please ?


    ------------------------------------
    public class MyCustomStrategy1103 : Strategy
    {
    #region Variables
    // Wizard generated variables
    // 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()
    {
    SetStopLoss("", CalculationMode.Percent, 0.1, true);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (AAALowDownBuy(1.75, 1.75).Plot0[0] == 1)
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (BarsSinceEntry() == 10)
    {
    ExitLong("", "");
    }
    }

    #region Properties
    #endregion
    }

    -------custom indicator--------------
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    if (CurrentBar < 10) return;
    if (Low[0] < Low[1] && Low[1] < Low[2] && Low[2] < Low[3] && (Low[2] - Low[0])/Low[2]>= percentage1/100 && (Low[3] - Low[1])/Low[3]>= percentage2/100 && Low[0] < MIN(Low,5)[1]){
    Plot0.Set(1);
    }
    }
    Attached Files

    #2
    What is the Plot0 set to at the time of the invalid order? From your indicator, do you reset the Plot to 0 when the condition is no longer true?

    I'd suggest adding Print() statements to ensure that Plot value is what you expect at this time.
    MatthewNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    55 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    142 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 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