rec usage is not allowed in this context (When trying to create an Alert)

T

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:
G

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);
 
T

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:

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;
 

Similar threads

Top