Option Straddle based on Moving Average

P

Piper2808t

New member
VIP
open and close between avgexp. i meant high and low between avgexp. straddles on a daily time frame in a column if ema 200 is between the high and low of a daily bar than by a straddle 30-45 days out
 
H

horserider

Active member
Still makes no sense. If avgexp means an EMA and an EMA is a line. How do you get a high and low or open and close to fall between a line ?
 
H

horserider

Active member
That is not what you said. Now it makes some sense as far as a statement but what sense does it make for trading.
 
H

horserider

Active member
Ahh ok Now that what you wanted is better explained maybe someone will be able to help.
 
sirigina

sirigina

New member
VIP
Here is a script that plots an arrow when EMA crosses between High and Low of the day.
Is this what you are looking for?

#Straddle_Signal_With_EMA

input duration = 200;
def lo = low;
def hi = high;
def cl = close;

def _EMA = MovingAverage(AverageType.EXPONENTIAL, cl, duration);

def emabetween = if (_EMA <= hi and _EMA >= lo) then 1 else 0;

plot EmaBetweenHighLow = emabetween;
EmaBetweenHighLow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
EmaBetweenHighLow.SetLineWeight(2);

plot EMA = _EMA;
#END
 
sirigina

sirigina

New member
VIP
2 General Questions:
  1. Is it possible to show the above indicator Only ONCE and Only if it occurred in the last 5 days? Avoid noise and ignore older signals
  2. How do I make this indicator to show only on daily aggregation chart? Noisy in 5 min charts
Thanks in advance
 
BenTen

BenTen

Administrative
Staff
VIP
@sri5nivas Regarding your second question, try using the following condition.

Code:
declare hide_on_intraday;
 
sirigina

sirigina

New member
VIP
Couldn't sleep until I figure this out, but I finally got it working the way I want it.
In this modified script, you can specify LookbackDays (number of days to look back) for this condition.
Basically if the condition occurred too long ago, then it won't show it.
If you want to see all past indicators, you can specify 0 for LookbackDays

Note: TOS indicates that this might cause performance issues. If you see any sluggishness, use the previous version.

#Straddle_Signal_With_EMA
#LookbackDays = 0 will show all past indicators, or specify number of days to look back

declare hide_on_intraday;

input Duration = 200;
input LookbackDays = 0;
def lo = low;
def hi = high;
def cl = close;

def _EMA = MovingAverage(AverageType.EXPONENTIAL, cl, Duration);
def NumberOfBars = HighestAll(if !IsNaN(close) then BarNumber() else Double.NEGATIVE_INFINITY);

def emabetween = if ( (LookbackDays <= 0 or BarNumber() > NumberOfBars-LookbackDays ) AND (_EMA <= hi and _EMA >= lo) ) then 1 else 0;

plot EmaBetweenHighLow = emabetween;
EmaBetweenHighLow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
EmaBetweenHighLow.SetLineWeight(2);

plot EMA = _EMA;

#END
 
P

Piper2808t

New member
VIP
any way to put this in a column as to when the arrow appears
 
sirigina

sirigina

New member
VIP
Here it is. You can add this to a Custom Column script.
It shows "A" if the EMA crossed between high and low in the last 5 days.

#Straddle_Signal_Column
def _EMA = MovingAverage(AverageType.EXPONENTIAL, close, 200);

def emabetween = if ( (_EMA[0] <= high[0] and _EMA[0] >= low[0]) or (_EMA[1] <= high[1] and _EMA[1] >= low[1]) or (_EMA[2] <= high[2] and _EMA[2] >= low[2]) or (_EMA[3] <= high[3] and _EMA[3] >= low[3]) or (_EMA[4] <= high[4] and _EMA[4] >= low[4]) ) then 1 else 0;

AddLabel(emabetween, "A", Color.DARK_RED);
AddLabel(!emabetween, " ");
#END
 
Last edited:
sirigina

sirigina

New member
VIP
@Piper2808t
If you are adding the signal column, probably it would be good to know the approximate straddle cost as well.
You can add this column which approximate theoretical cost of a straddle that is 45 days out.

#StraddleCost
#Approximate theoretical cost of Straddle 45 days out
2 * (0.4 * ImpVolatility() * Sqrt (45/365)) * close
#END
 
sirigina

sirigina

New member
VIP
@Piper2808t
Please let me know how this indicator works for you.

I usually buy 45 day straddle when I see a stock is moving in a tight channel and expecting a catalyst or a surprise in the next 45 days. I will try this as well.
 

Top