input TargetRatio = 1.015;
input barexit = 2;
def LongTarget = LongEnt * TargetRatio;
def LongExt= LongTarget or LongEnt from barexit bars ago;
AddOrder(OrderType.SELL_TO_CLOSE, LongExt, close, TradeSize);
input TargetRatio = 1.015;
input barexit = 2;
def LongTarget = EntryPrice() * TargetRatio;
def LongExt= (close >= LongTarget) or (LongEnt from barexit bars ago);
AddOrder(OrderType.SELL_TO_CLOSE, LongExt, close, TradeSize);
input expirationDate = 20191019;
AddLabel(IsOptionable(), "ATM Call: " + GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL), Color.UPTICK);
AddLabel(IsOptionable(), "1st OTM Call: " + GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)), Color.GREEN);
AddLabel(IsOptionable(), "2nd OTM Call: " + GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL))), Color.LIGHT_GREEN);
@RobertPayne Thanks. It seems TS doesn't provide the means to get price from codes.
def MA5 = Average(close, 5);
def MA13 = Average(close, 13);
def buyCondition = MA5 crosses above MA13;
AddOrder(OrderType.BUY_TO_OPEN, buyCondition, open[-1], 100, Color.UPTICK, Color.UPTICK, "BTO");
def sellCondition = close >= EntryPrice() + 2;
AddOrder(OrderType.SELL_TO_CLOSE, sellCondition, open[-1], 100, Color.DOWNTICK, Color.DOWNTICK, "STC");
GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)
How do you get price using that function? The code you posted last doesn't seem to use it.
@RobertPayne Got it working, thanks.
EDIT: The option function (returns a code) can be used with a fundamental function (returns price) to get the option price:
close(symbol = GetATMOption(GetUnderlyingSymbol(), Date, OptionClass.CALL))
def expDate = 20191019; #options expiration date
def bidPrice = close(symbol = GetATMOption(GetUnderlyingSymbol(), expDate, OptionClass.CALL), priceType = PriceType.BID);
def askPrice = close(symbol = GetATMOption(GetUnderlyingSymbol(), expDate, OptionClass.CALL), priceType = PriceType.ASK);
plot Data = close;
declare lower;
input expirationDate = 20200612;
plot AprilATMPutPrice = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT));
@RobertPayne just wanted to let you know that these aren't working for some reason. I tried them over the weekend and nothing appeared, so I wanted to wait till the market was active today and still no response from the program. The labels appear but the actual options don't appear.
input expirationDate = 20220114;
AddLabel(IsOptionable(), "ATM Call: " + GetATMOption(GetUnderlyingSymbol(), expirationDate+1, OptionClass.CALL), Color.UPTICK);
AddLabel(IsOptionable(), "1st OTM Call: " + GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate+1, OptionClass.CALL)), Color.GREEN);
AddLabel(IsOptionable(), "2nd OTM Call: " + GetNextOTMOption(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate+1, OptionClass.CALL))), Color.LIGHT_GREEN);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.