Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What's wrong with my script? Thanks in advance

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

    What's wrong with my script? Thanks in advance

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class ZZZ : Strategy
    {
    private RSI RSI1;
    private MACD MACD1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "ZZZ";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    RSI1 = RSI(2,1);
    MACD1 = MACD(12,26,9);
    }
    }

    protected override void OnBarUpdate()
    {
    // Set 1
    if ((CrossAbove(RSI1.Default, 10, 0))
    && (MACD1.Diff[0] > 0))
    {
    EnterLong(10, "");
    }
    // Set 2
    if (CrossAbove(RSI1.Default, 80, 0))
    {
    ExitLong(10, "", "");
    }

    }
    }
    }

    #2
    Originally posted by sashe71 View Post
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class ZZZ : Strategy
    {
    private RSI RSI1;
    private MACD MACD1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "ZZZ";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    RSI1 = RSI(2,1);
    MACD1 = MACD(12,26,9);
    }
    }

    protected override void OnBarUpdate()
    {
    // Set 1
    if ((CrossAbove(RSI1.Default, 10, 0))
    && (MACD1.Diff[0] > 0))
    {
    EnterLong(10, "");
    }
    // Set 2
    if (CrossAbove(RSI1.Default, 80, 0))
    {
    ExitLong(10, "", "");
    }

    }
    }
    }
    What makes you think that anything is wrong?

    Comment


      #3
      Hello sashe71,

      Thank you for writing in.

      Can you please clarify what issue(s) you are running into with your script?
      Zachary G.NinjaTrader Customer Service

      Comment


        #4
        I try to backtest it on 15 min with ES 09-16, it returns no results

        Comment


          #5
          Originally posted by sashe71 View Post
          I try to backtest it on 15 min with ES 09-16, it returns no results
          You probably want to be Crossover testing for 1 bar not 0 bars back.
          Code:
          // Set 1
          if ((CrossAbove(RSI1.Default, 10, [COLOR="Red"][B]1[/B][/COLOR]))
          && (MACD1.Diff[0] > 0))
          {
          EnterLong(10, "");
          }
          // Set 2
          if (CrossAbove(RSI1.Default, 80, [COLOR="red"][B]1[/B][/COLOR]))
          {
          ExitLong(10, "", "");
          }
          .

          Comment


            #6
            Hello sashe71,

            koganam has spotted the case here:
            Originally posted by koganam View Post
            You probably want to be Crossover testing for 1 bar not 0 bars back.
            Code:
            // Set 1
            if ((CrossAbove(RSI1.Default, 10, [COLOR="Red"][B]1[/B][/COLOR]))
            && (MACD1.Diff[0] > 0))
            {
            EnterLong(10, "");
            }
            // Set 2
            if (CrossAbove(RSI1.Default, 80, [COLOR="red"][B]1[/B][/COLOR]))
            {
            ExitLong(10, "", "");
            }
            .
            The lookBackPeriod needs at least 1 in order to look for any cross to occur. We need to look back at the previous bar or further back (more than 1) in order to find the prior price level and compare that to the current in order to confirm the cross condition is true.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            649 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            576 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X