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

General Trend Indicator (Don't Working)

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

    General Trend Indicator (Don't Working)

    Hi, we 're creating an indicator to detect the general trend of the instrument in which we work from the typical indicator SuperTrend , so far we think we are doing well as we work with orders MultiTimeFrame as you can see in the code that I had but when we the indicator on the chart not work properly, I have attached pictures so you can see where it fails .

    Supposedly this indicator if we have a 5 minute chart i chose to tell us the general trend of 15 min we would have to dial 1 or -1 depending on whether the 15-minute chart the trend is bullish or bearish.

    I hope you can help me. Thank you very much in advance .



    public class SuperTrendFractal : Indicator
    {
    #region Variables
    // Wizard generated variables
    private double multiplicador = 2.500; // Default setting for Multiplicador
    private int longuitud = 14; // Default setting for Longuitud
    private int timeframe = 5; // Default setting for TimeFrame
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {

    Add(PeriodType.Minute, timeframe);
    Add(new Plot(Color.Green, PlotStyle.Line, "TradingLine"));
    Overlay = false;
    CalculateOnBarClose = true;
    }


    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    { // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    // Condition set 1
    /*if (SuperTrend(longuitud, multiplicador, true).UpTrend.Get(0) == SuperTrend(longuitud, multiplicador, true).DownTrend.Get(0) )
    {//Comprova que hi ha un tall
    */
    if (BarsInProgress == 1){
    if (Closes[1][0] > SuperTrend(BarsArray[1],longuitud, multiplicador, true).UpTrend[0])
    {
    TradingLine.Set(1);
    }
    if (Closes[1][0] < SuperTrend(BarsArray[1],longuitud, multiplicador, true).DownTrend[0])
    {
    TradingLine.Set(-1);
    }

    }
    }
    Attached Files
    Last edited by fisagol; 07-20-2015, 04:19 AM.

    #2
    Hello fisagol,

    Are there any error messages appearing in the Log tab of the Control Center?

    If so, what do these say?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      General Trend Indicator(Don't Working)

      Hello NinjaTrader_ChelseaB,

      Yes I just saw that gives an error message in the logs i just fails in method Initialize () . Deputy screenshot ! Thank you for the answer to see if I can finish among people taking the forum.
      Attached Files
      Last edited by fisagol; 07-20-2015, 10:20 AM.

      Comment


        #4
        Anyway the problem indicated in the logs think that has nothing to do with the flag that I'm showing here , I think they are other indicators that previously did but leave them in half and obviously not going well, the problem with this indicator in which I am working esque if the graph above has a time frame of 15 minutes and the indicator you put 15 14 13 12 .... min captures perfectly the trend, but its main function is not that , but is that the graphic chosen this to 5 min and the indicator shows the trend of 15 min .

        Comment


          #5
          Hello fisagol,

          Just to confirm, when you add this indicator to a 5 minute chart, no error message appears in the Log tab of the Control Center, is this correct?

          Add a print that prints the value of the SuperTrend() indicator on every bar.
          What values are printing in the Output Window?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Yes I'm confirm. If I do it , I dont have errors, but the problem is that the indicator doesn't do it objective. The most important mistake are that the multi-timeframe don't works good. I need a solution to use my indicator, for example it would be good to have time-frame fixed in some indicator.
            Last edited by fisagol; 07-20-2015, 03:04 PM.

            Comment


              #7
              Hello fisagol,

              I have created an example test strategy to demonstrate that using a secondary series does work and does not cause issues.

              This example allows the user to set the period used for a secondary series. The orders are placed during BarsInProgress 1 and are placed to the secondary series.
              Attached Files
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thank you for code NinjaTrader_ChelseaB but now your code not work when I compile this code. The error that make are here but I don't know to solution.

                Click image for larger version

Name:	error.jpg
Views:	1
Size:	327.4 KB
ID:	874064

                I don't know this error it will be for the version of ninja
                Last edited by fisagol; 07-21-2015, 08:59 AM.

                Comment


                  #9
                  Hello fisagol,

                  The strategy I have provided you does not have errors.

                  The errors are coming from the file you are trying to compile that is name MyCustomStrategy.

                  You need to fix this first, and then import my script from the Tools -> Import -> NinjaScript.. menu.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Yes but when I import your .zip, this is the error that appears
                    Click image for larger version

Name:	errrrrrr.jpg
Views:	1
Size:	74.5 KB
ID:	874065
                    For this reason I say that maybe fail version of ninja that isn't compatible? I don't know why

                    Comment


                      #11
                      Hi fisagol,

                      That was my mistake.

                      I created this for NinjaTrader 8 beta and gave directions for importing into NinjaTrader 8.

                      Here is the script created as an indicator for NinjaTrader 7.

                      This will plot the value of the SMA using the secondary series.
                      Attached Files
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Now import correctly. ThankYou for exemple. Now I work for this example and I'll try to make an strategy with this and my conceptual indicator. I hope that work

                        Comment


                          #13
                          I put my code because that work but the same problem persist, now is more wrong because with this code not works any thing jaja

                          I'm only call supertrend, and if that condition is true if (Close[1][0] < SuperTrend(BarsArray[1],longuitud, multiplicador, true).DownTrend[0]) of secondary timeframe draw a line an another panel with nombre -1 and this condition are false draw 1

                          namespace NinjaTrader.Indicator
                          {
                          /// <summary>
                          /// This indicator uses a secondary timeframe for a call to the SMA
                          /// </summary>
                          [Description("This indicator uses a secondary timeframe for a call to the SMA")]
                          public class MultiTimeFrameIndicatorExample : Indicator
                          {
                          #region Variables
                          // Wizard generated variables
                          private int secondaryPeriod = 5; // Default setting for SecondaryPeriod
                          private double multiplicador = 2.500; // Default setting for Multiplicador
                          private int longuitud = 14; // Default setting for Longuitud
                          // User defined variables (add any user defined variables below)
                          #endregion

                          /// <summary>
                          /// This method is used to configure the indicator and is called once before any bar data is loaded.
                          /// </summary>
                          protected override void Initialize()
                          {
                          Add(PeriodType.Minute, secondaryPeriod);
                          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "CalculatedValues"));
                          Overlay = false;
                          }

                          /// <summary>
                          /// Called on each bar update event (incoming tick)
                          /// </summary>
                          protected override void OnBarUpdate()
                          {
                          // if the plot is not set on every primary bar, then it will not appear on the chart since the plot is synced to the primary series.
                          // ensure there are enough bars of the secondary series so there is not an error
                          //if (CurrentBars[1] > 13)
                          //CalculatedValues.Set(SMA(BarsArray[1], 14)[0]);
                          if (Close[1][0] > SuperTrend(BarsArray[1],longuitud, multiplicador, true).UpTrend[0])
                          {
                          CalculatedValues.Set(1);
                          }
                          if (Close[1][0] < SuperTrend(BarsArray[1],longuitud, multiplicador, true).DownTrend[0])
                          {
                          CalculatedValues.Set(-1);
                          }
                          // print the time and close price of every secondary bar to show this works.
                          if (BarsInProgress == 1)
                          Print(Times[0][1]+" - Close[0]: "+Close[0]);
                          }

                          #region Properties
                          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                          public DataSeries CalculatedValues
                          {
                          get { return Values[0]; }
                          }

                          [Description("")]
                          [GridCategory("Parameters")]
                          public int SecondaryPeriod
                          {
                          get { return secondaryPeriod; }
                          set { secondaryPeriod = Math.Max(1, value); }
                          }
                          [Description("")]
                          [GridCategory("Parameters")]
                          public double Multiplicador
                          {
                          get { return multiplicador; }
                          set { multiplicador = Math.Max(1, value); }
                          }

                          [Description("")]
                          [GridCategory("Parameters")]
                          public int Longuitud
                          {
                          get { return longuitud; }
                          set { longuitud = Math.Max(1, value); }
                          }
                          #endregion
                          }
                          }
                          Last edited by fisagol; 07-21-2015, 10:55 AM.

                          Comment


                            #14
                            Hello fisagol,

                            Are you certain this plot is being set on every bar?

                            It seems it plots when there is a downtrend or an uptrend. What if there is neither?

                            Is this a histogram or a line plot?

                            A histogram would not require that every plot be set.

                            If you print the value that you have set on every bar, does every bar have a -1 or 1?

                            if (Close[1][0] > SuperTrend(BarsArray[1],longuitud, multiplicador, true).UpTrend[0])
                            {
                            CalculatedValues.Set(1);
                            }
                            if (Close[1][0] < SuperTrend(BarsArray[1],longuitud, multiplicador, true).DownTrend[0])
                            {
                            CalculatedValues.Set(-1);
                            }

                            Print(CalculatedValues[0]);
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Is only a line plot i think, I don't make a histogram because in the future if I make a strategy with this indicator histogram is more difficult than sample line plot.

                              In all bars checks this 2 conditions
                              Last edited by fisagol; 07-21-2015, 11:19 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rhyminkevin, Today, 04:58 PM
                              3 responses
                              48 views
                              0 likes
                              Last Post Anfedport  
                              Started by iceman2018, Today, 05:07 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post iceman2018  
                              Started by lightsun47, Today, 03:51 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post lightsun47  
                              Started by 00nevest, Today, 02:27 PM
                              1 response
                              14 views
                              0 likes
                              Last Post 00nevest  
                              Started by futtrader, 04-21-2024, 01:50 AM
                              4 responses
                              50 views
                              0 likes
                              Last Post futtrader  
                              Working...
                              X