Create put/call ratio for individual stock?

YungTraderFromMontana

Well-known member
I'm interested on the connection between P/C ratio and price movement but to analyze it I would need a lower study that plots the P/C ratio. Nothing fancy, just all puts/all calls, I don't care about the strikes. It seems like it would be easy but I've never come across it. Does anyone know of an indicator like this or how to make one? I feel it would be a cool thing to backtest and maybe add to a strategy. If I could get this I'd be happy to create an indicator using it for the community.

Code:
declare lower;

input pcrAveragePeriod = 20;
input expirationDate = 20150418;
def atmC = volume(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL));
def itmC1 = volume(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)));
def itmC2 = volume(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))));
def itmC3 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)))));
def itmC4 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))))));
def itmC5 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)))))));
def itmC6 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))))))));
def itmC7 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)))))))));
def itmC8 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))))))))));
def itmC9 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)))))))))));
def itmC10 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))))))))))));
def otmC1 = volume(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)));
def otmC2 = volume(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))));
def otmC3 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)))));
def otmC4 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))))));
def otmC5 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)))))));
def otmC6 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))))))));
def otmC7 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)))))))));
def otmC8 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))))))))));
def otmC9 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)))))))))));
def otmC10 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))))))))))));
def atmCV = if !IsNaN(atmC) then atmC else 0;
def itmC1V = if !IsNaN(itmC1) then itmC1 else 0;
def itmC2V = if !IsNaN(itmC2) then itmC2 else 0;
def itmC3V = if !IsNaN(itmC3) then itmC3 else 0;
def itmC4V = if !IsNaN(itmC4) then itmC4 else 0;
def itmC5V = if !IsNaN(itmC5) then itmC5 else 0;
def itmC6V = if !IsNaN(itmC6) then itmC6 else 0;
def itmC7V = if !IsNaN(itmC7) then itmC7 else 0;
def itmC8V = if !IsNaN(itmC8) then itmC8 else 0;
def itmC9V = if !IsNaN(itmC9) then itmC9 else 0;
def itmC10V = if !IsNaN(itmC10) then itmC10 else 0;
def otmC1V = if !IsNaN(otmC1) then otmC1 else 0;
def otmC2V = if !IsNaN(otmC2) then otmC2 else 0;
def otmC3V = if !IsNaN(otmC3) then otmC3 else 0;
def otmC4V = if !IsNaN(otmC4) then otmC4 else 0;
def otmC5V = if !IsNaN(otmC5) then otmC5 else 0;
def otmC6V = if !IsNaN(otmC6) then otmC6 else 0;
def otmC7V = if !IsNaN(otmC7) then otmC7 else 0;
def otmC8V = if !IsNaN(otmC8) then otmC8 else 0;
def otmC9V = if !IsNaN(otmC9) then otmC9 else 0;
def otmC10V = if !IsNaN(otmC10) then otmC10 else 0;


def atmP = volume(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT));
def itmP1 = volume(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)));
def itmP2 = volume(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))));
def itmP3 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)))));
def itmP4 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))))));
def itmP5 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)))))));
def itmP6 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))))))));
def itmP7 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)))))))));
def itmP8 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))))))))));
def itmP9 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)))))))))));
def itmP10 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))))))))))));
def otmP1 = volume(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)));
def otmP2 = volume(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))));
def otmP3 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)))));
def otmP4 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))))));
def otmP5 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)))))));
def otmP6 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))))))));
def otmP7 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)))))))));
def otmP8 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))))))))));
def otmP9 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)))))))))));
def otmP10 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT))))))))))));
def atmPV = if !IsNaN(atmP) then atmP else 0;
def itmP1V = if !IsNaN(itmP1) then itmP1 else 0;
def itmP2V = if !IsNaN(itmP2) then itmP2 else 0;
def itmP3V = if !IsNaN(itmP3) then itmP3 else 0;
def itmP4V = if !IsNaN(itmP4) then itmP4 else 0;
def itmP5V = if !IsNaN(itmP5) then itmP5 else 0;
def itmP6V = if !IsNaN(itmP6) then itmP6 else 0;
def itmP7V = if !IsNaN(itmP7) then itmP7 else 0;
def itmP8V = if !IsNaN(itmP8) then itmP8 else 0;
def itmP9V = if !IsNaN(itmP9) then itmP9 else 0;
def itmP10V = if !IsNaN(itmP10) then itmP10 else 0;
def otmP1V = if !IsNaN(otmP1) then otmP1 else 0;
def otmP2V = if !IsNaN(otmP2) then otmP2 else 0;
def otmP3V = if !IsNaN(otmP3) then otmP3 else 0;
def otmP4V = if !IsNaN(otmP4) then otmP4 else 0;
def otmP5V = if !IsNaN(otmP5) then otmP5 else 0;
def otmP6V = if !IsNaN(otmP6) then otmP6 else 0;
def otmP7V = if !IsNaN(otmP7) then otmP7 else 0;
def otmP8V = if !IsNaN(otmP8) then otmP8 else 0;
def otmP9V = if !IsNaN(otmP9) then otmP9 else 0;
def otmP10V = if !IsNaN(otmP10) then otmP10 else 0;


