ThinkorSwim 'rec usage is not allowed in this context' Alerts

Brady0524

New member
VIP
The thinkscript study I created and shared yesterday, I try to use it in setting alert. But was unable to do it. The "OK" button stayed grayed out and was not available for me to continue to the alert. Then I saw the following message: "rec usage is not allowed in this context"

I'm looking to set up Conditional Study Alerts found under MarketWatch tab. In particular I wish to use the Languerre RSI, along with a few other conditions, to trigger alert to phone. The problem is the Rec Coding. If you enter this L-RSI into the study alert tab you get the statement found in the title. I was wondering if there was a work around. Thanks.
 

BenTen

Administrative
Staff
VIP
I'm not sure if alerts generated by indicators will show up on the mobile app. I never experience such thing so I can't confirm it. Regarding the error, @markos is familiar with the L-RSI indicator, he might be able to help.
 

markos

Well-known member
VIP
Thanks @BenTen (y)

Hey @Brady0524 We can get this fixed. I will have to look into it when I get home tonight. There are a number of variations to this code.

In the meantime, please go to Tutorials and find the "how to guide for the RSI Laguerre indicator". Please read all the way down.

Next, open the studies that you are using, then copy and paste the whole code in here. Both the chart study and the scan study. Be sure to put
#??Code??# In front of each code before you post the reply.

You may need an updated code. For one reason or another ToS broke the RSI Lg scanner during a language upgrade last year.
In that vein, please insert this scan to see if it works or not with your current code.
 

tabla

New member
VIP
When trying to create a marketwatch alert for this indicator it gives an error - "rec usage not allowed in this context"
I assume it is because of BorS=GetValue(BorS,1);
How do I get around this?

What the indicator is doing is - paint only the 1st arrow in short-term trend.
if BorS is already at Buy signal, dont plot.
Only plot BoRs if was previously a Sell signal and now has changed direction to Buy.

Any ideas - how I can make this work so that I can create Marketwatch alerts?

I tried using a scanner for alerting - but it doesnt work (although GetValue doesnt generate an error when creating a scanner)

Appreciate your input!

Script below -

Code:
#declare lower;

input length = 10;
input breakoutLevel = -5;
input breakdownLevel = -95;


def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);

def WR = if result > 0 then 0 else result;
plot UpSignal = if Crosses(WR, breakoutLevel, CrossingDirection.ABOVE) then high else Double.NaN;
plot DownSignal = if Crosses(WR, breakdownLevel, CrossingDirection.BELOW) then high else Double.NaN;

def whichCondition = if UpSignal is true then 1
else if DownSignal is true then -1 else 0;

input offset = 0;
def BorS;
if 0 == 1
{
BorS=0;
}
else
{
  if WhichCondition == 0
  {  
  BorS=GetValue(BorS,1);
  }
  else
  {
  BorS=WhichCondition;
  }
}
plot BBB = if Crosses(WR, breakoutLevel, CrossingDirection.ABOVE) and (BorS==1 and GetValue(Bors,1) != 1) then low else Double.NaN ;

plot SSS = if Crosses(WR, breakdownLevel, CrossingDirection.BELOW) and (BorS==-1 and GetValue(Bors,1) != -1) then high else Double.NaN;

BBB.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BBB.SetDefaultColor(Color.YELLOW);
SSS.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SSS.SetDefaultColor(Color.PINK);
 
Last edited by a moderator:

MJJ3

New member
Hi,
I'm trying to create an alert that triggers when price crosses below the vwap. I keep getting the following error.

"rec usage is not allowed in this context"

I know this is due to my referencing a prior value but I don't know how to get around it. The thinkscript I am using is as follows.
Code:
close crosses below GtDailyVWAP()

Where the function GtDailyVWAP is:
Code:
def yyyyMmDd = GetYYYYMMDD();
def isPeriodRolled = if yyyyMmDd != yyyyMmDd[1] then 1 else 0;

def volumeSum;
def volumeVwapSum;
def volumeSumPrev;
def volumeVwapSumPrev;

volumeSumPrev = volumeSum[1];
volumeVwapSumPrev = volumeVwapSum[1];

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
} else {
    volumeSum = volumeSumPrev + volume;
    volumeVwapSum = volumeVwapSumPrev + volume * vwap;
}
def price = volumeVwapSum / volumeSum;

plot VWAP = price;

VWAP.SetDefaultColor(GetColor(0));
 

JabronLames

Member
VIP
I'm trying to manually set an alert for a chart I pulled up by navigating to..

=> Right Click Chart
=> Select 'Create Alert'
=> Select 'Price' Dropdown
• Select 'Study'
• Select 'Edit'...

