Supertrend Conditional Order

T

Trendy_Trades

New member
Hello everyone :D I have been using a modified supertrend script, based off of the Mobius supertrend, but have not been able to get it properly set up for conditional orders. I have seen the issue with the recurrence in the script brought up in a few other posts, but am wondering if anyone has been able to figure out a fix? The error code that comes up is: "rec usage is not allowed in this context" which refers to the line: "def ST = if close < ST[1] then UP else DN;"


Here is the base supertrend script I have been using:

Code:
input AtrMult = .8;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);

def LW_Band_Basic = HL2 + (-AtrMult * ATR);

def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];

def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and close < ST

                then Color.RED

               else if PaintBars and close > ST

                    then Color.GREEN

                     else Color.CURRENT);

def bullish = close crosses below ST;
def bearish = close crosses above ST;

# Alerts
Alert(bullish, " ", Alert.Bar, Sound.Chimes);
Alert(bearish, " ", Alert.Bar, Sound.Bell);
# End Code SuperTrend

Thanks in advance for your time and help :D
 
rad14733

rad14733

Well-known member
VIP
You cannot use any code in conditional orders that utilizes recursion and I'm fairly certain that the error you are receiving is due to that limitation... Conditional orders can only process simple code, unfortunately...
 

Similar threads

Top