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

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 geddyisodin, Today, 05:20 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Max238, Today, 01:28 AM
            3 responses
            30 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by timko, Today, 06:45 AM
            2 responses
            12 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by habeebft, Today, 07:27 AM
            0 responses
            4 views
            0 likes
            Last Post habeebft  
            Started by Tim-c, Today, 03:54 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X