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

A problem with Swing indicator.

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

    A problem with Swing indicator.

    Hi, I am trying to develop a simple trading strategy using this indicator but I have some problems.

    This is the code of the system:

    #region Variables
    // Wizard generated variables
    privateint barrasPivot = 5; // Default setting for BarrasPivot
    // 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>
    protectedoverridevoid Initialize()
    {
    CalculateOnBarClose = true;
    }

    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    EnterLongStop(DefaultQuantity, Swing(BarrasPivot).SwingHigh[0], "");

    EnterShortStop(DefaultQuantity, Swing(BarrasPivot).SwingLow[0], "");
    }

    There are some occasions at which the system work correctly and there are others in which the system does not do any trade. In some occasions if I change the parameter "BarrasPivot" the system stops working though it has sufficient historical data. What I can do to solve this mistake?

    Thank you very much in advance.

    In the following file it is possible to find the code of the system:
    Attached Files
    Last edited by Davizito; 09-24-2009, 09:24 AM.

    #2
    Davizito,

    Please check your Control Center logs for errors. How are you determining it is not working? Remember the Swing indicator is actually an indicator that repaints itself meaning when it sees something in the future, it will go back and change its old values. Just because it has changed its old values does not mean you can now all of a sudden go back and say you have placed a trade there. This nature of the indicator is what makes it look so good.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh,

      Thanks a lot for your reply, I see that the strategy does not work because I see that in the backtest there are no trades. You can see a screenshot of my log (I was trying to do a backtest on Dax future from 1-1-2009 to 23-9-2009). In this occasion I am using a parameter BarrasPivot = 5. It is a very strange mistake, because if I change this parameter (for example) BarrasPivot=4 or BarrasPivot=6 the strategy works correctly.

      I can see in the log the next line:

      “Error on calling 'OnBarUpdate' method for strategy 'SwingHL': Stop price must not be 0”
      Attached Files

      Comment


        #4
        Suggest you print Swing(BarrasPivot).SwingHigh[0] and see what value it actually is.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi Josh

          I am using the next code:

          Print (Swing(BarrasPivot).SwingHigh[0]+ " SwingHigh " + DateTime.Now.ToString());
          Print (Swing(BarrasPivot).SwingLow[
          0]+ " SwingLow " + DateTime.Now.ToString());

          EnterLongStop(DefaultQuantity, Swing(BarrasPivot).SwingHigh[
          0], "");
          EnterShortStop(DefaultQuantity, Swing(BarrasPivot).SwingLow[
          0], "");

          ...and I can only see this in the output window:

          0 SwingHigh 24/09/2009 3:49:45
          0 SwingLow 24/09/2009 3:49:45


          I was trying to do a backtest from 1-1-2009 to 24-9-2009.

          Is it possible that there is some mistake in the Swing indicator?

          Thanks a lot for your help.

          Comment


            #6
            It could be easily zero at the start of your chart, so you would need to add a check to the entries only placing orders if the value is different from 0.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks a lot for your help Bertrand, the problem has been solved!
              Last edited by Davizito; 09-24-2009, 08:26 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ETFVoyageur, Today, 02:15 AM
              0 responses
              7 views
              0 likes
              Last Post ETFVoyageur  
              Started by Board game geek, Today, 01:34 AM
              0 responses
              5 views
              0 likes
              Last Post Board game geek  
              Started by morrnel, 05-12-2024, 06:07 PM
              3 responses
              40 views
              0 likes
              Last Post wzgy0920  
              Started by FishTrade, Yesterday, 11:11 PM
              0 responses
              7 views
              0 likes
              Last Post FishTrade  
              Started by Austiner87, Yesterday, 03:42 PM
              1 response
              22 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X