entryprice() -+ will not close correctley

*correctly

Hey guys I created a strategy trying to exit entryprice() +-3, I’m using this on /es and Range chart

Problem I’m having is it closes the trade on next candle when triggered, or sometimes completely misses

Any work around that you guys can recommend??

I plotted the target with red horizontal and stop with red horizontal sometimes its close but not always

NCKUX34.png

gUckJbP.png


here is one completely missed target and got stopped

TudPFjz.png


Code:
def h = high ;
def l = low;
def c = close ;
def o = open ;
def v = volume;

def down  = h <= h[1] and l < l[1];
def down_green =  down and c > o;

def rvol_Type = AverageType.SIMPLE;
input RVol_length = 10 ;
def AvgVol = MovingAverage(rvol_Type, v, RVol_length);
def CurrentToAvg = Round(v / AvgVol);

def rv1 = 1.6;
def rv2 = 2.0;
def rv3 = 2.6;

def displace = 0;
def length = 20;
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
def averageType = AverageType.Simple;

def sDev = stdev(data = c[-displace], length = length);
def MidLine = MovingAverage(averageType, data = c[-displace], length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;


input target = 3;
input stop = 3;
input qty = 1;

def LE =  down_green and  CurrentToAvg > rv2 and low < lowerband;
def lpt = close crosses entryprice() + target;
def stp = close crosses entryprice() - stop;

def longtargetx =  if LE then  close + target  else 0;
plot longtargetxx = longtargetx;
  longtargetxx.SetDefaultColor(Color.green);
  longtargetxx.SetPaintingStrategy(PaintingStrategy.hoRIZONTAL);

def longstopx = if LE  then close - STOP else 0 ;
plot longstopxx = longstopx;
   longstopxx.SetDefaultColor(Color.light_RED);
   longstopxx.SetPaintingStrategy(PaintingStrategy.hoRIZONTAL);


addOrder(OrderType.buy_TO_OPEN, le, tickColor = GetColor(0),  name = ";LE;", arrowColor = color.cyan);

AddOrder(OrderType.SELL_TO_CLOSE, lpt, tradeSize = qty, name = ";LPT;",arrowColor = color.green);

AddOrder(OrderType.SELL_TO_CLOSE, stp ,tradeSize = qty, name = ";LSTP;",arrowColor = color.red);
 
Made a couple changes... check it out:

OkcFSpy.jpg


Ruby:
def h = high ;
def l = low;
def c = close ;
def o = open ;
def v = volume;

def down  = h <= h[1] and l < l[1];
def down_green =  down and c > o;

def rvol_Type = AverageType.SIMPLE;
input RVol_length = 10 ;
def AvgVol = MovingAverage(rvol_Type, v, RVol_length);
def CurrentToAvg = Round(v / AvgVol);

def rv1 = 1.6;
def rv2 = 2.0;
def rv3 = 2.6;

def displace = 0;
def length = 20;
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
def averageType = AverageType.Simple;

def sDev = stdev(data = c[-displace], length = length);
def MidLine = MovingAverage(averageType, data = c[-displace], length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;

def entryPrice = EntryPrice();

input target = 3;
input stop = 3;
input qty = 1;

def LE =  down_green and  CurrentToAvg > rv2 and low < lowerband;
def lpt = close[-1] crosses entryprice[-1] + target;
def stp = close[-1] crosses entryprice[-1] - stop;

def longtargetx =  if LE then  close + target  else 0;
plot longtargetxx = longtargetx;
  longtargetxx.SetDefaultColor(Color.green);
  longtargetxx.SetPaintingStrategy(PaintingStrategy.hoRIZONTAL);

def longstopx = if LE  then close - STOP else 0 ;
plot longstopxx = longstopx;
   longstopxx.SetDefaultColor(Color.light_RED);
   longstopxx.SetPaintingStrategy(PaintingStrategy.hoRIZONTAL);


addOrder(OrderType.buy_TO_OPEN, le, tickColor = GetColor(0),  name = ";LE;", arrowColor = color.cyan);

AddOrder(OrderType.SELL_TO_CLOSE, lpt, tradeSize = qty, name = ";LPT;", price = entryPrice[-1] + target, arrowColor = color.green);

AddOrder(OrderType.SELL_TO_CLOSE, stp ,tradeSize = qty, name = ";LSTP;", price = entryPrice[-1] - stop, arrowColor = color.red);
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
246 Online
Create Post

Similar threads

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