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);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
@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);
I have the problem. Did you ever solve?Hello @RobertPayne
When i try to plot ATM option close price on the chart as a line instead of a label, the line blinks between price and N/A (or 0), and totally repaints the ATM close price when underlying price changes. Is it possible to have the indicator plot line stay without disappearing whenever the underlying price fluctuates?
For example, at market open let's say 250 is the ATM option strike and after few mins 255 is the ATM option strike. Can we draw the indicator by dynamically taking in the ATM option price and continue draw the line as price changes without having the issue of repainting the entire plot?
Thanks!
I have the problem. Did you ever solve?
The question above was:it is unclear what you are asking.
the original post was vague.
you didn't reference any code. this thread just has code pieces here and there.
post the code you tried and write out full sentences, describing what you want to see.
I seem to have possibly answered my own question.The question above was:
Can we draw the indicator by dynamically taking in the ATM option price and continue draw the line as price changes without having the issue of repainting the entire plot?
It has to do with getatmoption().
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.