input expirationDate2 = 20150516;
def atm2C = volume(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL));
def itm2C1 = volume(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)));
def itm2C2 = volume(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))));
def itm2C3 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)))));
def itm2C4 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))))));
def itm2C5 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)))))));
def itm2C6 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))))))));
def itm2C7 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)))))))));
def itm2C8 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))))))))));
def itm2C9 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)))))))))));
def itm2C10 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))))))))))));
def otm2C1 = volume(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)));
def otm2C2 = volume(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))));
def otm2C3 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)))));
def otm2C4 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))))));
def otm2C5 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)))))));
def otm2C6 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))))))));
def otm2C7 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)))))))));
def otm2C8 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))))))))));
def otm2C9 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL)))))))))));
def otm2C10 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.CALL))))))))))));
def atm2CV = if !IsNaN(atm2C) then atm2C else 0;
def itm2C1V = if !IsNaN(itm2C1) then itm2C1 else 0;
def itm2C2V = if !IsNaN(itm2C2) then itm2C2 else 0;
def itm2C3V = if !IsNaN(itm2C3) then itm2C3 else 0;
def itm2C4V = if !IsNaN(itm2C4) then itm2C4 else 0;
def itm2C5V = if !IsNaN(itm2C5) then itm2C5 else 0;
def itm2C6V = if !IsNaN(itm2C6) then itm2C6 else 0;
def itm2C7V = if !IsNaN(itm2C7) then itm2C7 else 0;
def itm2C8V = if !IsNaN(itm2C8) then itm2C8 else 0;
def itm2C9V = if !IsNaN(itm2C9) then itm2C9 else 0;
def itm2C10V = if !IsNaN(itm2C10) then itm2C10 else 0;
def otm2C1V = if !IsNaN(otm2C1) then otm2C1 else 0;
def otm2C2V = if !IsNaN(otm2C2) then otm2C2 else 0;
def otm2C3V = if !IsNaN(otm2C3) then otm2C3 else 0;
def otm2C4V = if !IsNaN(otm2C4) then otm2C4 else 0;
def otm2C5V = if !IsNaN(otm2C5) then otm2C5 else 0;
def otm2C6V = if !IsNaN(otm2C6) then otm2C6 else 0;
def otm2C7V = if !IsNaN(otm2C7) then otm2C7 else 0;
def otm2C8V = if !IsNaN(otm2C8) then otm2C8 else 0;
def otm2C9V = if !IsNaN(otm2C9) then otm2C9 else 0;
def otm2C10V = if !IsNaN(otm2C10) then otm2C10 else 0;

