Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 JackyP, Today, 06:17 AM
    0 responses
    3 views
    0 likes
    Last Post JackyP
    by JackyP
     
    Started by rodriguesdanny, 05-15-2024, 12:06 PM
    3 responses
    19 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by FAQtrader, 04-25-2024, 12:00 PM
    16 responses
    262 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Irukandji, Today, 05:49 AM
    0 responses
    4 views
    0 likes
    Last Post Irukandji  
    Started by Human#102, Today, 05:18 AM
    0 responses
    9 views
    0 likes
    Last Post Human#102  
    Working...
    X