Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Use a filter conditions ( last 3 trades wins, not enterlong)

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

    Use a filter conditions ( last 3 trades wins, not enterlong)

    Hello to all.
    I would like to include a filter condition in my strategy = (if last 3 trades wins, not enter in the next trade).

    But i cannot solve an index out of bounds array error





    ​ public class longstrategy : Strategy
    {​
    double firstTradeProfitCurrency = 0;
    double secondTradeProfitCurrency = 0;
    double thirdTradeProfitCurrency =0;​

    protected override void OnBarUpdate()
    {​


    if (BarsInProgress != 0)

    return;


    // if (CurrentBar < BarsRequiredToTrade)
    // return;
    if(CurrentBars[0] < 10 || CurrentBars[1] < 10 || CurrentBars[2] < 10 || CurrentBars[3] < 10) return;

    // Evaluate strategy logic once per bar
    if (IsFirstTickOfBar)
    {​
    firstTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency;
    secondTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 2].ProfitCurrency;
    thirdTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 3].ProfitCurrency;

    if ((firstTradeProfitCurrency<=0) || (secondTradeProfitCurrency<=0) || (thirdTradeProfitCurrency<=0))
    enter long
    ...
    ...
    ...


    thanks in advance

    #2
    Hello memonic,

    Check the trade count first.

    if (SystemPerformance.AllTrades.Count > 3)
    {
    // there are 3 trades
    }
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    22 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    120 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    63 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    45 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X