• Get $40 off VIP by signing up for a free account! Sign Up

Suggestions for Renko with Donchian For ThinkOrSwim

JoeDV

Active member
VIP
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);

euMq7fi.png
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@JoeDV
What renko setting u r using for /es and /nq?
I've been playing around with 20 tick Renko but not crazy enough to actually trade based on something I threw together from here and there. I've actually moved on to the following, again, pieced together from various code found here and elsewhere. Mostly looking at micro Dow on 20 tick. Just learning so throwing things out there for suggestions.


Code:
input Corrlength = 10;
input MALength = 13;

input ShowTrades = no;
input ShowSignals = yes;

input BarsUsedForRange = 3;
input BarsRequiredToRemainInRange = 4;

def Zero = 0;

##### Consolidation - Flat ######################################
def HH = highest(high[1], BarsUsedForRange);
def LL = lowest(low[1], BarsUsedForRange);
def maxH = highest(hh, BarsRequiredToRemainInRange);
def maxL = lowest(ll, BarsRequiredToRemainInRange);
def HHn = if maxH == maxH[1] or maxL == maxL then maxH else HHn[1];
def LLn = if maxH == maxH[1] or maxL == maxL then maxL else LLn[1];
def Bh = if high <= HHn and HHn == HHn[1] then HHn else double.nan;
def Bl = if low >= LLn and LLn == LLn[1] then LLn else double.nan;
def CountH = if isnan(Bh) or isnan(Bl) then 2 else CountH[1] + 1;
def CountL = if isnan(Bh) or isnan(Bl) then 2 else CountL[1] + 1;
def ExpH = if barnumber() == 1 then double.nan else
            if CountH[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then HHn[-BarsRequiredToRemainInRange] else
            if High <= ExpH[1] then ExpH[1] else double.nan;
def ExpL = if barnumber() == 1 then double.nan else
            if Countl[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then LLn[-BarsRequiredToRemainInRange] else
            if Low >= ExpL[1] then ExpL[1] else double.nan;

plot BoxHigh = if !isnan(expL) and !isnan(ExpH) then ExpH else double.nan;
plot BoxLow = if !isnan(expL) and !isnan(ExpH) then ExpL else double.nan;

addcloud( BoxHigh, BoxLow, color.dark_gray, color.dark_gray);

def Flat = BoxHigh[1] and BoxLow[1];
#################################################


##### Correlation Trendflex ########################
def R = (WMA(close, Corrlength) - Average(close, Corrlength)) * (Corrlength + 1) /
(StDev(close, Corrlength) * Sqrt((Sqr(Corrlength) - 1) / 3));

def SlopeUp = (R > R[1]) and (R[1] > R[2]);
def SlopeDn = (R < R[1]) and (R[1] < R[2]);

AssignPriceColor(if SlopeUp then color.blue else if SlopeDn then color.plum else if SlopeUp[1] then color.blue else color.plum);
#################################################


##### Moving Average #####################
plot MAE = MovAvgExponential(Close, MALength, 0 , no);

#####################################################

##### Signals #########################

def BuySignal = ((R crosses above Zero and close is greater than MAE) OR (high is greater than high[1] and SlopeUp and R is greater than Zero)) and IsNan(Flat);
def SellSignal = ((R crosses below Zero and close is less than MAE) OR (high < high[1] and SlopeDn and R < Zero)) and IsNan(Flat);

def BuyStop = SlopeDn and close is less than MAE;
def SellStop = SlopeUp and close is greater than MAE;

def CurrPos;

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];
}
}


plot BS = BuySignal and (CurrPos[1] <> 1) and ShowSignals;    #### Buy and we're not already long
BS.SetDefaultColor(Color.CYAN);
BS.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
alert(BuySignal and (CurrPos[1] <> 1),”Renko BUY Alert”,alert.BAR);

plot SS = SellSignal and (CurrPos[1] <> -1) and ShowSignals;    #### Sell and we're not already short
SS.SetDefaultColor(Color.YELLOW);
SS.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
alert(SellSignal and (CurrPos[1] <> -1),”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(StopBuy and (CurrPos[1] == 1),”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(StopSell and (CurrPos[1] == -1),”Renko SELL STOP Alert”,alert.BAR);



addOrder(OrderType.BUY_TO_OPEN,BuySignal and CurrPos[1] <> 1 and ShowTrades, high,1);
addOrder(OrderType.SELL_TO_OPEN, SellSignal and CurrPos[1] <> -1 and ShowTrades, low, 1);
addOrder(OrderType.SELL_TO_CLOSE, BuyStop and CurrPos[1] == 1 and ShowTrades, low, 1);
addOrder(OrderType.BUY_TO_CLOSE, SellStop and CurrPos[1] == -1 and ShowTrades, high,1);

cyan=buy, yellow=sell, gray=stops

3WCo6qk.png
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
365 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top