Posted to TSL 7-23-19
11:45 jeffrey2360: Would be great to be able to grab live greeks in a study the same way we get price. HIstorical data is not that important, but having live ratio is very useful (delta/theta)
11:46 Mobius:
	
	
	
	
	
		
11:47 Mobius: That is pretty bloody close
11:47 Mobius: usually within a penny
11:48 jeffrey2360: Oh. I got to study that code. Will it be possible to apply this to 4 options in a single study ?
11:50 Mobius: sure. You'll need to run 4 instances of the study, change the ones for puts from the above which is for calls and alter the other strikes.
11:52 Mobius: And it would help to have a degree in mathematics and coding but you can probably do it. Maybe
	
		
			
		
		
	
				
			11:45 jeffrey2360: Would be great to be able to grab live greeks in a study the same way we get price. HIstorical data is not that important, but having live ratio is very useful (delta/theta)
11:46 Mobius:
		Code:
	
	# Delta Calculation
# For Options with 1 dollar strikes
# Mobius
# V01.07.2019
input DayToExpiry = 2; #hint: Don't mess with this.
input Series_IV = 1;
def IV = SeriesVolatility(series = Series_IV);
def K = Floor(close);
def S = close;
def R = GetInterestRate();
def t = DayToExpiry / 365;
def d1 = (log(S / K) + ((R + (sqr(IV) / 2)) * t)) / (IV * sqrt(t));
script cnd
     {
      input data  = 1;
      def a = AbsValue(data);
      def b1 =  .31938153;
      def b2 = -.356563782;
      def b3 = 1.781477937;
      def b4 = -1.821255978;
      def b5 = 1.330274429;
      def b6 =  .2316419;
      def e = 1 / (1 + b6 * a);
      def i = 1 - 1 / Sqrt(2 * Double.Pi) * Exp(-Power(a, 2) / 2) *
            (b1 * e + b2 * e * e + b3 * Power(e, 3) + b4 * Power(e, 4) + b5 * Power(e, 5));
      plot CND = if data < 0
                then 1 - i
                else i;
     }
def Delta = cnd(d1);
AddLabel(1, "Delta Est = " + Delta, color.white);
# End Code Delta Estimate
	11:47 Mobius: That is pretty bloody close
11:47 Mobius: usually within a penny
11:48 jeffrey2360: Oh. I got to study that code. Will it be possible to apply this to 4 options in a single study ?
11:50 Mobius: sure. You'll need to run 4 instances of the study, change the ones for puts from the above which is for calls and alter the other strikes.
11:52 Mobius: And it would help to have a degree in mathematics and coding but you can probably do it. Maybe
			
				Last edited: