Options Profit % and Breakeven price

anasmatar

New member
I found this code on the internet to show the potential profit % and the breakeven price for the options chain but its only working for Put side for some reason. Could someone help look at the code and fix it to work for Call and Puts?

def maxShares = 100;
def maxContracts = 1;

def premium_call = maxContracts * (bid + ask) / 2 * 100;
def premiumPct_call = premium_call / (maxShares * close(GetUnderlyingSymbol()));

def strikePriceGain_call = GetStrike() - close(GetUnderlyingSymbol());
def premiumPlusSharesPct = ((strikePriceGain_call * maxShares) + premium_call) / (maxShares * close(GetUnderlyingSymbol()));

def premium_put = maxContracts * close * maxShares;
def premiumPct_put = premium_put/(maxShares * close(getUnderlyingSymbol()));

def newBreakevenPrice_put = getStrike() - close;

AddLabel(!isPut(), AsPercent(premiumPct_call) + " | " + AsPercent(premiumPlusSharesPct), color.WHITE);
AddLabel(isPut(), AsPercent(premiumPct_put) + " | " + AsPrice(newBreakevenPrice_put), color.WHITE);
 

barbaros

Administrator
Staff member
It is designed to be that way. When it is not put, aka call, it shows a percent. When it is a put, it shows a price, it calls it break even price.
 

barbaros

Administrator
Staff member
Ah, I see it now.

This is for calls:
Code:
AddLabel(!isPut(), AsPercent(premiumPct_call) + " | " + AsPercent(premiumPlusSharesPct), color.WHITE);

And, this is for puts:
Code:
AddLabel(isPut(), AsPercent(premiumPct_put) + " | " + AsPrice(newBreakevenPrice_put), color.WHITE);

I don't see any issues with it. It works as designed and no NaNs. Can you attach a screenshot?
 

anasmatar

New member
Ah, I see it now.

This is for calls:
Code:
AddLabel(!isPut(), AsPercent(premiumPct_call) + " | " + AsPercent(premiumPlusSharesPct), color.WHITE);

And, this is for puts:
Code:
AddLabel(isPut(), AsPercent(premiumPct_put) + " | " + AsPrice(newBreakevenPrice_put), color.WHITE);

I don't see any issues with it. It works as designed and no NaNs. Can you attach a screenshot?
see below
5WKQCdO.jpg
 

barbaros

Administrator
Staff member
Funny thing, I seem to have this for my option list columns as well and it is working well. Here is the one that I have.

Code:
# Wheel Column

def maxShares = 100;
def maxContracts = 1;

def symbolPrice = close(GetUnderlyingSymbol());
def BidAsk2 = bid; #(bid + ask) / 2;

def premium_call = maxContracts * BidAsk2 * 100;
def premiumPct_call = premium_call / (maxShares * symbolPrice);

def strikePriceGain_call = GetStrike() - symbolPrice;
def premiumPlusSharesPct = ((strikePriceGain_call * maxShares) + premium_call) / (maxShares * symbolPrice);

def premium_put = maxContracts * BidAsk2 * maxShares;
def premiumPct_put = premium_put/(maxShares * symbolPrice);

def newBreakevenPrice_put = getStrike() - BidAsk2;

AddLabel(!isPut(), AsPercent(premiumPct_call) + " | " + AsPercent(premiumPlusSharesPct), color.WHITE);
AddLabel(isPut(), AsPercent(premiumPct_put) + " | " + AsPrice(newBreakevenPrice_put), color.WHITE);
 
Top