def atm2P = volume(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT));
def itm2P1 = volume(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)));
def itm2P2 = volume(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))));
def itm2P3 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)))));
def itm2P4 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))))));
def itm2P5 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)))))));
def itm2P6 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))))))));
def itm2P7 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)))))))));
def itm2P8 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))))))))));
def itm2P9 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)))))))))));
def itm2P10 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))))))))))));
def otm2P1 = volume(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)));
def otm2P2 = volume(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))));
def otm2P3 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)))));
def otm2P4 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))))));
def otm2P5 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)))))));
def otm2P6 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))))))));
def otm2P7 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)))))))));
def otm2P8 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))))))))));
def otm2P9 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT)))))))))));
def otm2P10 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate2, OptionClass.PUT))))))))))));
def atm2PV = if !IsNaN(atm2P) then atm2P else 0;
def itm2P1V = if !IsNaN(itm2P1) then itm2P1 else 0;
def itm2P2V = if !IsNaN(itm2P2) then itm2P2 else 0;
def itm2P3V = if !IsNaN(itm2P3) then itm2P3 else 0;
def itm2P4V = if !IsNaN(itm2P4) then itm2P4 else 0;
def itm2P5V = if !IsNaN(itm2P5) then itm2P5 else 0;
def itm2P6V = if !IsNaN(itm2P6) then itm2P6 else 0;
def itm2P7V = if !IsNaN(itm2P7) then itm2P7 else 0;
def itm2P8V = if !IsNaN(itm2P8) then itm2P8 else 0;
def itm2P9V = if !IsNaN(itm2P9) then itm2P9 else 0;
def itm2P10V = if !IsNaN(itm2P10) then itm2P10 else 0;
def otm2P1V = if !IsNaN(otm2P1) then otm2P1 else 0;
def otm2P2V = if !IsNaN(otm2P2) then otm2P2 else 0;
def otm2P3V = if !IsNaN(otm2P3) then otm2P3 else 0;
def otm2P4V = if !IsNaN(otm2P4) then otm2P4 else 0;
def otm2P5V = if !IsNaN(otm2P5) then otm2P5 else 0;
def otm2P6V = if !IsNaN(otm2P6) then otm2P6 else 0;
def otm2P7V = if !IsNaN(otm2P7) then otm2P7 else 0;
def otm2P8V = if !IsNaN(otm2P8) then otm2P8 else 0;
def otm2P9V = if !IsNaN(otm2P9) then otm2P9 else 0;
def otm2P10V = if !IsNaN(otm2P10) then otm2P10 else 0;

input expirationDate3 = 20150620;
def atm3C = volume(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL));
def itm3C1 = volume(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)));
def itm3C2 = volume(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))));
def itm3C3 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)))));
def itm3C4 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))))));
def itm3C5 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)))))));
def itm3C6 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))))))));
def itm3C7 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)))))))));
def itm3C8 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))))))))));
def itm3C9 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)))))))))));
def itm3C10 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))))))))))));
def otm3C1 = volume(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)));
def otm3C2 = volume(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))));
def otm3C3 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)))));
def otm3C4 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))))));
def otm3C5 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)))))));
def otm3C6 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))))))));
def otm3C7 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)))))))));
def otm3C8 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))))))))));
def otm3C9 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL)))))))))));
def otm3C10 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.CALL))))))))))));
def atm3CV = if !IsNaN(atm3C) then atm3C else 0;
def itm3C1V = if !IsNaN(itm3C1) then itm3C1 else 0;
def itm3C2V = if !IsNaN(itm3C2) then itm3C2 else 0;
def itm3C3V = if !IsNaN(itm3C3) then itm3C3 else 0;
def itm3C4V = if !IsNaN(itm3C4) then itm3C4 else 0;
def itm3C5V = if !IsNaN(itm3C5) then itm3C5 else 0;
def itm3C6V = if !IsNaN(itm3C6) then itm3C6 else 0;
def itm3C7V = if !IsNaN(itm3C7) then itm3C7 else 0;
def itm3C8V = if !IsNaN(itm3C8) then itm3C8 else 0;
def itm3C9V = if !IsNaN(itm3C9) then itm3C9 else 0;
def itm3C10V = if !IsNaN(itm3C10) then itm3C10 else 0;
def otm3C1V = if !IsNaN(otm3C1) then otm3C1 else 0;
def otm3C2V = if !IsNaN(otm3C2) then otm3C2 else 0;
def otm3C3V = if !IsNaN(otm3C3) then otm3C3 else 0;
def otm3C4V = if !IsNaN(otm3C4) then otm3C4 else 0;
def otm3C5V = if !IsNaN(otm3C5) then otm3C5 else 0;
def otm3C6V = if !IsNaN(otm3C6) then otm3C6 else 0;
def otm3C7V = if !IsNaN(otm3C7) then otm3C7 else 0;
def otm3C8V = if !IsNaN(otm3C8) then otm3C8 else 0;
def otm3C9V = if !IsNaN(otm3C9) then otm3C9 else 0;
def otm3C10V = if !IsNaN(otm3C10) then otm3C10 else 0;

