EntryPrice() always return NaN in OnDemand

FutureMG

New member
Plus
I'm trying to set my profit and stop losses using the entry price for an order, however, entryPrice() always returns NaN; even when an order is active.

Even in the simple example below, EntryPrice() always returns NaN.

What am I missing or doing wrong?


Code:
input price = close;
input length = 14;
input over_bought = 70;
input over_sold = 30;
input rsiAverageType = AverageType.WILDERS;

def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);

AddOrder(OrderType.BUY_AUTO, rsi crosses above over_sold, tickColor = GetColor(0), arrowColor = GetColor(0), name = "RSI_LE");
AddOrder(OrderType.SELL_AUTO, rsi crosses below over_bought, tickColor = GetColor(1), arrowColor = GetColor(1), name = "RSI_SE");

addLabel(yes,entryPrice());
 
I figured out a workaround for anyone who is struggling with this. I'm a little embarrassed it took me this long to figure out. I'm not sure why entryPrice() doesn't persist. Hopefully it changes in an update. Anyway, here's the workaround:

Code:
def entryp = if isNan(entryPrice()) then entryp[1] else entryPrice();

Hope this saves someone some time.
 
@FutureMG I just use a def entry = EntryPrice(); but sometimes just include a call to EntryPrice() in my logic... I think your issue may be that AddLabel() sometimes has issues with direct calls to some functions, and I believe EntryPrice() is one of them...
 
Last edited:
I've actually been playing with this for the past couple of hours. Honestly, unless I'm missing something, the implementation of EntryPrice() needs to be updated.

Let me explain.

The following code will execute just fine:
Code:
def selllongp = close > entryPrice() + takeprof;
addOrder(OrderType.SELL_TO_CLOSE, selllongp, tickColor = GetColor(5), arrowColor = GetColor(5));

However, if you try to perform any sort of logic using EntryPrice() prior to an order execution, it will simply return NaN:
Code:
if (EntryPrice() >= 0) {
    test = 1;
} else {
    test = 2;
}

The first condition, literally never executes even though it's always true. It's as if the value of EntryPrice() can only be accessed when directly used in an order.

Unless I'm missing something, this severely limits how EntryPrice() can be used.
 
Last edited:
Any modifications of EntryPrice() would be well down the list of priorities at the moment, one would think... It is more for backtesting than anything else... And OnDemand is clunky at best... paperMoney Mode works better but has its own issues... The fact that it doesn't share any resources with the realtime live trading mode, meaning that they have to be copied over, being one of the biggest...
 
Seems like a serious oversight if I'm being honest. EntryPrice is such a critical piece of information when trading. To not be able to perform any logic using it severely limits the utility on backtesting on the TOS platform.

I'm really trying to come up with a clever way around this but I'm coming up short. It behaves really strangely. If (EntryPrice >= 1000) is false, everything works as expected. But if EntryPrice is say 200, then "if (EntryPrice >= 199)" prevents any orders from showing up in backtesting at all.

Surely I'm not the only one who's ran into this?!
 
Is this in live TOS as a Strategy or elsewhere...??? The accuracy and efficiency of data returns has been erratic at best, depending on the operational mode of TSO... The EntryPrice() function is not used for actual trades which is why I say that it is most likely low(er) on the priority list... And while it might be nice to have a huge team of developers devoted to improving all aspects of the Desktop platform, I'm fairly confident saying that the majority of coding effort is spread thin across all platforms... Just my personal opinion...
 
I'm using OnDemand to backtest my strategy. Good way to get different datasets.

But, I'm inclined to agree with you. It's just disappointing is all. I've been fighting with this for a few days now and whenever I think I've figured something out, I discover a new limitation. I even tried this gem:

Code:
def test1 = if (buylong and !isNan(EntryPrice())) then open else test1[1];

I was confident this would work but apparently, even when an order is already in place, !isNan(EntryPrice()) won't consistently throw NaN or the price. The lack of consistency in how this function works is driving me mad 😅😅
 
Hey, on the brighter side, at least this issue has caused you to dig deeper into Thinkscript coding as a whole... That in itself is something I wish more people would consider...
 
Your thread effectively underscores the limitations of on-demand capabilities and the entryprice() function.

ThinkOrSwim remains one of the most advanced charting platforms for technical analysis. However, its tools for trade review, analysis, and portfolio management are notably limited. Users are often required to conduct comprehensive portfolio analysis outside of the platform due to these constraints.

Please note that this forum is not affiliated with Charles Schwab. For enhancement requests or functionality updates, contacting Schwab directly would be the recommended approach.

Hopefully, they will consider updates to better support this critical area.
 
Welp, I just confirmed with TOS the following:

I appreicate your patience. I can confirm that the entryprice() function will not work outside of the addorder() function. That value is unable to be plotted anywhere. I am afraid that is just a platform limitation. Nonetheless, I would be happy to pass along the interest in that feature working outside of addorder() functions. I do apolgoize for any inconvenience

I have another approach I'm going to try that I THINK will work. Will try and code it up this evening and report back. Wish me luck!
 
I figured it out!

Code:
def ep;

if (barNumber() == 1) {
    ep = 0;
} else {
    if (buytrig and ep[1] == 0) {
        ep = open[-1];
    } else if (selltrig) {
        ep = 0;
    } else {
        ep = ep[1];
    }
}

This will maintain the entry price so that more complex operations can be done on it to trigger the sell orders. This also prevents the value from being overridden if your buytrig activates again while still in a simulated trade.
 

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
295 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