Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

help

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

    help

    Hello everyone, I took this piece of code from the nt8 Camarilla Pivot script, maybe someone in the community could give me a helping hand to be able to say +1% or -1% from the prior close, or if this is not the right approach, guide me in the right direction, even if it is only one line it would already be a start for me to move forward, to tell you the truth I have no idea how to do that ,and I have no money to pay a guy to make it for me ,I try some random stuff but my platform crash ansd I end up reinstalling it several times,when I copy the code and change the indicator name to work on it crashes also thank you for any help

    s1 = currentClose - (currentHigh - currentLow) * 1.1 / 12;
    r1 = currentClose + (currentHigh - currentLow) * 1.1 / 12;
    s2 = currentClose - (currentHigh - currentLow) * 1.1 / 6;
    r2 = currentClose + (currentHigh - currentLow) * 1.1 / 6;
    s3 = currentClose - (currentHigh - currentLow) * 1.1 / 4;
    r3 = currentClose + (currentHigh - currentLow) * 1.1 / 4;
    s4 = currentClose - (currentHigh - currentLow) * 1.1 / 2;
    r4 = currentClose + (currentHigh - currentLow) * 1.1 / 2;

    something like that
    s1 = currentClose - 1*Percent
    r1 = currentClose + 1*Percent
    s2 = currentClose - 2*Percent
    r2 = currentClose + 2*Percent
    s3 = currentClose - 3*Percent
    r3 = currentClose + 3*Percent
    s4 = currentClose - 4*Percent
    r4 = currentClose + 4*Percent

    the code begin is
    AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.PivotsR1);
    AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.PivotsR2);
    AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.PivotsR3);
    AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.PivotsR4);
    AddPlot(Brushes.Crimson, NinjaTrader.Custom.Resource.PivotsS1);
    AddPlot(Brushes.Crimson, NinjaTrader.Custom.Resource.PivotsS2);
    AddPlot(Brushes.Crimson, NinjaTrader.Custom.Resource.PivotsS3);
    AddPlot(Brushes.Crimson, NinjaTrader.Custom.Resource.PivotsS4);
    }
    else if (State == State.Configure)
    {
    if (priorDayHlc == HLCCalculationMode.DailyBars)
    AddDataSeries(BarsPeriodType.Day, 1);
    }
    else if (State == State.DataLoaded)
    {
    storedSession = new SessionIterator(Bars);
    }
    else if (State == State.Historical)
    {
    if (priorDayHlc == HLCCalculationMode.DailyBars && BarsArray[1].DayCount <= 0)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PiviotsDailyDataError, TextPosition.BottomRight);
    Log(NinjaTrader.Custom.Resource.PiviotsDailyDataEr ror, LogLevel.Error);
    return;
    }

    if (!Bars.BarsType.IsIntraday && BarsPeriod.BarsPeriodType != BarsPeriodType.Day && (BarsPeriod.BarsPeriodType != BarsPeriodType.HeikenAshi && BarsPeriod.BarsPeriodType != BarsPeriodType.PriceOnVolume && BarsPeriod.BarsPeriodType != BarsPeriodType.Volumetric || BarsPeriod.BaseBarsPeriodType != BarsPeriodType.Day))
    {
    Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PiviotsDailyBarsError, TextPosition.BottomRight);
    Log(NinjaTrader.Custom.Resource.PiviotsDailyBarsEr ror, LogLevel.Error);
    }
    if ((BarsPeriod.BarsPeriodType == BarsPeriodType.Day || ((BarsPeriod.BarsPeriodType == BarsPeriodType.HeikenAshi || BarsPeriod.BarsPeriodType == BarsPeriodType.PriceOnVolume || BarsPeriod.BarsPeriodType == BarsPeriodType.Volumetric) && BarsPeriod.BaseBarsPeriodType == BarsPeriodType.Day)) && pivotRangeType == PivotRange.Daily)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PiviotsWeeklyBarsError , TextPosition.BottomRight);
    Log(NinjaTrader.Custom.Resource.PiviotsWeeklyBarsE rror, LogLevel.Error);
    }
    if ((BarsPeriod.BarsPeriodType == BarsPeriodType.Day || ((BarsPeriod.BarsPeriodType == BarsPeriodType.HeikenAshi || BarsPeriod.BarsPeriodType == BarsPeriodType.PriceOnVolume || BarsPeriod.BarsPeriodType == BarsPeriodType.Volumetric) && BarsPeriod.BaseBarsPeriodType == BarsPeriodType.Day)) && BarsPeriod.Value > 1)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PiviotsPeriodTypeError , TextPosition.BottomRight);
    Log(NinjaTrader.Custom.Resource.PiviotsPeriodTypeE rror, LogLevel.Error);
    }
    if ((priorDayHlc == HLCCalculationMode.DailyBars &&
    (pivotRangeType == PivotRange.Monthly && BarsArray[1].GetTime(0).Date >= BarsArray[1].GetTime(BarsArray[1].Count - 1).Date.AddMonths(-1)
    || pivotRangeType == PivotRange.Weekly && BarsArray[1].GetTime(0).Date >= BarsArray[1].GetTime(BarsArray[1].Count - 1).Date.AddDays(-7)
    || pivotRangeType == PivotRange.Daily && BarsArray[1].GetTime(0).Date >= BarsArray[1].GetTime(BarsArray[1].Count - 1).Date.AddDays(-1)))
    || pivotRangeType == PivotRange.Monthly && BarsArray[0].GetTime(0).Date >= BarsArray[0].GetTime(BarsArray[0].Count - 1).Date.AddMonths(-1)
    || pivotRangeType == PivotRange.Weekly && BarsArray[0].GetTime(0).Date >= BarsArray[0].GetTime(BarsArray[0].Count - 1).Date.AddDays(-7)
    || pivotRangeType == PivotRange.Daily && BarsArray[0].GetTime(0).Date >= BarsArray[0].GetTime(BarsArray[0].Count - 1).Date.AddDays(-1)
    )
    {
    Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PiviotsInsufficentData Error, TextPosition.BottomRight);
    Log(NinjaTrader.Custom.Resource.PiviotsInsufficent DataError, LogLevel.Error);
    }
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if ((priorDayHlc == HLCCalculationMode.DailyBars && BarsArray[1].DayCount <= 0)
    || (!Bars.BarsType.IsIntraday && BarsPeriod.BarsPeriodType != BarsPeriodType.Day && (BarsPeriod.BarsPeriodType != BarsPeriodType.HeikenAshi && BarsPeriod.BarsPeriodType != BarsPeriodType.PriceOnVolume && BarsPeriod.BarsPeriodType != BarsPeriodType.Volumetric || BarsPeriod.BaseBarsPeriodType != BarsPeriodType.Day))
    || ((BarsPeriod.BarsPeriodType == BarsPeriodType.Day || ((BarsPeriod.BarsPeriodType == BarsPeriodType.HeikenAshi || BarsPeriod.BarsPeriodType == BarsPeriodType.PriceOnVolume || BarsPeriod.BarsPeriodType == BarsPeriodType.Volumetric) && BarsPeriod.BaseBarsPeriodType == BarsPeriodType.Day)) && pivotRangeType == PivotRange.Daily)
    || ((BarsPeriod.BarsPeriodType == BarsPeriodType.Day || ((BarsPeriod.BarsPeriodType == BarsPeriodType.HeikenAshi || BarsPeriod.BarsPeriodType == BarsPeriodType.PriceOnVolume || BarsPeriod.BarsPeriodType == BarsPeriodType.Volumetric) && BarsPeriod.BaseBarsPeriodType == BarsPeriodType.Day)) && BarsPeriod.Value > 1)
    || ((priorDayHlc == HLCCalculationMode.DailyBars && (pivotRangeType == PivotRange.Monthly && BarsArray[1].GetTime(0).Date >= BarsArray[1].GetTime(BarsArray[1].Count - 1).Date.AddMonths(-1)
    || pivotRangeType == PivotRange.Weekly && BarsArray[1].GetTime(0).Date >= BarsArray[1].GetTime(BarsArray[1].Count - 1).Date.AddDays(-7)
    || pivotRangeType == PivotRange.Daily && BarsArray[1].GetTime(0).Date >= BarsArray[1].GetTime(BarsArray[1].Count - 1).Date.AddDays(-1)))
    || pivotRangeType == PivotRange.Monthly && BarsArray[0].GetTime(0).Date >= BarsArray[0].GetTime(BarsArray[0].Count - 1).Date.AddMonths(-1)
    || pivotRangeType == PivotRange.Weekly && BarsArray[0].GetTime(0).Date >= BarsArray[0].GetTime(BarsArray[0].Count - 1).Date.AddDays(-7)
    || pivotRangeType == PivotRange.Daily && BarsArray[0].GetTime(0).Date >= BarsArray[0].GetTime(BarsArray[0].Count - 1).Date.AddDays(-1)))
    return;

    RemoveDrawObject("NinjaScriptInfo");

    if (PriorDayHlc == HLCCalculationMode.DailyBars && CurrentBars[1] >= 0)
    {
    // Get daily bars like this to avoid situation where primary series moves to next session before previous day OHLC are added
    if (cacheTime != Times[0][0])
    {
    cacheTime = Times[0][0];
    cacheBar = BarsArray[1].GetBar(Times[0][0]);
    }
    dailyBarHigh = BarsArray[1].GetHigh(cacheBar);
    dailyBarLow = BarsArray[1].GetLow(cacheBar);
    dailyBarClose = BarsArray[1].GetClose(cacheBar);
    }
    else
    {
    dailyBarHigh = double.MinValue;
    dailyBarLow = double.MinValue;
    dailyBarClose = double.MinValue;
    }

    double high = (dailyBarHigh == double.MinValue) ? Highs[0][0] : dailyBarHigh;
    double low = (dailyBarLow == double.MinValue) ? Lows[0][0] : dailyBarLow;
    double close = (dailyBarClose == double.MinValue) ? Closes[0][0] : dailyBarClose;

    DateTime lastBarTimeStamp = GetLastBarSessionDate(Times[0][0], pivotRangeType);

    if ((currentDate != Globals.MinDate && pivotRangeType == PivotRange.Daily && lastBarTimeStamp != currentDate)
    || (currentWeek != Globals.MinDate && pivotRangeType == PivotRange.Weekly && lastBarTimeStamp != currentWeek)
    || (currentMonth != Globals.MinDate && pivotRangeType == PivotRange.Monthly && lastBarTimeStamp != currentMonth))
    {
    s1 = currentClose - (currentHigh - currentLow) * 1.1 / 12;
    r1 = currentClose + (currentHigh - currentLow) * 1.1 / 12;
    s2 = currentClose - (currentHigh - currentLow) * 1.1 / 6;
    r2 = currentClose + (currentHigh - currentLow) * 1.1 / 6;
    s3 = currentClose - (currentHigh - currentLow) * 1.1 / 4;
    r3 = currentClose + (currentHigh - currentLow) * 1.1 / 4;
    s4 = currentClose - (currentHigh - currentLow) * 1.1 / 2;
    r4 = currentClose + (currentHigh - currentLow) * 1.1 / 2;
    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);
    }



    Attached Files

    #2
    Hello janio,

    Thank you for your post.

    Please note it is not within our support model to create, debug, or modify, code or logic for our clients. That said we can provide assistance if you decide to code this yourself.

    I am not clear on what you mean by "to say +1% or -1% from the prior close". What value are you trying to calculate that is 1% from the prior close?

    Comment


      #3
      Hello NinjaTrader_Gaby​ I am looking for tthe distance from the prior close,the percentage distance when you use the ruler

      Comment


        #4
        Click image for larger version  Name:	Desktop Screenshot 2025.04.08 - 17.04.00.46.png Views:	0 Size:	87.9 KB ID:	1340019 the red line is the prior day close,and I am looking to plot levels at 1% intervals from it above and below
        If you know what indicator can do that work?
        Last edited by janio973; 04-08-2025, 02:23 PM.

        Comment


          #5
          I have something similar, however, with current volatility you probably want 9 levels. lol.. It may have some bugs...
          PHP Code:
          #region Using declarations
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion
          
          namespace NinjaTrader.NinjaScript.Indicators
          {
              public class CamarillaPriorCloseLevels : Indicator
              {
                  private double PriorClose;
                  private double S4, S3, S2, S1, Pivot, R1, R2, R3, R4;
          
                  [NinjaScriptProperty]
                  [Display(Name = "Percentage Level", Order = 1, GroupName = "Parameters")]
                  public double PercentageLevel { get; set; } = 1.0; // Default is 1.0%
          
                  [NinjaScriptProperty]
                  [Display(Name = "Time Frame (minutes)", Order = 2, GroupName = "Parameters")]
                  public int TimeFrame { get; set; } = 5; // Default is 5-minute timeframe
          
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description = "Plots Camarilla pivot levels based on prior close plus and minus percentage levels.";
                          Name = "CamarillaPriorCloseLevels";
                          Calculate = Calculate.OnEachTick;
                          IsOverlay = true;
          
                          AddPlot(Brushes.OrangeRed, "S4");
                          AddPlot(Brushes.Orange, "S3");
                          AddPlot(Brushes.Yellow, "S2");
                          AddPlot(Brushes.Green, "S1");
                          AddPlot(Brushes.Blue, "Pivot");
                          AddPlot(Brushes.LightGreen, "R1");
                          AddPlot(Brushes.Lime, "R2");
                          AddPlot(Brushes.YellowGreen, "R3");
                          AddPlot(Brushes.OrangeRed, "R4");
                      }
                      else if (State == State.Configure)
                      {
                          // Add secondary data series based on the user-selected timeframe
                          AddDataSeries(Data.BarsPeriodType.Minute, TimeFrame);
                      }
                      else if (State == State.DataLoaded)
                      {
                          // Verify that we have the secondary series
                          if (BarsArray.Length <= 1)
                          {
                              Print("Error: Secondary data series not available.");
                              return;
                          }
                      }
                  }
          
                  protected override void OnBarUpdate()
                  {
                      // Ensure we have enough bars in both series
                      if (CurrentBars[0] < 2 || CurrentBars[1] < 2)
                          return;
          
                      if (BarsInProgress == 1)
                      {
                          // Secondary series calculations
                          if (Bars.IsFirstBarOfSession)
                          {
                              // Get prior close at the start of a new session
                              PriorClose = Close[1];
                              Print($"New session started, initializing Prior Close: {PriorClose}");
                          }
          
                          // Calculate the percentage value
                          double percentValue = PriorClose * (PercentageLevel / 100.0);
                          
                          // Calculate Camarilla levels based on prior close +/- percentage
                          Pivot = PriorClose;
                          
                          // Calculate 4 levels above and below based on fractions of the percentage
                          R1 = PriorClose + (percentValue * 0.25);
                          R2 = PriorClose + (percentValue * 0.50);
                          R3 = PriorClose + (percentValue * 0.75);
                          R4 = PriorClose + percentValue;
                          
                          S1 = PriorClose - (percentValue * 0.25);
                          S2 = PriorClose - (percentValue * 0.50);
                          S3 = PriorClose - (percentValue * 0.75);
                          S4 = PriorClose - percentValue;
          
                          Print($"Calculated levels based on Prior Close: {PriorClose}, Percentage: {PercentageLevel}%");
                      }
                      else if (BarsInProgress == 0)
                      {
                          // Primary series - plot the values
                          Values[0][0] = S4;
                          Values[1][0] = S3;
                          Values[2][0] = S2;
                          Values[3][0] = S1;
                          Values[4][0] = Pivot;
                          Values[5][0] = R1;
                          Values[6][0] = R2;
                          Values[7][0] = R3;
                          Values[8][0] = R4;
                      }
                  }
              }
          }&#8203;
          
          &#8203; 
          
          Last edited by MiCe1999; 04-08-2025, 05:20 PM.

          Comment


            #6
            MiCe1999​ thanks for your help bro god bless you Im going to test right now

            Comment


              #7
              The indicator works very well,I begin backtest thanks again for your time put into this MiCe1999
              I wanted to put this on builder but I cant choose just one pivot per example cross above R1 enter long because all plots is appearing,need i do something to only choose one?
              Click image for larger version  Name:	Desktop Screenshot 2025.04.08 - 21.53.03.84.png Views:	0 Size:	165.8 KB ID:	1340038
              Last edited by janio973; 04-09-2025, 04:54 AM.

              Comment


                #8
                Originally posted by janio973 View Post
                The indicator works very well,I begin backtest thanks again for your time put into this MiCe1999
                I wanted to put this on builder but I cant choose just one pivot per example cross above R1 enter long because all plots is appearing,need i do something to only choose one?
                Click image for larger version Name:	Desktop Screenshot 2025.04.08 - 21.53.03.84.png Views:	0 Size:	165.8 KB ID:	1340038
                Ask support/forum. I have never used a strategy builder. Maybe setting all other plots to transparent will do the trick.
                Last edited by MiCe1999; 04-09-2025, 05:16 AM.

                Comment


                  #9
                  I have made some adjustements with your code and it looks better with the current volatility,look that beauty MiCe1999Click image for larger version

Name:	Desktop Screenshot 2025.04.09 - 08.16.51.35.png
Views:	108
Size:	102.6 KB
ID:	1340059 ,i have now just to find a way to use/set this on strategy builder NinjaTrader_Gaby

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  559 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  324 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  546 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  547 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X