def atm3P = volume(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT));
def itm3P1 = volume(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)));
def itm3P2 = volume(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))));
def itm3P3 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)))));
def itm3P4 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))))));
def itm3P5 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)))))));
def itm3P6 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))))))));
def itm3P7 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)))))))));
def itm3P8 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))))))))));
def itm3P9 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)))))))))));
def itm3P10 = volume(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))))))))))));
def otm3P1 = volume(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)));
def otm3P2 = volume(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))));
def otm3P3 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)))));
def otm3P4 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))))));
def otm3P5 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)))))));
def otm3P6 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))))))));
def otm3P7 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)))))))));
def otm3P8 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))))))))));
def otm3P9 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT)))))))))));
def otm3P10 = volume(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate3, OptionClass.PUT))))))))))));
def atm3PV = if !IsNaN(atm3P) then atm3P else 0;
def itm3P1V = if !IsNaN(itm3P1) then itm3P1 else 0;
def itm3P2V = if !IsNaN(itm3P2) then itm3P2 else 0;
def itm3P3V = if !IsNaN(itm3P3) then itm3P3 else 0;
def itm3P4V = if !IsNaN(itm3P4) then itm3P4 else 0;
def itm3P5V = if !IsNaN(itm3P5) then itm3P5 else 0;
def itm3P6V = if !IsNaN(itm3P6) then itm3P6 else 0;
def itm3P7V = if !IsNaN(itm3P7) then itm3P7 else 0;
def itm3P8V = if !IsNaN(itm3P8) then itm3P8 else 0;
def itm3P9V = if !IsNaN(itm3P9) then itm3P9 else 0;
def itm3P10V = if !IsNaN(itm3P10) then itm3P10 else 0;
def otm3P1V = if !IsNaN(otm3P1) then otm3P1 else 0;
def otm3P2V = if !IsNaN(otm3P2) then otm3P2 else 0;
def otm3P3V = if !IsNaN(otm3P3) then otm3P3 else 0;
def otm3P4V = if !IsNaN(otm3P4) then otm3P4 else 0;
def otm3P5V = if !IsNaN(otm3P5) then otm3P5 else 0;
def otm3P6V = if !IsNaN(otm3P6) then otm3P6 else 0;
def otm3P7V = if !IsNaN(otm3P7) then otm3P7 else 0;
def otm3P8V = if !IsNaN(otm3P8) then otm3P8 else 0;
def otm3P9V = if !IsNaN(otm3P9) then otm3P9 else 0;
def otm3P10V = if !IsNaN(otm3P10) then otm3P10 else 0;

def totalCallVolume = atmCV + itmC1V + itmC2V + itmC3V + itmC4V + itmC5V + itmC6V + itmC7V + itmC8V + itmC9V + itmC10V
+ otmC1V + otmC2V + otmC3V + otmC4V + otmC5V + otmC6V + otmC7V + otmC8V + otmC9V + otmC10V +
atm2CV + itm2C1V + itm2C2V + itm2C3V + itm2C4V + itm2C5V + itm2C6V + itm2C7V + itm2C8V + itm2C9V + itm2C10V
+ otm2C1V + otm2C2V + otm2C3V + otm2C4V + otm2C5V + otm2C6V + otm2C7V + otm2C8V + otm2C9V + otm2C10V +
atm3CV + itm3C1V + itm3C2V + itm3C3V + itm3C4V + itm3C5V + itm3C6V + itm3C7V + itm3C8V + itm3C9V + itm3C10V
+ otm3C1V + otm3C2V + otm3C3V + otm3C4V + otm3C5V + otm3C6V + otm3C7V + otm3C8V + otm3C9V + otm3C10V;

plot calls = if !isNan(close) then totalCallVolume else double.nan;
calls.SetDefaultColor(Color.GREEN);

