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

Help with simple strategy - break of previous daily close

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

    Help with simple strategy - break of previous daily close

    Hi all,

    I have a simple strategy that compiles successfully however it does not show entry and exits on my chart.

    The strategy goes long after the break of the previous close to the up side and exits at 4:55 pm.

    Any idea what could be causing this?

    Code is below:

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class BreakofClose : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "BreakofClose";
    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)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (CrossAbove(Close, Close, 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 2
    if (Times[0][0].TimeOfDay == new TimeSpan(16, 55, 0))
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
    }

    }
    }
    }

    #2
    Hello omermirza, thanks for writing in.

    Your entry condition is never getting reached: CrossAbove(Close, Close, 1)

    The CrossAbove method needs two distinct series because it checks for the following: Series1[0] > Series2[0] && Series1[1] < Series2[1]

    Consider checking the Close against a different series, like the High or Low series. E.g. to check if the Close went above the High of last bar:

    Code:
    if(CurrentBar < 1) return;
    
    if (Close[0] > High[1] && Position.MarketPosition == MarketPosition.Flat)
    {
    Print("Condition True");
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }
    When you get unexpected results like this, always use the Print method to print data from your script to see if the entry conditions are becoming true or not.

    Please let me know if any further questions come up.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello omermirza, thanks for writing in.

      Your entry condition is never getting reached: CrossAbove(Close, Close, 1)

      The CrossAbove method needs two distinct series because it checks for the following: Series1[0] > Series2[0] && Series1[1] < Series2[1]

      Consider checking the Close against a different series, like the High or Low series. E.g. to check if the Close went above the High of last bar:

      Code:
      if(CurrentBar < 1) return;
      
      if (Close[0] > High[1] && Position.MarketPosition == MarketPosition.Flat)
      {
      Print("Condition True");
      EnterLong(Convert.ToInt32(DefaultQuantity), "");
      }
      When you get unexpected results like this, always use the Print method to print data from your script to see if the entry conditions are becoming true or not.

      Please let me know if any further questions come up.
      HI Chris,

      There's no way to check if the current price crossed above the close of the previous bar?

      -Omer

      Comment


        #4
        Hello Omer, thanks for your reply.

        That would look like this:

        if(Close[0] > Close[1])
        { //... }

        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X