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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    73 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    152 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    162 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    100 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    288 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X