This is my first post, love this forum as I've tried to learn how to use ThinkScript. Looking for suggestions from some of you more senior scripters as to how I might improve this script I wrote (borrowing from various threads here and there) to come up with a Renko+Donchian strategy that I try to use on futures. Back testing is decent enough using my settings, but I put little to no faith in that.
Code:
##################################################
## Donchian setup for use with Renko Charts ##
## Using AwesomeOsc and MACD for validation ##
##################################################
input BandLength = 20;
input ShowSignals = yes;
def Awesome = AwesomeOscillator().AO;
def MACDVal = MACDHistogram().diff;
#### Create Donchian ####
plot upperBand = Highest(high[1], BandLength);
plot lowerBand = Lowest(low[1], BandLength);
plot middleBand = (upperBand + lowerBand) / 2;
upperBand.SetDefaultColor(Color.gray);
lowerBand.SetDefaultColor(Color.gray);
middleBand.SetDefaultColor(Color.dark_gray);
#### Signals ####
def SingleUp = high > high[1];
def SingleDn = high < high[1];
def DoubleUp = (high[1] > high[2]) and (high > high[1]);
def DoubleDn = (high[1] < high[2]) and (high < high[1]);
def TripleUp = (high[2] > high[3]) and(high[1] > high[2]) and (high > high[1]);
def TripleDn = (high[2] < high[3]) and(high[1] < high[2]) and (high < high[1]);
def BelowMD = high < middleBand;
def AboveMD = low > middleBand;
def BelowLB = high < lowerBand;
def AboveHB = low > upperBand;
def AwesomeUp = Awesome > Awesome[1];
def AwesomeDn = Awesome < Awesome[1];
def AwesomePos = Awesome > 0;
def AwesomeNeg = Awesome < 0;
def MACDPos = MACDVal > 0;
def MACDNeg = MACDVal < 0;
#### Variable to hold our position (Long/Short/Flat) ####
def CurrPos;
#### BuySignals ####
def BuySignal = (DoubleUp or AboveHB) and AwesomePos and MACDPos;
#### BuyStop Signals ####
def BuyStop = TripleDn or (high crosses below BelowMD) or (SingleDn and (high[1]==middleBand[1]));
#### SellSignals ####
def SellSignal = (DoubleDn or BelowLB) and AwesomeNeg and MACDNeg;
#### SellStop Signals ####
def SellStop = TripleUp or (low crosses above AboveMD) or (SingleUp and (low[1]==middleBand[1]));
if (BarNumber()==1) {
CurrPos = 0;
}else{
if CurrPos[1] == 0 { #### IF we're FLAT ####
If BuySignal {
CurrPos = 1;
} else if SellSignal {
CurrPos = -1;
} else {
CurrPos = CurrPos[1];
}
} else if CurrPos[1] == 1 { #### IF we're LONG ####
If SellSignal {
CurrPos = -1;
} else if BuyStop {
CurrPos = 0;
} else {
CurrPos = CurrPos[1];
}
} else if CurrPos[1] == -1 { #### IF we're SHORT ####
If BuySignal {
CurrPos = 1;
} else if SellStop {
CurrPos = 0;
} else {
CurrPos = CurrPos[1];
}
} else {
CurrPos = CurrPos[1];
}
}
#### Show signals and alert if Show Signals is turned on
plot BS = BuySignal and (CurrPos[1] <> 1) and ShowSignals; #### Buy and we're not already long
BS.SetDefaultColor(Color.UPTICK);
BS.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
alert(BuySignal and (CurrPos[1] <> 1 and ShowSignals),”Renko BUY Alert”,alert.BAR);
plot SS = SellSignal and (CurrPos[1] <> -1) and ShowSignals; #### Sell and we're not already short
SS.SetDefaultColor(Color.DOWNTICK);
SS.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
alert( SellSignal and (CurrPos[1] <> -1) and ShowSignals,”Renko SELL Alert”,alert.BAR);
plot StopBuy = BuyStop and CurrPOs[1]==1 and ShowSignals; #### Long and receive a stop
StopBuy.SetDefaultColor(Color.gray);
StopBuy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
alert( BuyStop and CurrPOs[1]==1 and ShowSignals,”Renko Buy Stop Alert”,alert.BAR);
plot StopSell = SellStop and CurrPOs[1]==-1 and ShowSignals; #### Short and we receive a stop
StopSell.SetDefaultColor(Color.gray);
StopSell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
alert( SellStop and CurrPOs[1]==-1 and ShowSignals,”Renko Sell Stop Alert”,alert.BAR);