• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 williamzz, Today, 11:37 AM
            1 response
            7 views
            0 likes
            Last Post Emma1
            by Emma1
             
            Started by thecashguys, Today, 10:18 AM
            0 responses
            6 views
            0 likes
            Last Post thecashguys  
            Started by pjsmith, Today, 09:58 AM
            0 responses
            9 views
            0 likes
            Last Post pjsmith
            by pjsmith
             
            Started by bebbus, Today, 09:13 AM
            0 responses
            6 views
            0 likes
            Last Post bebbus
            by bebbus
             
            Started by roblogic, Today, 08:04 AM
            0 responses
            7 views
            0 likes
            Last Post roblogic  
            Working...
            X