def totalPutVolume = atmPV + itmP1V + itmP2V + itmP3V + itmP4V + itmP5V + itmP6V + itmP7V + itmP8V + itmP9V + itmP10V
+ otmP1V + otmP2V + otmP3V + otmP4V + otmP5V + otmP6V + otmP7V + otmP8V + otmP9V + otmP10V+
atm2PV + itm2P1V + itm2P2V + itm2P3V + itm2P4V + itm2P5V + itm2P6V + itm2P7V + itm2P8V + itm2P9V + itm2P10V
+ otm2P1V + otm2P2V + otm2P3V + otm2P4V + otm2P5V + otm2P6V + otm2P7V + otm2P8V + otm2P9V + otm2P10V+
atm3PV + itm3P1V + itm3P2V + itm3P3V + itm3P4V + itm3P5V + itm3P6V + itm3P7V + itm3P8V + itm3P9V + itm3P10V
+ otm3P1V + otm3P2V + otm3P3V + otm3P4V + otm3P5V + otm3P6V + otm3P7V + otm3P8V + otm3P9V + otm3P10V;

plot puts = if !isNan(close) then totalPutVolume else double.nan;
puts.SetDefaultColor(Color.RED);

plot pcr = (puts/max(1,calls));
pcr.setDefaultColor(color.BLACK);
plot pcrAvg = average(pcr,pcrAveragePeriod);
pcrAvg.setDefaultColor(color.BLUE);
pcr.hide();

AddLabel(yes, Concat("Put Volume: ", totalPutVolume), color.RED);
AddLabel(yes, Concat("Call Volume: ", totalCallVolume), color.GREEN);
AddLabel(yes, Concat("P/C: ", totalPutVolume/totalCallVolume), color.BLUE);
 
@YungTraderFromMontana I saw your idea and figured I'd try it, check if this fits what you're looking for. :)

Code:
#$PCALL_Indicator
#Pensar
#06/16/2020
#$PCALL below 0.75 - high bullish market sentiment
#$PCALL between 0.75-1.00 - neutral market sentiment
#$PCALL above 1.00  - high bearish market sentiment

declare lower;

input labels = yes;

plot pcall = close("$PCALL");
     pcall.SetLineWeight(1);
     pcall.SetPaintingStrategy(paintingstrategy.line_vs_points);
     pcall.AssignValueColor(if pcall > 1.0 then color.red
                            else if pcall > 0.75 then color.gray
                            else color.green);

plot high_line = 1.0;
     high_line.SetDefaultColor(color.red);

plot mid_line = 0.75;
     mid_line.SetPaintingStrategy(paintingstrategy.dashes);
     mid_line.SetDefaultColor(color.gray);

plot low_line = 0.50;
     low_line.SetDefaultColor(color.green);

AddLabel(Labels,"$PCALL: " + close("$PCALL"), Color.gray);
AddLabel(Labels, "Sentiment: " + (if pcall > 1.0
         then "Highly Bearish"
         else if pcall > 0.75 then "Neutral"
         else "Highly Bullish"),
         if pcall > 1.0 then color.red
         else if pcall > 0.75 then color.gray
         else color.green);

#end code
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@Pensar Yo this is amazing, a whole new world of analysis has opened up.

Edit: Actually this isn't what I wanted, this give p/c ratio of all options on the market. I need it for individual stocks. Would you know how to do that?
 
Last edited by a moderator:
Oh, I understand what you want now. That is likely difficult to get. As you mentioned, Tomsk posted in this thread the code to get the ATM put/call ratio of a particular stock, and that probably would have to be repeated multiple times for each individual strike. :( I have never looked very deep into coding it.
 
@YungTraderFromMontana Your original title and question were related to the general put/call ratio. That is why it was moved there. Next time, please be more specific about your request.

Now that we understood what you wanted, these two threads may be useful:
Understand how the put/call ratio is being calculated, then apply that calculation to all the strikes within the individual ticker.
 
P/C Ratio $PCALL ration for any symbol in the chart (TOS Platform)
OCC means? with reference to $ PCALL, also $CPC gives total PUT CALL ratio for all the Indexes? not sure, but will be defintly be interesting to have it as an Indicator or an Avg in form of a line graph for SPY, SPX and all the Optionable Stocks.There must be something
 
Last edited:
There is a P/C ratio available for each stock in ToS, located under the Trade tab for options and then "Today's option statistics". Is this piece of data able to be plotted over time in an indicator? I believe this is the type of thing the OP is looking for, and I would love to see as well. Thanks all!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
196 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top