Why won't this strategy plot?

YungTraderFromMontana

Well-known member
I've been working on a options strategy and really want to test it so I can get a better understanding on how I can improve it. My goal was to have a buy condition and then sell on the opening of the 4th day. I'm pretty sure I did this a very unorthodox way, it plots arrows, yet It won't work in a strategy. Hopefully someone can help. Does anyone know a simpler way to make the sell condition "sell after 3 days"
Code:
input price = close;
input length4 = 13;
input displace = 0;
plot AvgExp = ExpAverage(price[-displace], length4);
input length6 = 48.5;
plot AvgExp2 = ExpAverage(price[-displace], length6);
def c = close;

input length = 14;
input calcLength = 5;
input smoothLength = 3;
input length2 = 30;
input calclength2 = 5;
input smoothlength2 = 2;
input agg = AggregationPeriod.DAY;
input agg2 = AggregationPeriod.THREE_DAYS;


def zeroline = 0;
def o10 = open(period = agg);
def c10 = close(period = agg);
def data = fold i = 0 to length2
           with s
           do s + (if c10 > GetValue(o10, i)
                   then 1
                   else if c10 < GetValue(o10, i)
                        then - 1
                        else 0);
def EMA5 = ExpAverage(data, calclength2);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);

def zero = if IsNaN(c) then Double.NaN else 0;
def ob = if IsNaN(c) then Double.NaN else Round(length * .7);
def ob2 = if IsNaN(c) then Double.NaN else Round(length * .3);
def  ob3 = if IsNaN(c) then Double.NaN else Round(length * .0504);
def ob4 = if IsNaN(c) then Double.NaN else Round(length * -.7);
def ob5 = if IsNaN(c) then Double.NaN else Round(length * -.3);
def ob6 = if IsNaN(c) then Double.NaN else Round(length * -.2);
def ob7 = if IsNaN(c) then Double.NaN else Round(length * .0);
def os = if IsNaN(c) then Double.NaN else -Round(length * .2);
def os2 = if IsNaN(c) then Double.NaN else -Round(length * .6);
def os3 = if IsNaN(c) then Double.NaN else -Round(length * .0);
def os4 = if IsNaN(c) then Double.NaN else -Round(length * -.1);

def o2 = open(period = agg2);
def c2 = close(period = agg2);
def data2 = fold i2 = 0 to length
           with s2
           do s2 + (if c2 > GetValue(o2, i2)
                   then 1
                   else if c2 < GetValue(o2, i2)
                        then - 1
                        else 0);

def EMA52 = ExpAverage(data2, calclength2);
def Main2 = ExpAverage(EMA52, smoothLength);
def Signal2 = ExpAverage(Main2, smoothLength);


input BuyorSell = {default Buy, Sell};
input ShowTodayOnly = yes;
input ShowEntryExitBands = yes;
input ShowBubbles = yes;
input BuyEntry = 3;
input SellEntry = 3;
input BuyExit = 20;
input SellExit = 20;

input ATRLength = 50;
input TargetATRMult = 1;
input DisplayLines = yes;
input PriceDigit = 2;

# High

def H1  = Highest(high, SellExit);
def H2  = fold i3 = 1 to SellExit
          with ip = 0.0
          do if GetValue(high, i3) == H1 or GetValue(high, i3) < ip
             then ip
             else GetValue(high, i3);
def H3  = fold i1 = 1 to SellExit
          with ip1 = 0.0
          do if GetValue(high, i1) == H1 or GetValue(high, i1) == H2 or GetValue(high, i1) < ip1
             then ip1
             else GetValue(high, i1);
def HH  = (H2 + H3) / 2.0;

# Low

def L1  = Lowest(low, BuyExit);
def L2  = fold i4 = 1 to BuyExit
          with ip2 = 10000000.0
          do if GetValue(low, i4) == L1 or GetValue(low, i4) > ip2
             then ip2
             else GetValue(low, i4);
def L3  = Lowest(if low == L1 or low == L2 then 1000000 else low, BuyExit);
def LL  = (L2 + L2) / 2.0;

def QB = Highest(high, BuyEntry);
def QS = Lowest(low, SellEntry);
plot x = QB[1];
plot y = ll;
def ATRVal = ATR(length = ATRLength, averageType = AverageType.SIMPLE);
def mATR = Highest(ATRVal, ATRLength);
plot reversethatb = (high - open > 0) and (open > close);

plot optionbuy = (close > QB[1]) and ((Main - 2 > Main[1]) or (main > ob)) and (close[1] < QB[2]) and (close[2] < QB[3]) and (close[3] < QB[4]);
plot sell = optionbuy[3];

AddOrder(OrderType.Buy_TO_OPEN, condition = optionbuy
, price =  open[-1], 1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BE");

AddOrder(OrderType.Sell_to_Close, condition = sell
, price = open[-1], 1, tickcolor = Color.RED, arrowcolor = Color.RED, name = "SE");
 

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
You need to add it as a strategy and it will plot your order. Here I have MSFT on the 1Y 1D chart with the code you posted.

WAr9cym.png
 

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.
Top