NexusFi: Find Your Edge


Home Menu

 





Rec usaged is not allowed in this context


Discussion in ThinkOrSwim

Updated
    1. trending_up 4,883 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
BombaFett
San Francisco, CA, USA
 
Posts: 2 since Jan 2017
Thanks Given: 0
Thanks Received: 0

Demigods,

I have the following code I use as a trailing stop loss:

 
Code
#ATR Stoploss
input Length = 20;
input ATRFactor = 3;
input AverageType = AverageType.WILDERS;

def HiLo = Min(high - low, 1.5 * Average(high - low, Length));
def HRef = if low <= High[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);

def TrueRange;
    TrueRange = Max(HiLo, Max(HRef, LRef));

def ATR = ATRFactor*MovingAverage(AverageType, TrueRange, Length);

def trail;
    if (close()[1] > trail[1]) {
    trail = Max(trail[1], close - ATR);
    } else {
    trail = Min(trail[1], close - ATR);
    }

plot TrailingStop = trail;
When I build a conditional sell order in the Study Order Condition screen, I set it up as the following:

 
Code
close crosses below ATRTrailingStop_UPTREND_v2()
My problem is, seemingly at random, I'll get an error message stating "rec usage is not allowed in this context". Twice now, I've built this study from scratch, testing to see if the order will pass with each change and it'll work, but then it seems as if it just decides it doesn't want to work anymore.

For example, I set the order up last night and it worked perfectly this morning. When I tied to setup my next order, I get the error message. What am I dong wrong? I'm stumped...HALP


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trump Media to sell instant access to market-moving soci …
Traders Hideout
No book, only a stair: journaling fills where price move …
Cryptocurrency
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
Datafeed for Atas
Platforms and Indicators
EA
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Mes vs MNQ
6 thanks
NexusFi site changelog and issues/problem reporting
5 thanks
BERN ALGOS algo trading journal
3 thanks
TopStep Trader disappointment
2 thanks
Johnnys Journal
2 thanks
  #2 (permalink)
jbalint
Madison WI
 
Posts: 1 since Jun 2017
Thanks Given: 2
Thanks Received: 0

your definition of trail references the previous value. this is called a recursive reference. according to the docs (at the very bottom here), this is not allowed in conditional orders: (add http colon slash slash) tlc.thinkorswim.com/center/howToTos/thinkManual/Trade/Order-Entry-Tools/conditionalorders.html


Reply With Quote
  #3 (permalink)
Tradin
Atlanta Georgia
 
Posts: 1 since Jul 2020
Thanks Given: 0
Thanks Received: 0


Is there a broker other than TOS/Ameritrade that will allow rec usage? Or were you able to find a work around? Trying to find someplace to use an ATR trailstop to close an open position automatically with a conditional/coded orders. I keep getting this recursive data not allowed message too, and I guess will need to switch to another broker that will if possible. Thanks in advance for any help


Reply With Quote




Last Updated on July 25, 2020


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts