Leledc Exhaustion Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
Leledc Exhaustion Bar is an indicator converted by @diazlaz for ThinkorSwim. It does a great job of pointing out when a trend may be coming to an end.

Some comments found on TradingView:

An Exhaustion Bar is a bar which signals the exhaustion of the trend in the current direction. In other words, an exhaustion bar is “A bar of the last seller” in case of a downtrend and “A bar of last buyer” in case of an uptrend. Having said that when a party cannot take the price further in their direction, naturally the other party comes in, takes charge and reverses the direction of the trend.

Note: This indicator does not repaint ;)

Luo4qxj.png


Q3ULsAL.png


thinkScript Code

Code:
#Leledc Exhaustion Port
#Joy_Bangla
#
#https://www.tradingview.com/script/pQv1kge2-Leledc-Exhaustion-V4/
#The Psychology
#Let's assume that we have a group of people, say 100 people who decide to go for a casual running.
#After running for a few KM's few of them will say “I am exhausted. I cannot run further”.
#They will quit running. After running further, another bunch of runners will say I am exhausted. I can’t run further
#and they also will quit running. This goes on and on and then there will be a stage where only a few will be left
#in the running. Now a stage will come where the last person left in the running will say am exhausted and he stops running.
#That means no one is left now in the running. This means all are exhausted in the running.
#
#The same way an exhaustion bar works. The reason is an exhaustion bar sometimes formed at almost tops and bottoms.
#
#Timeframe
#The exhaustion bars are found on all Time frames as a trend also exists on all Timeframes.
#However, as a thumb rule Higher the Time frame, higher will be the accuracy as well as the profitability.
#
#Trading the Leledec Exhaustion Bars
#I may trade as soon as it is shown on the chart.
#I may trade when price breaks the high/low of the bar depending on whether I am getting bullish or bearish signal
#I may trade when price breaks the high/low of the bar depending on whether I am getting bullish or bearish signal.
#I may also be looking to ensure the current volume is higher than the previous few
#(? how many?) bar volumes.
#
# Ported 2019.11.16
# Release 1.0
#

input maj_qual = 6;
input maj_len = 30;
input min_qual = 5;
input min_len = 5;

input showMajor = yes; #show major
input showMinor = no; #show minor

script lele {
    input qual = 6; #default major
    input len = 30; #default major

    def bIndex = CompoundValue(1,
     if (bIndex[1] > qual) and (close < open) and high >= Highest(high, len) then 0 else
     if (close > close[4]) then bIndex[1] + 1 else bIndex[1]
    , 0);

    def sIndex = CompoundValue(1,
     if ((sIndex[1] > qual) and (close > open) and (low <= Lowest(low, len))) then 0 else
     if (close < close[4]) then sIndex[1] + 1 else sIndex[1]
    , 0);

    def ret =
     if (bIndex[1] > qual) and (close < open) and high >= Highest(high, len) then -1 else
     if ((sIndex[1] > qual) and (close > open) and (low <= Lowest(low, len))) then 1
    else 0;

    plot sData = ret;
}

#PLOTS

def major = lele(maj_qual,maj_len);

plot pUP = major == 1;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);

plot pDown = major == -1;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);

# Alerts
Alert(pUP, " ", Alert.Bar, Sound.Chimes);
Alert(pDown, " ", Alert.Bar, Sound.Bell);
 
Last edited:

Jenny

New member
Hi Ben

Thanks for sharing. Looks interesting especially when it doenst repaint . Can you help by adding an audio alert on the arrows? Thanks !
 

horserider

Well-known member
VIP
Some of the code is not used. Took it out.

Code:
input maj_qual = 6;
input maj_len = 30;


script lele {
    input qual = 6; #default major
    input len = 30; #default major

    def bIndex = CompoundValue(1,
     if (bIndex[1] > qual) and (close < open) and high >= Highest(high, len) then 0 else
     if (close > close[4]) then bIndex[1] + 1 else bIndex[1]
    , 0);

    def sIndex = CompoundValue(1,
     if ((sIndex[1] > qual) and (close > open) and (low <= Lowest(low, len))) then 0 else
     if (close < close[4]) then sIndex[1] + 1 else sIndex[1]
    , 0);

    def ret =
     if (bIndex[1] > qual) and (close < open) and high >= Highest(high, len) then -1 else
     if ((sIndex[1] > qual) and (close > open) and (low <= Lowest(low, len))) then 1
    else 0;

    plot sData = ret;
}

#PLOTS

def major = lele(maj_qual,maj_len);

plot pUP = major == 1;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);

plot pDown = major == -1;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);
 

MatthewA

