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

Modify Pivot Indicator Code, minor changes required. Advice needed.

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

    Modify Pivot Indicator Code, minor changes required. Advice needed.

    Hi,

    I am new to Ninja Trader and would like to modify the standard pivot indicator to calculate as follows;

    Pivot Point = (High + Low + Close) / 3

    #1 high pivot (R1) = Pivot point + (Pivot Point - Low)
    #1 low pivot (S1) = Pivot Point - (High - Pivot Point)

    #2 high pivot (R2) = Pivot Point + 20 (Pivot Point - Low)
    #2 low pivot (S2) = Pivot Point - 20 (High - Pivot Point)

    #3 high pivot (R3) = High + 20 (Pivot Point - Low)
    #3 low pivot (S3) = Low - 20 (High - Pivot Point)

    Is it possible to cut and paste the standard pivot code provided by NT and change the lines of code as required...the reason I ask this is I tried to, to no avail.

    I would be using these on 10 minute charts based on the high, low and close of the previous session.

    Any advice on the matter would be great.
    Last edited by suprsnipes; 03-03-2009, 05:01 AM.

    #2
    Hi suprsnipes, welcome to the NinjaTrader support forums! Sure you can open the 'Pivots' code in your NinjaScript editor and modify the programming for PP, S1, S2, S3, R1, R2, and R3 as needed in your custom formula.

    For a good start, please check those coding tutorials - http://www.ninjatrader-support.com/H...verview18.html

    You can also review those pivot scripts from our sharing - http://www.ninjatrader-support2.com/...h=pivot&desc=1

    For professional custom coding, you can contact those NinjaScript consultants - http://www.ninjatrader.com/webnew/pa...injaScript.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Are these the lines of code I need to change in bold?

      I have marked the lines of code that I would like to edit, if they are the correct lines in the first place, can't see anything else in the code that is similar so I'm thinking yes??

      Plus I copied the standard NT 'Pivots' indicator code then changed the lines but then received an error message from NT as follows;

      Firstly when I go to save this as another name it says; 'Your indicator was saved as a new file. Please replace any instances of the old file name with the new file name within your NinjaScript code'. I'm not sure how to identify this and if I even have to??

      I then go to the indicators window to add and my new custom indicator is not showing.

      I thought that I may have to export the code and import it like you would any indicator you got from someone else but received this message, 'You have custom NinjaScript files on your PC that have programming errors. These errors must be resolved before you can export an NinjaScript Archive File.

      Thanks in advance,

      if (Bars == null)
      return;
      if (!Data.BarsType.GetInstance(Bars.Period.Id).IsIntr aday && Bars.Period.Id != PeriodType.Day)
      return;
      if (Bars.Period.Id == PeriodType.Day && pivotRangeType == PivotRange.Daily)
      return;
      if (Bars.Period.Id == PeriodType.Day && Bars.Period.Value > 1)
      return;

      // pivots only work for
      // - intraday
      // - 1 day chart with PivotRange Weekly or Monthly

      if (!isDailyDataLoaded && !isInitializing)
      {
      isInitializing = true;

      if (priorDayHLC == HLCCalculationMode.DailyBars && Data.BarsType.GetInstance(Bars.Period.Id).IsIntrad ay)
      {
      dailyBars = Data.Bars.GetBars(Bars.Instrument, new Period(PeriodType.Day, 1), Bars.From, Bars.To, (Session) Bars.Session.Clone(), Data.Bars.SplitAdjust, Data.Bars.DividendAdjust);
      existsHistDailyData = (dailyBars.Count <= 1) ? false : true;
      }
      else
      existsHistDailyData = false;

      isInitializing = false;
      isDailyDataLoaded = true;
      }

      IBar dailyBar;
      if (existsHistDailyData)
      {
      DateTime intradayBarTime = Time[0].AddSeconds(-1).Date;
      dailyBar = dailyBars.Get(dailyBars.GetBar(intradayBarTime));

      if (dailyBar.Time.Date > intradayBarTime.Date)
      {
      for (DateTime i = intradayBarTime; i >= dailyBars.Get(0).Time; i = i.AddDays(-1))
      {
      dailyBar = dailyBars.Get(dailyBars.GetBar(i));
      if (dailyBar.Time.Date == i.Date)
      break;
      }
      }
      }
      else
      dailyBar = null;

      double high = existsHistDailyData ? dailyBar.High : High[0];
      double low = existsHistDailyData ? dailyBar.Low : Low[0];
      double close = existsHistDailyData ? dailyBar.Close : Close[0];

      if ((currentDate != Cbi.Globals.MinDate && pivotRangeType == PivotRange.Daily && Time[0].AddSeconds(-1).Date != currentDate)
      || (currentWeek != Cbi.Globals.MinDate && pivotRangeType == PivotRange.Weekly && RoundUpTimeToPeriodTime(Time[0].AddSeconds(-1).Date, PivotRange.Weekly) != currentWeek)
      || (currentMonth != Cbi.Globals.MinDate && pivotRangeType == PivotRange.Monthly && RoundUpTimeToPeriodTime(Time[0].AddSeconds(-1).Date, PivotRange.Monthly) != currentMonth))
      {
      pp = (currentHigh + currentLow + currentClose) / 3;
      s1 = 2 * pp - currentHigh;
      r1 = 2 * pp - currentLow;
      s2 = pp - (currentHigh - currentLow);
      r2 = pp + (currentHigh - currentLow);
      s3 = pp - 2 * (currentHigh - currentLow);
      r3 = pp + 2 * (currentHigh - currentLow);

      currentClose = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedClose : close;
      currentHigh = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedHigh : high;
      currentLow = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedLow : low;
      }
      else
      {
      currentClose = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedClose : close;
      currentHigh = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedHigh : Math.Max(currentHigh, high);
      currentLow = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedLow : Math.Min(currentLow, low);
      }

      if (pivotRangeType == PivotRange.Daily)
      currentDate = Time[0].AddSeconds(-1).Date;
      if (pivotRangeType == PivotRange.Weekly)
      currentWeek = RoundUpTimeToPeriodTime(Time[0].AddSeconds(-1).Date, PivotRange.Weekly);
      if (pivotRangeType == PivotRange.Monthly)
      currentMonth = RoundUpTimeToPeriodTime(Time[0].AddSeconds(-1).Date, PivotRange.Monthly);

      if ((pivotRangeType == PivotRange.Daily && currentDate != Cbi.Globals.MinDate)
      || (pivotRangeType == PivotRange.Weekly && currentWeek != Cbi.Globals.MinDate)
      || (pivotRangeType == PivotRange.Monthly && currentMonth != Cbi.Globals.MinDate))
      {
      PP.Set(pp);
      R1.Set(r1);
      S1.Set(s1);
      R2.Set(r2);
      S2.Set(s2);
      R3.Set(r3);
      S3.Set(s3);

      Comment


        #4
        Yes, you need to edit the bold lines for your custom formulas to take effect. If it does not show up in the indicators list on the charts, it means there were compilation errors of your changes - just open the new indicator up, hit F5 and click on each error on the bottom. Then debug those step by step, if you need further tips to debug your code please check this link - http://www.ninjatrader-support2.com/...ead.php?t=4678
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TraderBCL, Today, 04:38 AM
        2 responses
        16 views
        0 likes
        Last Post TraderBCL  
        Started by martin70, 03-24-2023, 04:58 AM
        14 responses
        106 views
        0 likes
        Last Post martin70  
        Started by Radano, 06-10-2021, 01:40 AM
        19 responses
        609 views
        0 likes
        Last Post Radano
        by Radano
         
        Started by KenneGaray, Today, 03:48 AM
        0 responses
        5 views
        0 likes
        Last Post KenneGaray  
        Started by thanajo, 05-04-2021, 02:11 AM
        4 responses
        471 views
        0 likes
        Last Post tradingnasdaqprueba  
        Working...
        X