Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

System trades too much

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

    System trades too much

    I am trying to code a simple breakout Strat to try and get familiar with ninja scripting, I managed to cut and paste enough code together to make what I want, but I cant seem to get the system to only trade between the start time and endtime for my breakouts. Any help would be appreciated.

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class Test : Strategy
    {
    #region Variables
    // Wizard generated variables
    private double currentDay;
    private double currentOpenRangeHigh;
    private double currentOpenRangeLow;
    private int longTrade;
    private int shortTrade;
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    SetProfitTarget("", CalculationMode.Ticks, 6);
    SetStopLoss("", CalculationMode.Ticks, 6, true);


    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (ToDay(Time[0]) != currentDay)
    {
    currentDay = ToDay(Time[0]);
    currentOpenRangeHigh = 0;
    currentOpenRangeLow = 100000;
    longTrade = 0;
    shortTrade = 0;

    }
    // Condition set 1
    if (ToTime(Time[0]) >= ToTime(9,00, 0)
    && ToTime(Time[0]) <= ToTime(10, 00, 0))
    {
    if (High[0] > currentOpenRangeHigh)
    {
    currentOpenRangeHigh = High[0];
    }
    if (Low[0] < currentOpenRangeLow)
    {
    currentOpenRangeLow = Low[0];
    }
    }



    // Condition set 3
    if (ToTime(Time[0]) > ToTime(7, 20, 0) && ToTime(Time[0]) < ToTime(9, 30, 0))
    {
    if (Close[0] > currentOpenRangeHigh && longTrade <1)
    {
    EnterLong(DefaultQuantity, "");

    }

    // Condition set 4
    }
    if (Close[0] < currentOpenRangeLow && shortTrade < 1)
    {
    EnterShort(DefaultQuantity, "");
    }
    }

    #2
    Hi Net_Trader,

    Thank you for posting and welcome to the forums!

    Thank you for your code.

    Based off that, I would suggest that you try using the HHMMSS format instead of the ToTime();

    Example:
    Code:
    if (ToTime(Time[0]) >= 090000
    && ToTime(Time[0]) <= 100000)
    While you can continue to use the ToTime() you will need to put the full second amount.
    Right now what you have will return this -
    * ToTime(9,00,0) = 9000
    Which the system doesn't recognize as a real time structure.

    ToTime(9,00,00) = 90000 will return 9:00 AM

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your Prompt reply Cal,

      I did make those changes and re-compiled with the same exact results. After the breakout it should not reset and gear up for another breakout, that one break is it for the day whether the trade is over or not.

      Thanks
      Net_Trader

      Comment


        #4
        Hi Net_Trader,

        Would you mind sharing your CS file so I can test out on my end?

        You can find the file in (My) Documents > NinjaTrader 7 > bin > custom > Strategy.

        To add an attachment to the post, Click Reply -> Go Advanced > Click the paperclip in the top toolbar to add an attachment.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          I have made some changes, been experimenting, it should not be too far off from what I posted.

          Thanks
          Net_trader
          Attached Files

          Comment


            #6
            I got it figured out from watching one of your webinars... Thanks
            Net_ trader

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rocketman7, Today, 02:12 AM
            7 responses
            31 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by guillembm, Yesterday, 11:25 AM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by junkone, 04-21-2024, 07:17 AM
            10 responses
            149 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by tsantospinto, 04-12-2024, 07:04 PM
            6 responses
            101 views
            0 likes
            Last Post tsantospinto  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            7 responses
            28 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X