The study I have loaded on my chart is below, it finds the distance form the current price to the ATR Trailing Stop as a %. I'm setting the 'alert' for when the price approaches the trailing stop.

Plot distanceToStop is less than VALUE.

When I set the condition for the study in the watchlist, I receive the error "Error Processing Script: No Such Study

Is anyone able to clue me in on what I'm doing wrong?

For reference to everyone here. You cannot create an alert based on a study with a REFERENCE(). Now that the alert has been re-created...there is a new error. yay.

rec usage is not allowed in this context

Any ideas what this means? TOS has little info on it....

Code:
# By Dan Dude
# ATR Trailing Stop - Chart Label
# Copyright forever
input price = close;

def ATR = reference ATRTrailingStop();

#def DistanceBetween = (Sqrt(Sqr(EMASlow / EMAFast))) / 100;

#def distanceToStop = (price / ATR - 1) * 100;

plot distanceToStop =  (Sqrt(Sqr(price / ATR - 1))) * 100;

#def distanceToStopInDollars=  (Sqrt(Sqr(price - ATR)));

input Labels = "Yes";


AddLabel(distanceToStop and yes, "ATR Dist. = " + asPercent(round(distanceToStop,2)), if distanceToStop > .35 then color.light_RED else color.light_green);

#AddLabel(distanceToStopInDollars and yes, "ATR Dist. = $" + asText(round(distanceToStopInDollars,2)), color.light_green);

**END
 

GhostNet117

New member
I am trying to create alerts for a the PSAR indicator of a stock inverting from bullish to bearish, but I cannot get it to work. Basically, selecting PSAR as a study alert does not work in ThinkOrSwim, even though you can use basically all other crossover studies for an alert. I copied the script think or swim provides into a custom script, but now and getting the error: c and I cannot figure out why. Any helpful assistance is appreciated. All I have done is embedded the PSAR indicator script inside of a PSAR crossover script.

Code:
#wizard input: crossingType
#wizard text: Inputs: acceleration factor:
#wizard input: accelerationFactor
#wizard text: acceleration limit:
#wizard input: accelerationLimit

input accelerationFactor = 0.02;
input accelerationLimit = 0.2;
input crossingType = {default Bearish, Bullish};

#Begin Embedded PSAR Script
script ParabolicScript {
input accelerationFactor = 0.02;
input accelerationLimit = 0.2;
Assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
Assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = low;
case short:
if (SAR[1] < high)
then {
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = extreme[1];
} else {
state = state.short;
if (low < extreme[1])
then {
acc = Min(acc[1] + accelerationFactor, accelerationLimit);
extreme = low;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = Max(Max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
}
case long:
if (SAR[1] > low)
then {
state = state.short;
acc = accelerationFactor;
extreme = low;
SAR = extreme[1];
} else {
state = state.long;
if (high > extreme[1])
then {
acc = Min(acc[1] + accelerationFactor, accelerationLimit);
extreme = high;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = Min(Min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
}
}
#End Embedded PSAR Script

plot parSAR = SAR;
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.SetDefaultColor(GetColor(5));
}
def sar = ParabolicScript(accelerationFactor = accelerationFactor, accelerationLimit = accelerationLimit);

plot signal = Crosses(sar, close, crossingType == crossingType.Bearish);

signal.DefineColor("Bullish", GetColor(5));
signal.DefineColor("Bearish", GetColor(6));
signal.AssignValueColor(if crossingType == crossingType.Bullish then signal.Color("Bullish") else signal.Color("Bearish"));

signal.SetPaintingStrategy(if crossingType == crossingType.Bullish
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);
 

Thebtrader

Member
VIP
Anyone know how to get around "rec usage is not allowed in this context" for a simple trailing stop for an alert or order?

This is the code I am using:

Code:
Input Discount = .6;
Input Starttime = 0945;
def SecondsPassed = SecondsfromTime(Starttime);
def TSTP = if SecondsPassed >0 then if (Close * (1-Discount/100)) < TSTP[1] then TSTP[1] else Close * (1-Discount/100) else 0;
plot TSTP1 = If Close crosses below TSTP then 1 else 0;
 

trade_coder

New member
I saw someone asked similar question quite a while back on other places, and it seemed to be a limitation of thinkscript. In fact, I have Study and Strategy that use alot of rec, and have been not able to setup email/sms alert for those Study/Strategy. Anyone knows if it is still a limitation of TOS, or has been resolved or some workaround?

I have some kind of silly "workaround" is to use the alert with sound, and wrote a small program to send me an email/sms when there is sound generated from the PC.

Wonder if there is a smarter way to solve the problem?
 

Similar threads

Top