Advertisement
Guest User

Untitled

a guest
Jul 16th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. namespace NinjaTrader.NinjaScript.Indicators
  2. {
  3.     public class Diff : Indicator
  4.     {  
  5.         private PriorDayOHLC PriorDayOHLC1;
  6.         private PriorDayOHLC PriorDayOHLC2;
  7.        
  8.         protected override void OnStateChange()
  9.         {
  10.             if (State == State.SetDefaults)
  11.             {
  12.                 Description                                 = @"Enter the description for your new custom Indicator here.";
  13.                 Name                                        = "Diff";
  14.                 Calculate                                   = Calculate.OnBarClose;
  15.                 IsOverlay                                   = false;
  16.                 DisplayInDataBox                            = true;
  17.                 DrawOnPricePanel                            = true;
  18.                 DrawHorizontalGridLines                     = true;
  19.                 DrawVerticalGridLines                       = true;
  20.                 PaintPriceMarkers                           = true;
  21.                 ScaleJustification                          = NinjaTrader.Gui.Chart.ScaleJustification.Right;
  22.                 //Disable this property if your indicator requires custom values that cumulate with each new market data event.
  23.                 //See Help Guide for additional information.
  24.                 IsSuspendedWhileInactive                    = true;
  25.                 AddPlot(Brushes.White, "Diff");
  26.             }
  27.             else if (State == State.Configure)
  28.             {
  29.             }
  30.         }
  31.  
  32.         protected override void OnBarUpdate()
  33.         {          
  34.             if (CurrentBars[0] <= 55)  
  35.                 return;
  36.            
  37.             if (BarsInProgress != 0)
  38.                 return;
  39.  
  40.            
  41.             if (PriorDayOHLC1.PriorHigh[1] - PriorDayOHLC2.PriorOpen[1] == 0) // check for potential divide by zero
  42.                 {
  43.                     return; // don't plot the value
  44.                 }
  45.                
  46.             double PDHigh = PriorDayOHLC1.PriorHigh[1];            
  47.             double PDOpen = PriorDayOHLC2.PriorOpen[1];
  48.  
  49.            
  50.             Value[0] = PDHigh - PDOpen;
  51.                
  52.                
  53.         }
  54.        
  55.         #region Properties
  56.  
  57.         [Browsable(false)]
  58.         [XmlIgnore]
  59.         public Series<double> Diff
  60.         {
  61.             get { return Values[0]; }
  62.         }
  63.  
  64.         #endregion
  65.     }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement