DefelRadar
New member
Hello All,
I have a custom ThinkScript code that I wrote that gives the dreaded orange triangle exclamation point whenever I try to add the buy and sell plots. It seems all happy up until the point I add the plots. I have read on the forum that in general a SuperTrend indicator and a indicator that repaints can lead to TOS flagging it as too complicated. I do have both of those in conditions in my code. I also have a second issue where I am using the sum() function to help me watch to see if my indicator that repaints has done so before I buy/sell. Sometimes that gives me buy/sells in the same candles due to my look back seeing a previous buy/sell signal. I tired where I could to use the built in functions/indicators, hoping that would make it less complicated. Below is the code:
The gist of the code is:
Buy: if I have a super trend indicator or OnBalance Volume MACD indicator or a Bollinger Band Breakout Indicator and I look back 10 bars and there is still the signalrevBot indicator (this one gets repainted).
Sell: if I look back 16 bars and the signaldown is still there (it gets repainted) and I have zero or one of these indicators present super trend indicator or OnBalance Volume MACD indicator or a Bollinger Band Breakout Indicator.
I use this on the 5min /GC futures chart and would like #1 get rid of the buy/sell "chop" that happens at times and #2 automate and test the buy entry/exits in paper trading which I need to get rid of the too complex desigination or find another way to automate in paper trading.
Thanks for your help!!
I have a custom ThinkScript code that I wrote that gives the dreaded orange triangle exclamation point whenever I try to add the buy and sell plots. It seems all happy up until the point I add the plots. I have read on the forum that in general a SuperTrend indicator and a indicator that repaints can lead to TOS flagging it as too complicated. I do have both of those in conditions in my code. I also have a second issue where I am using the sum() function to help me watch to see if my indicator that repaints has done so before I buy/sell. Sometimes that gives me buy/sells in the same candles due to my look back seeing a previous buy/sell signal. I tired where I could to use the built in functions/indicators, hoping that would make it less complicated. Below is the code:
Code:
## SuperTrend Code
input AtrMult = 3.0;
input nATR = 13.0;
input AvgType = AverageType.HULL;
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;
def SuperTrendActive = if close > ST then 1 else 0;
#OBVMACD Code
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
#plot OBV = TotalSum(Sign(close - close[1]) * volume);
def OBVM = reference OnBalanceVolume();
def Value = MovingAverage(averageType, OBVM, fastLength) - MovingAverage(averageType, OBVM, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
def OBVMACDBuySignal = Crosses(Value, Avg, CrossingDirection.ABOVE);
# Bollinger Band Breakout Strategy
# Define the length and standard deviation multiplier for the Bollinger Bands
input length = 20;
input numDev = 2.0;
## Check for a positive breakout
def breakout = BollingerBandsCrossover(length, numDev, "upper", "above", "SIMPLE").signal;
# AsGoodAsItGets Indicator without Arrows
#CSR Buy/Sell Arrows with Short/Long Bubbles
#Developed 4-9-22 First Edition 8-23-22 Revised
#No Arrow Edition 1/1/23
input atrreversal = 2.5;
def priceh = MovingAverage(AverageType.EXPONENTIAL, high, 5);
def pricel = MovingAverage(AverageType.EXPONENTIAL, low, 5);
def EIL = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastL;
def EIH = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastH;
input short_repaint_lookback = 16;
def signaldown = !IsNaN(EIH);
#AddChartBubble(signaldown, high + .15, "Short", Color.WHITE, yes);
def signaldownrepaint = if Sum(signaldown, short_repaint_lookback) then 1 else 0; #there is a short signal within the last 15 bars
input long_repaint_lookback = 10;
def signalrevBot = !IsNaN(EIL);
def signalrevBotrepaint = if Sum(signalrevBot, long_repaint_lookback) then 1 else 0; #there is a long signal within the last 15 bars
#AddChartBubble(signalrevBot, low - .55, "Long", Color.WHITE, no);
## Arrow Count
def ArrowCount;
if (OBVMACDBuySignal and SuperTrendActive and breakout ) {
ArrowCount = 3;
} else if ((SuperTrendActive == 1 and breakout == 1) or (OBVMACDBuySignal == 1 and SuperTrendActive == 1 ) or (OBVMACDBuySignal == 1 and breakout == 1)) {
ArrowCount = 2;
} else if (SuperTrendActive == 1 or OBVMACDBuySignal == 1 or breakout == 1) {
ArrowCount = 1;
} else {
ArrowCount = 0;
}
#trying to only buy/sell once per round trip buy sell trade
def test_buy = if signalrevBotrepaint == 1 and ArrowCount > 0 then 1 else 0;
def test_sell = if (signaldownrepaint and ArrowCount <= 1 and ArrowCount[1] >= 1) then 1 else 0;
def Hold_test_buy_Value = if test_buy then 1 else if !test_sell then Hold_test_buy_Value[1] else 0;
def Hold_test_sell_Value = if test_sell then 1 else if !test_buy then Hold_test_sell_Value[1] else 0;
def Signal_Buy = if test_buy and Hold_test_sell_Value[1] == 1 then 1 else 0;
#Signal_Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
def Signal_Sell = if test_sell and Hold_test_buy_Value[1] == 1 then 1 else 0;
#Signal_Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
### BUY BUY BUY
#def Buy = if Signal_Buy == 1 then 1 else 0;
#AddChartBubble(Buy, high + .15, "Buy", Color.Green, yes);
plot Buy = if Signal_Buy then low + .15 else double.NaN;;
Buy.setPaintingStrategy(PaintingStrategy.ARROW_UP);
Buy.setLineWeight(3);
#SELL SELL SELL
def Sell_Sig = if Signal_Sell == 1 then 1 else Double.NaN;
plot SellSig = if Sell_Sig then high * 1.00015 else double.NaN;;
SellSig.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSig.setLineWeight(3);
The gist of the code is:
Buy: if I have a super trend indicator or OnBalance Volume MACD indicator or a Bollinger Band Breakout Indicator and I look back 10 bars and there is still the signalrevBot indicator (this one gets repainted).
Sell: if I look back 16 bars and the signaldown is still there (it gets repainted) and I have zero or one of these indicators present super trend indicator or OnBalance Volume MACD indicator or a Bollinger Band Breakout Indicator.
I use this on the 5min /GC futures chart and would like #1 get rid of the buy/sell "chop" that happens at times and #2 automate and test the buy entry/exits in paper trading which I need to get rid of the too complex desigination or find another way to automate in paper trading.
Thanks for your help!!