Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit strategy to one trade per day

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

    Limit strategy to one trade per day

    I am wanting to place only one trade per day for my strategy.

    When I use the following code, I have a problem with the variables. When I try to backtest the strategy the window into which you adjust your variables is all completely blank and I am not able to go any further.

    I was working fine until I put in the "private bool traded = false;" I think I have it in the wrong place.

    Please give some suggestions.
    Thanks
    Glen

    /// <summary>
    /// End of Day Trade
    /// </summary>
    [Description("End of Day Trade")]
    public class EndOfDayTrade : Strategy

    {
    #region Variables
    // Wizard generated variables
    private int profitTarget = 44; // Default setting for ProfitTarget
    private int stopLoss = 15; // Default setting for StopLoss
    // User defined variables (add any user defined variables below)
    #endregion

    private bool traded = false;

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    Add(OpenPrice830(8, 30));
    Add(ClosePrice1429(14, 29));
    Add(Stochastics(4, 6, 2));
    Add(OpenPrice830(8, 30));
    Add(ClosePrice1429(14, 29));
    Add(Stochastics(4, 6, 2));
    SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
    SetStopLoss("", CalculationMode.Ticks, StopLoss, false);

    CalculateOnBarClose = true;
    if (Bars.FirstBarOfSession && FirstTickOfBar)
    traded = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>

    protected override void OnBarUpdate()

    {
    // Condition set 1
    if (ToTime(Time[0]) > ToTime(14, 30, 0)
    && OpenPrice830(8, 30).OpenPrice[0] < ClosePrice1429(14, 29).ClosePrice[0]
    && Stochastics(4, 6, 2).D[1] < Stochastics(4, 6, 2).D[0]
    && Open[0] < Close[0]
    && traded == false)
    {
    EnterLong(DefaultQuantity, "EDT Long");
    traded = true;
    }

    // Condition set 2
    if (ToTime(Time[0]) > ToTime(14, 30, 0)
    && OpenPrice830(8, 30).OpenPrice[0] > ClosePrice1429(14, 29).ClosePrice[0]
    && Stochastics(4, 6, 2).D[1] > Stochastics(4, 6, 2).D[0]
    && Open[0] > Close[0]
    && traded == false)
    {
    EnterShort(DefaultQuantity, "EDT Short");
    traded = true;
    }
    }

    #2
    Hello,


    Thank you for your note.

    Start by moving your new bool line above #endregion.

    Also move this:

    if (Bars.FirstBarOfSession && FirstTickOfBar)
    traded = false;


    From the Initialize method and into the OnBarUpdate method at the top.
    DenNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    580 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    335 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    102 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    554 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    552 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X