Active member
input maj_qual = 12;#6
input maj_len = 45;#30
script lele {
input qual =12; #6 default major
input len = 45; #30 default major

I am finding the above a little more dependable on the 1 minute timeline

Also the authors mentioned a NO SUPPLY NO DEMAND indicator that I am guessing from their statements elsewhere they are using alongside this indicator. I bet it is like a hangtime of sorts. https://www.abundancetradinggroup.com/nsnd-mt4-indicator/ I bet that removes false positives from the exhaustion

They crowdsourced this work amongst tradeview and mt4 communities. They sell other unrelated scripts. I will get mt4 or a file opener later unless someone else who already has mt4 could post the code?
 
Last edited by a moderator:

zeek

Active member
2019 Donor
The NSND (no supply no demand) indicator above looks really interesting. Can anyone try convert this to TOS?
 

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
@MattATM Here is the source code:

Code:
            //+------------------------------------------------------------------+
//|                                                  NSNDHistory.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern int barcount=500;
extern int NSNDcount=10;
string comment[10];
static int prevtime=0;
static int prevfirstbar=0;
static double prevpricemax=0;
#property indicator_buffers 2
#property indicator_chart_window
#property indicator_color1  clrRed     
#property indicator_color2  clrYellow 
double CandleLowArrow[],CandleHighArrow[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------0-----------------------------+
int init()
  {
//---- indicators
f_clear();
  SetIndexBuffer(0,CandleLowArrow);
   SetIndexStyle(0,DRAW_ARROW,0,1,indicator_color1);
   SetIndexArrow(0,241);
   SetIndexBuffer(1,CandleHighArrow);
   SetIndexStyle(1,DRAW_ARROW,0,1,indicator_color2);
   SetIndexArrow(1,242);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   f_clear();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   int    counted_bars=IndicatorCounted();
   string Bull_or_Bear,obj_nameND;
   bool Low_Volume,Pins,Bear_Close_Below,Bull_Close_Above,Bear_Close_Above,Bull_Close_Below;
   string label;
   double chartheight=WindowPriceMax()-WindowPriceMin();
   double addhigh=6.00/100.00*chartheight;
//   Comment(WindowFirstVisibleBar(),"  ",prevfirstbar);
//----
  if(WindowFirstVisibleBar()!=prevfirstbar)
  {
   prevtime=0;
  }
  if(WindowPriceMax()!=prevpricemax)
  {
   prevtime=0;
  }
 
  if(Time[0]!=prevtime) // | prevfirstbar!=WindowFirstVisibleBar())// && 11==2)
  {
   f_clear();
  //for(int i=barcount;i>=1;i--)
   for(int i=WindowFirstVisibleBar();i>=WindowFirstVisibleBar()-500 && i>0 ;i--)
   {
    Bull_or_Bear=f_Bull_or_Bear(i);
    Low_Volume=f_Low_Volume(i);
    Pins=f_Pins(i,Bull_or_Bear);
  //  Comment(Bull_or_Bear," Low Volume ",Low_Volume,"  Pins ",Pins );
    Bear_Close_Below=false;
    Bear_Close_Above=false;
    Bull_Close_Above=false;
    Bull_Close_Below=false;
    int true_count=0;
    for(int ix=i;ix>i-NSNDcount && ix>0;ix--)
    {
     if(true_count<1)
      {
       if(Bull_or_Bear=="Bull" && Close[ix]>High[i] && !Bear_Close_Below)
       {
         Bull_Close_Above=true;
         true_count++;
       }
       if(Bull_or_Bear=="Bull" && Close[ix]<Low[i] && !Bear_Close_Above)
       {
         Bull_Close_Below=true;
         true_count++;
       }
       if(Bull_or_Bear=="Bear" && Close[ix]<Low[i] && !Bear_Close_Above)
       {
         Bear_Close_Below=true;
         true_count++;
       }
       if(Bull_or_Bear=="Bear" && Close[ix]>High[i] && !Bear_Close_Below)
       {
         Bear_Close_Above=true;
         true_count++;
       }
       }

    }//end for ix 
    label=TimeYear(Time[i])+DoubleToStr(TimeMonth(Time[i]),0)+DoubleToStr(TimeDay(Time[i]),0);
    label=label+DoubleToStr(TimeHour(Time[i]),0)+DoubleToStr(TimeMinute(Time[i]),0); 
    if(Bull_or_Bear=="Bull" && Low_Volume && Pins && !Bull_Close_Above && Bull_Close_Below)
    {
      obj_nameND="No Demand - "+i+" - "+label;
      CandleHighArrow[i]=(High[i]+0.00010);
      
    }
    if(Bull_or_Bear=="Bear" && Low_Volume && Pins && !Bear_Close_Below  && Bear_Close_Above)
    {
       CandleLowArrow[i]=(Low[i]-0.00010);

    }
    
   }//end for i
   prevtime=Time[0];
   prevfirstbar=WindowFirstVisibleBar();
   prevpricemax=WindowPriceMax();
   }//endif if prevtime
//----

   return(0);
  }
 
string f_Bull_or_Bear(int i)
{
 string retvar;
    if(Open[i]>Close[i])
   {
       retvar="Bear";
       comment[i]=comment[i]+"Bear ";
   }
   if(Close[i]>Open[i])
   {
    retvar="Bull";
    comment[i]=comment[i]+"Bull ";
   }
 return(retvar);
}

bool f_Low_Volume(int i)
{
  bool retvar=False;
     if(Volume[i]<Volume[i+1] && Volume[i]<Volume[i+2])
     {
       retvar=True;
       comment[i]=comment[i]+"Low Vol ";
    }
 return(retvar);
}

bool f_Pins(int i,string Bull_or_Bear)
{
  bool Pins=false;
  double pip=Point*1;
  bool retval;
  if(Bull_or_Bear=="Bear" && High[i]>Open[i]+pip && Low[i]<Close[i]-pip)
  {
    retval=true;
    comment[i]=comment[i]+" Pins";
  }
  if(Bull_or_Bear=="Bull" && High[i]>Close[i]+pip && Low[i]<Open[i]-pip)
  {
    retval=true;
    comment[i]=comment[i]+" Pins";
  }
  return(retval);
}

void f_clear()
{
  for (int i=ObjectsTotal(); i>0; i--)
 
 {
   if(StringSubstr(ObjectName(i),0,2)=="No")
   {
    ObjectDelete(ObjectName(i));
   }
 }
   for (i=ObjectsTotal(); i>0; i--)
 
 {
   if(StringSubstr(ObjectName(i),0,2)=="No")
   {
    ObjectDelete(ObjectName(i));
   }
 }
}
//+------------------------------------------------------------------+
 

jhorton56

Member
VIP
input maj_qual = 12;#6
input maj_len = 45;#30
script lele {
input qual =12; #6 default major
input len = 45; #30 default major

I am finding the above a little more dependable on the 1 minute timeline

Also the authors mentioned a NO SUPPLY NO DEMAND indicator that I am guessing from their statements elsewhere they are using alongside this indicator. I bet it is like a hangtime of sorts. https://www.abundancetradinggroup.com/nsnd-mt4-indicator/ I bet that removes false positives from the exhaustion

They crowdsourced this work amongst tradeview and mt4 communities. They sell other unrelated scripts. I will get mt4 or a file opener later unless someone else who already has mt4 could post the code?
Matt, did you replace the similar code in the study, or add this piece of code to the study?
 

Jenny

New member
Thanks @BenTen and @diazlaz on the above. I am just trying out on a 10 mins /ES to see how well it works. @BenTen, or anyone who can help with coding ..

can you help to convert it the above exhaustion bar into strategy whereby an entry ( either long or short) whenever the arrows complete the bar and to exit with a 4 points ? I would like to see if the report generated makes sense...Thanks a lot!
 

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
@Jenny Here is a simple backtesting strategy of the indicator. Not precisely the buy and sell condition you want, but it's a good start if you want to modify it to fit your needs.
  • Go long = up arrow
  • Exit position = down arrow
Code:
# Basic backtesting strategy for Leledc Exhaustion
# Ported to ThinkorSiwm by @diazlaz

input maj_qual = 6;
input maj_len = 30;
input min_qual = 5;
input min_len = 5;

input showMajor = yes; #show major
input showMinor = no; #show minor

script lele {
    input qual = 6; #default major
    input len = 30; #default major

    def bIndex = CompoundValue(1,
     if (bIndex[1] > qual) and (close < open) and high >= Highest(high, len) then 0 else
     if (close > close[4]) then bIndex[1] + 1 else bIndex[1]
    , 0);

    def sIndex = CompoundValue(1,
     if ((sIndex[1] > qual) and (close > open) and (low <= Lowest(low, len))) then 0 else
     if (close < close[4]) then sIndex[1] + 1 else sIndex[1]
    , 0);

    def ret =
     if (bIndex[1] > qual) and (close < open) and high >= Highest(high, len) then -1 else
     if ((sIndex[1] > qual) and (close > open) and (low <= Lowest(low, len))) then 1
    else 0;

    plot sData = ret;
}

#PLOTS

def major = lele(maj_qual,maj_len);

plot pUP = major == 1;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);

plot pDown = major == -1;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);

AddOrder(OrderType.BUY_TO_OPEN, condition = pUP, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, condition = pDown, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Cover");
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
178 Online
Create Post

Similar threads

Similar threads

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.
Top