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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    574 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X