• Get $40 off VIP by signing up for a free account! Sign Up

Pull Back Strategy For ThinkOrSwim

T

Trendman

Guest
Attached is a strategy that allows you to select a pullback and whether you want the first pull back or confirmation. The problem I am having is the signal fires using the close of the bar meeting the condition, however the AddOrder displays on the next bar. How can I get this to display on the bar that created the signal?

input longEntries = yes;
input shortEntries = no;
input entryMA = {default EMA8, EMA21, EMA34, SMA50, SMA200};
input entryType = {default pullbackOnly, Confirmation};
input targetMultiplier = 2;
input stopMultiplier = 1;
input quantity = 100;

def EMA8 = ExpAverage(close, 8);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);
def SMA50 = SimpleMovingAvg(close, 50);
def SMA200 = SimpleMovingAvg(close, 200);

def entryPullbackMA;
switch (entryMA){
case EMA8:
entryPullbackMA = EMA8;
case EMA21:
entryPullbackMA = EMA21;
case EMA34:
entryPullbackMA = EMA34;
case SMA50:
entryPullbackMA = SMA50;
case SMA200:
entryPullbackMA = SMA200;
}

def bullishStackedMAs = EMA8 > EMA21 and EMA21 > EMA34 and EMA34 > SMA50 and SMA50 > SMA200;

def bearishStackedMAs = EMA8 < EMA21 and EMA21 < EMA34 and EMA34 < SMA50 and SMA50 < SMA200;


def bullEntrySignal;
def bullEntryPrice;
def bearEntrySignal;
def bearEntryPrice;

switch(entryType){
case pullbackOnly:
bullEntrySignal = bullishStackedMAs and low <= entryPullbackMA;
bullEntryPrice = entryPullbackMA;
bearEntrySignal = bearishStackedMAs and high >= entryPullbackMA;
bearEntryPrice = entryPullbackMA;
case Confirmation:
bullEntrySignal = bullishStackedMAs and Lowest(low,2) <= entryPullbackMA and close > high[1];
bullEntryPrice = close;
bearEntrySignal = bearishStackedMAs and Highest(high,2) >= entryPullbackMA and close < low[1];
bearEntryPrice = close;
}

def ATRvalue = if (bullEntrySignal and !bullEntrySignal[1]) or (bearEntrySignal and !bearEntrySignal[1]) then ATR(14) else ATRvalue[1];


#Long-Side Trades
AddOrder(OrderType.BUY_TO_OPEN, longEntries and bullEntrySignal, bullEntryPrice, quantity, name= "buy");
AddOrder(OrderType.SELL_TO_CLOSE, high >= entryPrice() + targetMultiplier * ATRValue, entryPrice() + targetMultiplier * ATRValue, quantity,name= "buy");
AddOrder(OrderType.SELL_TO_CLOSE, low <= entryPrice() - stopMultiplier * ATRValue, entryPrice() - stopMultiplier * ATRValue, quantity, name= "buy");

#Short-Side Trades
AddOrder(OrderType.SELL_TO_OPEN, shortEntries and bearEntrySignal, bearEntryPrice, quantity, name = "sell");
AddOrder(OrderType.BUY_TO_CLOSE, low <= entryPrice() - targetMultiplier * ATRValue, entryPrice() - targetMultiplier * ATRValue, quantity, name = "sell");
AddOrder(OrderType.BUY_TO_CLOSE, high >= entryPrice() + stopMultiplier * ATRValue, entryPrice() + stopMultiplier * ATRValue, quantity, name = "sell");

#End Code
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

mod note:

We ask that only realistic strategies be posted to the forum.

Your request is not realistic.
The signal occurs on the close of the current bar.

By definition, the trade cannot take place until the open of the next bar.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
696 Online
Create Post

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