Confirmation Candles Indicator For ThinkorSwim

Just added 2 new strategies on pg.1 of the thread. The first is based on Ehler's Distant Coefficient Filter.
UHyFOuD.png

The second strategy is based off of the HiLo study.
x6GHOYa.png

Both strategies are adjustable. I hope everyone finds them useful. Happy trading!
Fantastic work! Many Thanks for your contribution. Cannot wait to try it.
 

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

@Christopher84 thanks again for your ideas, I checked the Ehlers Distance Coefficient out, on Tradingview they use 15 period, and when I use that with a NQ 10 min chart on TOS, I get a pretty good return. Have to see if there is repaint, but will test it further.
 
@Christopher84, good things happen when you and Mr Ehlers agree 😀. The setup I used this morning was your Ehlers Distance Coefficient Filter 35 period with a little coding for color. Then I color coded candles for the 10 period Ehlers DCF (love my Scalper 10/35 EMAs!) I also plotted a histo with consensusR, consensusBias, and direction formulas from your Scalper. The result is that I went 3 for 3 even though I'm not sure I have Ehlers scaled quite properly in EL.

If it's hard to visualize my setup, here it is on a 2 min cattle chart. Can you see why I plot your consensus data? Every bit of it was in confluence with Ehlers to go short at the open. And your consensus remained heavily biased to the downside during what turned out to be a pullback not a trend change. That's another reason it's so valuable.



Thank you again for sharing your talent with us!
 
@Christopher84, good things happen when you and Mr Ehlers agree 😀. The setup I used this morning was your Ehlers Distance Coefficient Filter 35 period with a little coding for color. Then I color coded candles for the 10 period Ehlers DCF (love my Scalper 10/35 EMAs!) I also plotted a histo with consensusR, consensusBias, and direction formulas from your Scalper. The result is that I went 3 for 3 even though I'm not sure I have Ehlers scaled quite properly in EL.

If it's hard to visualize my setup, here it is on a 2 min cattle chart. Can you see why I plot your consensus data? Every bit of it was in confluence with Ehlers to go short at the open. And your consensus remained heavily biased to the downside during what turned out to be a pullback not a trend change. That's another reason it's so valuable.



Thank you again for sharing your talent with us!
Nice work to @Christopher84 as usual!!! Great touch on the new set up Trader Raider! I just loaded the Ehlers as well and it's pretty solid on the 2m as is. Would you be able to share your adjustments via link? Thanks so much!!!
 
I just loaded the Ehlers as well and it's pretty solid on the 2m as is. Would you be able to share your adjustments via link? Thanks so much!!!
Indeed, I like it on the 2 min too! Apologies but I can't do anything in thinkscript except comment out labels and alerts. The changes I made were in easyLanguage and I'm not even sure I did it correctly. Color changes were simply plotting red if < 0 and green if above.
 
Indeed, I like it on the 2 min too! Apologies but I can't do anything in thinkscript except comment out labels and alerts. The changes I made were in easyLanguage and I'm not even sure I did it correctly. Color changes were simply plotting red if < 0 and green if above.
No worries! Thanks for the tips!
 
Just added 2 new strategies on pg.1 of the thread. The first is based on Ehler's Distant Coefficient Filter.
UHyFOuD.png

The second strategy is based off of the HiLo study.
x6GHOYa.png

Both strategies are adjustable. I hope everyone finds them useful. Happy trading!
Ehler's Distant Coefficient Filter is incredible. I did some backtest in TOS by the modified CODE as follows.
15Min,10Min,5Min, in 90Days. the code is just copied. it's not by me.

ETfPhjv.jpg
sWBBZ9v.jpg

QwT0ZYj.jpg


Code:
#Ehler's Distant Coefficient Filter Strategy Created by Christopher84 05/17/2022
input length = 34;
input coloredCandlesOn = yes;
def price = (high + low) / 2;

def coeff = length * price * price - 2 * price * sum(price, length)[1] + sum(price * price, length)[1];

plot Ehlers = sum(coeff * price, length) / sum(coeff, length);
Ehlers.SetDefaultColor(GetColor(1));

def UP1 = (Price > Ehlers);
def DN1 = (Price < Ehlers);

#Condition Calculation
def UPBias = UP1;
def DNBias = DN1;
def Direction = UPBias - DNBias;

AssignPriceColor(if coloredCandlesOn and ((Direction > 0)) then Color.GREEN else if coloredCandlesOn and ((Direction < 0)) then Color.RED else Color.GRAY);

def bull= (Direction > 0);#(price crosses above BuyStop);
def bear =  (Direction < 0);#(Price crosses below BuyStop);

def upsignal = bull;
def downsignal = bear;
#UpSignal.SetDefaultColor(Color.UPTICK);
#UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#DownSignal.SetDefaultColor(Color.DOWNTICK);
#DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

###------------------------------------------------------------------------------------------
# Profit and Loss Labels
#
# Fill in the 0>0 in the Create Signals section below to match your buy and sell signal conditions
#
# When using large amounts of hisorical data, P/L may take time to calculate
###------------------------------------------------------------------------------------------

input showSignals = yes; #hint showSignals: show buy and sell arrows
input LongTrades = yes; #hint LongTrades: perform long trades
input ShortTrades = yes; #hint ShortTrades: perform short trades
input showLabels  = yes; #hint showLabels: show PL labels at top
input showBubbles = yes; #hint showBubbles: show PL bubbles at close of trade
input useStops = no;     #hint useStops: use stop orders
input useAlerts = no;    #hint useAlerts: use alerts on signals
input tradeDaytimeOnly = no; #hint tradeDaytimeOnly: (IntraDay Only) Only perform trades during hours stated
input OpenTime = 0930; #hint OpenTime: Opening time of market
input CloseTime = 1600; #hint CloseTime: Closing time of market


def Begin = secondsfromTime(OpenTime);
def End = secondsTillTime(closetime);
# Only use market hours when using intraday timeframe
def isIntraDay = if getaggregationperiod() > 14400000 or getaggregationperiod()==0 then 0 else 1;
def MarketOpen = if !tradeDaytimeOnly or !isIntraDay then 1 else if tradeDaytimeOnly and isIntraDay and Begin > 0 and End > 0 then 1 else 0;
###------------------------------------------------------------------------------------------

######################################################
##  Create Signals -
##  FILL IN THIS SECTION
##      replace 0>0 with your conditions for signals
######################################################

def PLBuySignal = if  MarketOpen AND (upsignal) then 1 else 0 ; # insert condition to create long position in place of the 0>0
def PLSellSignal =  if MarketOpen AND (downsignal) then 1 else 0; # insert condition to create short position in place of the 0>0

def PLBuyStop  = if !useStops then 0 else if  (0>0) then 1 else 0  ; # insert condition to stop in place of the 0<0
def PLSellStop = if !useStops then 0 else if (0>0) then 1 else 0  ; # insert condition to stop in place of the 0>0

def PLMktStop = if MarketOpen[-1] == 0 then 1 else 0; # If tradeDaytimeOnly is set, then stop at end of day


#######################################
##  Maintain the position of trades
#######################################

def CurrentPosition;  # holds whether flat = 0 long = 1 short = -1

if (BarNumber()==1) OR isNaN(CurrentPosition[1]) {
    CurrentPosition = 0;
}else{
        if CurrentPosition[1] == 0 {            # FLAT
            if (PLBuySignal AND LongTrades) {
                CurrentPosition = 1;
            } else if (PLSellSignal AND ShortTrades){
                CurrentPosition = -1;
            } else {
                CurrentPosition = CurrentPosition[1];
            }
       } else if CurrentPosition[1] == 1 {      # LONG
            if (PLSellSignal AND ShortTrades){
                CurrentPosition = -1;
            } else if ((PLBuyStop and useStops) or PLMktStop or (PLSellSignal AND ShortTrades==0)){
                CurrentPosition = 0;
            } else {
                CurrentPosition = CurrentPosition[1];
            }
       } else if CurrentPosition[1] == -1 {     # SHORT
            if (PLBuySignal AND LongTrades){
                CurrentPosition = 1;
            } else if ((PLSellStop and useStops) or PLMktStop or (PlBuySignal and LongTrades==0)){
                CurrentPosition = 0;
            } else {
                CurrentPosition = CurrentPosition[1];
            }
       } else {
            CurrentPosition = CurrentPosition[1];
       }
}


def isLong  = if CurrentPosition == 1 then 1 else 0;
def isShort = if CurrentPosition == -1 then 1 else 0;
def isFlat  = if CurrentPosition == 0 then 1 else 0;

# If not already long and get a PLBuySignal
#Plot BuySig = if (!isLong[1] and PLBuySignal and showSignals and LongTrades) then 1 else 0;
Plot BuySig = if (((isShort[1] and LongTrades) or (isFlat[1] and LongTrades)) and PLBuySignal and showSignals) then 1 else 0;
BuySig.AssignValueColor(color.cyan);
BuySig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySig.SetLineWeight(5);

Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);
Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);

# If not already short and get a PLSellSignal
Plot SellSig = if (((isLong[1] and ShortTrades) or (isFlat[1] and ShortTrades)) and PLSellSignal and showSignals) then 1 else 0;
SellSig.AssignValueColor(color.cyan);
SellSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSig.SetLineWeight(5);

Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Ding);
Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Ding);

# If long and get a PLBuyStop
Plot BuyStpSig = if (PLBuyStop and isLong[1] and showSignals and useStops) or (isLong[1] and PLMktStop) or (isLong[1] and PLSellSignal and !ShortTrades) then 1 else 0;
BuyStpSig.AssignValueColor(color.light_gray);
BuyStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BuyStpSig.SetLineWeight(3);

Alert(BuyStpSig and useAlerts, "Buy Stop Signal",Alert.bar,sound.Ding);
Alert(BuyStpSig and useAlerts, "Buy Stop Signal",Alert.bar,sound.Ding);


# If short and get a PLSellStop
Plot SellStpSig = if (PLSellStop and isShort[1] and showSignals and useStops) or (isShort[1] and PLMktStop) or (isShort[1] and PLBuySignal and !LongTrades) then 1 else 0;
SellStpSig.AssignValueColor(color.light_gray);
SellStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SellStpSig.SetLineWeight(3);

Alert(SellStpSig and useAlerts, "Sell Stop Signal",Alert.bar,sound.Ding);
Alert(SellStpSig and useAlerts, "Sell Stop Signal",Alert.bar,sound.Ding);


#######################################
##  Orders
#######################################

def isOrder = if ((isFlat[1] and (BuySig and LongTrades) or (SellSig and ShortTrades)) or (isLong[1] and BuyStpSig or (SellSig and ShortTrades)) or (isShort[1] and SellStpSig or (BuySig and LongTrades))) then 1 else 0 ;
# If there is an order, then the price is the next days close
def orderPrice = if (isOrder and ((BuySig and LongTrades) or (SellSig and ShortTrades))) then close else orderPrice[1];

def orderCount = compoundValue(1,if isNan(isOrder) or barnumber()==1 then 0 else if (BuySig or SellSig) then orderCount[1]+1 else orderCount[1],0);


#######################################
##  Price and Profit
#######################################

def profitLoss;


if (!isOrder or orderPRice[1]==0){
    profitLoss = 0;
} else if ((isOrder and isLong[1]) and (SellSig or BuyStpSig)){
    profitLoss = close - orderPrice[1];
} else if ((isOrder and isShort[1]) and (BuySig or SellStpSig)) {
    profitLoss = orderPrice[1] - close;
} else {
    profitLoss = 0;
}


# Total Profit or Loss
def profitLossSum = compoundValue(1, if isNaN(isOrder)  or barnumber()==1 then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);

# How many trades won or lost
def profitWinners = compoundValue(1, if isNaN(profitWinners[1]) or barnumber()==1 then 0 else if isOrder and profitLoss > 0 then profitWinners[1] + 1 else profitWinners[1], 0);
def profitLosers = compoundValue(1, if isNaN(profitLosers[1])  or barnumber()==1 then 0 else if isOrder and profitLoss < 0 then profitLosers[1] + 1 else profitLosers[1], 0);
def profitPush = compoundValue(1, if isNaN(profitPush[1])  or barnumber()==1 then 0 else if isOrder and profitLoss == 0 then profitPush[1] + 1 else profitPush[1], 0);

# Current Open Trade Profit or Loss
def TradePL = If isLong then Round(((close - orderprice)/TickSize())*TickValue()) else if isShort then Round(((orderPrice - close)/TickSize())*TickValue()) else 0;

# Convert to actual dollars based on Tick Value for bubbles
def dollarProfitLoss = if orderPRice[1]==0 or isNaN(orderPrice[1]) then 0 else round((profitLoss/Ticksize())*Tickvalue());

# Closed Orders dollar P/L
def dollarPLSum = round((profitLossSum/Ticksize())*Tickvalue());


# Split profits or losses by long and short trades
def profitLong = compoundValue(1, if isNan(profitLong[1])  or barnumber()==1 then 0 else if isOrder and isLong[1] then profitLong[1]+dollarProfitLoss else profitLong[1],0);
def profitShort = compoundValue(1, if isNan(profitShort[1])  or barnumber()==1 then 0 else if isOrder and isShort[1] then profitShort[1]+dollarProfitLoss else profitShort[1],0);
def countLong = compoundValue(1, if isNaN(countLong[1])  or barnumber()==1 then 0 else if isOrder and isLong[1] then countLong[1]+1 else countLong[1],0);
def countShort = compoundValue(1, if isNaN(countShort[1])  or barnumber()==1 then 0 else if isOrder and isShort[1] then countShort[1]+1 else countShort[1],0);

# What was the biggest winning and losing trade
def biggestWin = compoundValue(1, if isNaN(biggestWin[1]) or barnumber()==1 then 0 else if isOrder and (dollarProfitLoss > 0) and (dollarProfitLoss > biggestWin[1]) then dollarProfitLoss else biggestWin[1], 0);
def biggestLoss = compoundValue(1, if isNaN(biggestLoss[1]) or barnumber()==1 then 0 else if isOrder and (dollarProfitLoss < 0) and (dollarProfitLoss < biggestLoss[1]) then dollarProfitLoss else biggestLoss[1], 0);

def ClosedTradeCount = if (isLong or isShort) then orderCount-1 else orderCount;
def OpenTrades = if (isLong or isShort) then 1 else 0;


# What percent were winners
def PCTWin = if (OpenTrades and (TradePL < 0)) then round((profitWinners/(ClosedTradeCount+1))*100,2)
else if (OpenTrades and (TradePL > 0)) then round(((profitWinners+1)/(ClosedTradeCount+1))*100,2) else round(((profitWinners)/(ClosedTradeCount))*100,2) ;

# Average trade
def avgTrade = if (OpenTrades and (TradePL < 0)) then round(((dollarPLSum - TradePL)/(ClosedTradeCount+1)),2)
else if (OpenTrades and (TradePL > 0)) then round(((dollarPLSum + TradePL)/(ClosedTradeCount+1)),2) else round(((dollarPLSum)/(ClosedTradeCount)),2) ;


#######################################
##  Create Labels
#######################################


AddLabel(showLabels and isIntraDay, if MarketOpen then "Market Open" else "Market Closed", color.white);
AddLabel(showLabels, GetSymbol()+" Tick Size: "+TickSize()+" Value: "+TickValue(), color.white);
AddLabel(showLabels and (LongTrades and ShortTrades), "Long+Short Trades", color.white);
AddLabel(showLabels and (LongTrades and !ShortTrades),"Long Trades Only", color.white);
AddLabel(showLabels and (!LongTrades and ShortTrades),"Short Trades Only", color.white);
AddLabel(showLabels, "Closed Orders: " + ClosedTradeCount + " P/L: " + AsDollars(dollarPLSum), if dollarPLSum > 0 then Color.GREEN else if dollarPLSum< 0 then Color.RED else Color.GRAY);
AddLabel(if !IsNan(orderPrice) and showLabels then 1 else 0, "Closed+Open P/L: "+ AsDollars(TradePL+dollarPLSum), if ((TradePL+dollarPLSum) > 0) then color.green else if ((TradePL+dollarPLSum) < 0) then color.red else color.gray);

AddLabel(showLabels, "Avg per Trade: "+ AsDollars(avgTrade), if avgTrade > 0 then Color.Green else if avgTrade < 0 then Color.RED else Color.GRAY);
AddLabel(showLabels, "Winners: "+ PCTWin +"%",if PCTWin > 50 then color.green else if PCTWin > 40 then color.yellow else color.gray);

AddLabel(showLabels, "MaxUp: "+ AsDollars(biggestWin) +" MaxDown: "+AsDollars(biggestLoss), color.white);
AddLabel(showLabels, "Long Profit: " +AsDollars(profitLong), if profitLong > 0 then color.green else if profitLong < 0 then color.red else color.gray);
AddLabel(showLabels, "Short Profit: " +AsDollars(profitShort), if profitShort > 0 then color.green else if profitShort < 0 then color.red else color.gray);
AddLabel(if !IsNan(CurrentPosition) and showLabels and OpenTrades then 1 else 0, "Open: "+ (If isLong then "Bought" else "Sold") + " @ "+orderPrice, color.white);
AddLabel(if !IsNan(orderPrice) and showLabels and OpenTrades then 1 else 0, "Open Trade P/L: "+ AsDollars(TradePL), if (TradePL > 0) then color.green else if (TradePl < 0) then color.red else color.gray);



#######################################
##  Chart Bubbles for Profit/Loss
#######################################


AddChartBubble(showSignals and showBubbles and isOrder and isLong[1], low, "$"+dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else color.Red, 0);
AddChartBubble(showSignals and showBubbles and isOrder and isShort[1], high,  "$"+dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else color.Red, 1);

#AssignPriceColor(if CurrentPosition == 1 then color.green else if CurrentPosition == -1 then color.red else color.gray);
.
 

Attachments

  • ETfPhjv.jpg
    ETfPhjv.jpg
    185 KB · Views: 283
Last edited by a moderator:
I want to change "Ehler's Distant Coefficient Filter Strategy" to study. But I have some problems with coding. I am not sure the following code is correct. Can anyone help me fix it, thanks.

Code:
#Ehler's Distant Coefficient Filter Strategy Created by Christopher84 05/17/2022
input length = 34;
input coloredCandlesOn = yes;
def price = (high + low) / 2;

def coeff = length * price * price - 2 * price * sum(price, length)[1] + sum(price * price, length)[1];

plot Ehlers = sum(coeff * price, length) / sum(coeff, length);
Ehlers.SetDefaultColor(GetColor(1));

def UP1 = (Price > Ehlers);
def DN1 = (Price < Ehlers);

#Condition Calculation
def UPBias = UP1;
def DNBias = DN1;
def Direction = UPBias - DNBias;

AssignPriceColor(if coloredCandlesOn and ((Direction > 0)) then Color.GREEN else if coloredCandlesOn and ((Direction < 0)) then Color.RED else Color.GRAY);

def Long_Entry = (Direction > 0);#(price crosses above BuyStop);
def Long_Exit =  (Direction < 0);#(Price crosses below BuyStop);

def upsignal = Long_Entry;
def downsignal = Long_Exit;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
 
I want to change "Ehler's Distant Coefficient Filter Strategy" to study. But I have some problems with coding. I am not sure the following code is correct. Can anyone help me fix it, thanks.

Code:
#Ehler's Distant Coefficient Filter Strategy Created by Christopher84 05/17/2022
input length = 34;
input coloredCandlesOn = yes;
def price = (high + low) / 2;

def coeff = length * price * price - 2 * price * sum(price, length)[1] + sum(price * price, length)[1];

plot Ehlers = sum(coeff * price, length) / sum(coeff, length);
Ehlers.SetDefaultColor(GetColor(1));

def UP1 = (Price > Ehlers);
def DN1 = (Price < Ehlers);

#Condition Calculation
def UPBias = UP1;
def DNBias = DN1;
def Direction = UPBias - DNBias;

AssignPriceColor(if coloredCandlesOn and ((Direction > 0)) then Color.GREEN else if coloredCandlesOn and ((Direction < 0)) then Color.RED else Color.GRAY);

def Long_Entry = (Direction > 0);#(price crosses above BuyStop);
def Long_Exit =  (Direction < 0);#(Price crosses below BuyStop);

def upsignal = Long_Entry;
def downsignal = Long_Exit;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Hi @qimy6688,
Here EDCF_Candles as a study. I hope you find it useful!
XpH6Yqz.png

Code:
#Ehler's Distant Coefficient Filter Study Created by Christopher84 05/20/2022
input length = 34;
input coloredCandlesOn = yes;
input displace = 13;
def price = (high + low) / 2;

def coeff = length * price * price - 2 * price * sum(price, length)[1] + sum(price * price, length)[1];

plot Ehlers = sum(coeff * price, length) / sum(coeff, length);
#Ehlers.SetDefaultColor(GetColor(1));

def EhlersD = Ehlers [+displace];

def UP1 = (Price > Ehlers);
def DN1 = (Price < Ehlers);

#Condition Calculation
def UPBias = UP1;
def DNBias = DN1;
def Direction = UPBias - DNBias;

#AddCloud(Ehlers, EhlersD, Color.GREEN, Color.CURRENT);
#AddCloud(EhlersD, Ehlers, Color.RED, Color.CURRENT);

AssignPriceColor(if coloredCandlesOn and ((Direction > 0)) then Color.GREEN else if coloredCandlesOn and ((Direction < 0)) then Color.RED else Color.GRAY);

plot Long_Entry = (Direction crosses above 0);
Long_Entry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Long_Entry.SetLineWeight(3);
Long_Entry.AssignValueColor(Color.UPTICK);

plot Long_Exit =  (Direction crosses below 0);
Long_Exit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Long_Exit.SetLineWeight(3);
Long_Exit.AssignValueColor(Color.DOWNTICK);
 
Hi @qimy6688,
Here EDCF_Candles as a study. I hope you find it useful!
XpH6Yqz.png

Code:
#Ehler's Distant Coefficient Filter Study Created by Christopher84 05/20/2022
input length = 34;
input coloredCandlesOn = yes;
input displace = 13;
def price = (high + low) / 2;

def coeff = length * price * price - 2 * price * sum(price, length)[1] + sum(price * price, length)[1];

plot Ehlers = sum(coeff * price, length) / sum(coeff, length);
#Ehlers.SetDefaultColor(GetColor(1));

def EhlersD = Ehlers [+displace];

def UP1 = (Price > Ehlers);
def DN1 = (Price < Ehlers);

#Condition Calculation
def UPBias = UP1;
def DNBias = DN1;
def Direction = UPBias - DNBias;

#AddCloud(Ehlers, EhlersD, Color.GREEN, Color.CURRENT);
#AddCloud(EhlersD, Ehlers, Color.RED, Color.CURRENT);

AssignPriceColor(if coloredCandlesOn and ((Direction > 0)) then Color.GREEN else if coloredCandlesOn and ((Direction < 0)) then Color.RED else Color.GRAY);

plot Long_Entry = (Direction crosses above 0);
Long_Entry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Long_Entry.SetLineWeight(3);
Long_Entry.AssignValueColor(Color.UPTICK);

plot Long_Exit =  (Direction crosses below 0);
Long_Exit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Long_Exit.SetLineWeight(3);
Long_Exit.AssignValueColor(Color.DOWNTICK);
[/CODthanks
[/QUOTE]
thanks a lot, sir. I use this code and add some code(just copy from another thread ) for statistics. The code is as follows.
But I compare it with the original strategy CODE. there are huge differences.
do you have some ideas about my CODE ?

YiW8tCa.jpg

Sy7cx9H.jpg


Code:
#Ehler's Distant Coefficient Filter Study Created by Christopher84 05/20/2022
input length = 34;
input coloredCandlesOn = yes;
input displace = 13;
def price = (high + low) / 2;

def coeff = length * price * price - 2 * price * sum(price, length)[1] + sum(price * price, length)[1];

plot Ehlers = sum(coeff * price, length) / sum(coeff, length);
#Ehlers.SetDefaultColor(GetColor(1));

def EhlersD = Ehlers [+displace];

def UP1 = (Price > Ehlers);
def DN1 = (Price < Ehlers);

#Condition Calculation
def UPBias = UP1;
def DNBias = DN1;
def Direction = UPBias - DNBias;

#AddCloud(Ehlers, EhlersD, Color.GREEN, Color.CURRENT);
#AddCloud(EhlersD, Ehlers, Color.RED, Color.CURRENT);

AssignPriceColor(if coloredCandlesOn and ((Direction > 0)) then Color.GREEN else if coloredCandlesOn and ((Direction < 0)) then Color.RED else Color.GRAY);

#plot Long_Entry = (Direction crosses above 0);
#Long_Entry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#Long_Entry.SetLineWeight(3);
#Long_Entry.AssignValueColor(Color.UPTICK);

#plot Long_Exit =  (Direction crosses below 0);
#Long_Exit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#Long_Exit.SetLineWeight(3);
#Long_Exit.AssignValueColor(Color.DOWNTICK);

def upsignal = (Direction crosses above 0);
def downsignal = (Direction crosses below 0);
#UpSignal.SetDefaultColor(Color.UPTICK);
#UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#DownSignal.SetDefaultColor(Color.DOWNTICK);
#DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

###------------------------------------------------------------------------------------------
# Profit and Loss Labels
#
# Fill in the 0>0 in the Create Signals section below to match your buy and sell signal conditions
#
# When using large amounts of hisorical data, P/L may take time to calculate
###------------------------------------------------------------------------------------------

input showSignals = yes; #hint showSignals: show buy and sell arrows
input LongTrades = yes; #hint LongTrades: perform long trades
input ShortTrades = yes; #hint ShortTrades: perform short trades
input showLabels  = yes; #hint showLabels: show PL labels at top
input showBubbles = yes; #hint showBubbles: show PL bubbles at close of trade
input useStops = no;     #hint useStops: use stop orders
input useAlerts = no;    #hint useAlerts: use alerts on signals
input tradeDaytimeOnly = no; #hint tradeDaytimeOnly: (IntraDay Only) Only perform trades during hours stated
input OpenTime = 0930; #hint OpenTime: Opening time of market
input CloseTime = 1600; #hint CloseTime: Closing time of market


def Begin = secondsfromTime(OpenTime);
def End = secondsTillTime(closetime);
# Only use market hours when using intraday timeframe
def isIntraDay = if getaggregationperiod() > 14400000 or getaggregationperiod()==0 then 0 else 1;
def MarketOpen = if !tradeDaytimeOnly or !isIntraDay then 1 else if tradeDaytimeOnly and isIntraDay and Begin > 0 and End > 0 then 1 else 0;
###------------------------------------------------------------------------------------------

######################################################
##  Create Signals -
##  FILL IN THIS SECTION
##      replace 0>0 with your conditions for signals
######################################################

def PLBuySignal = if  MarketOpen AND (upsignal) then 1 else 0 ; # insert condition to create long position in place of the 0>0
def PLSellSignal =  if MarketOpen AND (downsignal) then 1 else 0; # insert condition to create short position in place of the 0>0

def PLBuyStop  = if !useStops then 0 else if  (0>0) then 1 else 0  ; # insert condition to stop in place of the 0<0
def PLSellStop = if !useStops then 0 else if (0>0) then 1 else 0  ; # insert condition to stop in place of the 0>0

def PLMktStop = if MarketOpen[-1] == 0 then 1 else 0; # If tradeDaytimeOnly is set, then stop at end of day


#######################################
##  Maintain the position of trades
#######################################

def CurrentPosition;  # holds whether flat = 0 long = 1 short = -1

if (BarNumber()==1) OR isNaN(CurrentPosition[1]) {
    CurrentPosition = 0;
}else{
        if CurrentPosition[1] == 0 {            # FLAT
            if (PLBuySignal AND LongTrades) {
                CurrentPosition = 1;
            } else if (PLSellSignal AND ShortTrades){
                CurrentPosition = -1;
            } else {
                CurrentPosition = CurrentPosition[1];
            }
       } else if CurrentPosition[1] == 1 {      # LONG
            if (PLSellSignal AND ShortTrades){
                CurrentPosition = -1;
            } else if ((PLBuyStop and useStops) or PLMktStop or (PLSellSignal AND ShortTrades==0)){
                CurrentPosition = 0;
            } else {
                CurrentPosition = CurrentPosition[1];
            }
       } else if CurrentPosition[1] == -1 {     # SHORT
            if (PLBuySignal AND LongTrades){
                CurrentPosition = 1;
            } else if ((PLSellStop and useStops) or PLMktStop or (PlBuySignal and LongTrades==0)){
                CurrentPosition = 0;
            } else {
                CurrentPosition = CurrentPosition[1];
            }
       } else {
            CurrentPosition = CurrentPosition[1];
       }
}


def isLong  = if CurrentPosition == 1 then 1 else 0;
def isShort = if CurrentPosition == -1 then 1 else 0;
def isFlat  = if CurrentPosition == 0 then 1 else 0;

# If not already long and get a PLBuySignal
#Plot BuySig = if (!isLong[1] and PLBuySignal and showSignals and LongTrades) then 1 else 0;
Plot BuySig = if (((isShort[1] and LongTrades) or (isFlat[1] and LongTrades)) and PLBuySignal and showSignals) then 1 else 0;
BuySig.AssignValueColor(color.cyan);
BuySig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySig.SetLineWeight(5);

Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);
Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);

# If not already short and get a PLSellSignal
Plot SellSig = if (((isLong[1] and ShortTrades) or (isFlat[1] and ShortTrades)) and PLSellSignal and showSignals) then 1 else 0;
SellSig.AssignValueColor(color.cyan);
SellSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSig.SetLineWeight(5);

Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Ding);
Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Ding);

# If long and get a PLBuyStop
Plot BuyStpSig = if (PLBuyStop and isLong[1] and showSignals and useStops) or (isLong[1] and PLMktStop) or (isLong[1] and PLSellSignal and !ShortTrades) then 1 else 0;
BuyStpSig.AssignValueColor(color.light_gray);
BuyStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BuyStpSig.SetLineWeight(3);

Alert(BuyStpSig and useAlerts, "Buy Stop Signal",Alert.bar,sound.Ding);
Alert(BuyStpSig and useAlerts, "Buy Stop Signal",Alert.bar,sound.Ding);


# If short and get a PLSellStop
Plot SellStpSig = if (PLSellStop and isShort[1] and showSignals and useStops) or (isShort[1] and PLMktStop) or (isShort[1] and PLBuySignal and !LongTrades) then 1 else 0;
SellStpSig.AssignValueColor(color.light_gray);
SellStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SellStpSig.SetLineWeight(3);

Alert(SellStpSig and useAlerts, "Sell Stop Signal",Alert.bar,sound.Ding);
Alert(SellStpSig and useAlerts, "Sell Stop Signal",Alert.bar,sound.Ding);


#######################################
##  Orders
#######################################

def isOrder = if ((isFlat[1] and (BuySig and LongTrades) or (SellSig and ShortTrades)) or (isLong[1] and BuyStpSig or (SellSig and ShortTrades)) or (isShort[1] and SellStpSig or (BuySig and LongTrades))) then 1 else 0 ;
# If there is an order, then the price is the next days close
def orderPrice = if (isOrder and ((BuySig and LongTrades) or (SellSig and ShortTrades))) then close else orderPrice[1];

def orderCount = compoundValue(1,if isNan(isOrder) or barnumber()==1 then 0 else if (BuySig or SellSig) then orderCount[1]+1 else orderCount[1],0);


#######################################
##  Price and Profit
#######################################

def profitLoss;


if (!isOrder or orderPRice[1]==0){
    profitLoss = 0;
} else if ((isOrder and isLong[1]) and (SellSig or BuyStpSig)){
    profitLoss = close - orderPrice[1];
} else if ((isOrder and isShort[1]) and (BuySig or SellStpSig)) {
    profitLoss = orderPrice[1] - close;
} else {
    profitLoss = 0;
}


# Total Profit or Loss
def profitLossSum = compoundValue(1, if isNaN(isOrder)  or barnumber()==1 then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);

# How many trades won or lost
def profitWinners = compoundValue(1, if isNaN(profitWinners[1]) or barnumber()==1 then 0 else if isOrder and profitLoss > 0 then profitWinners[1] + 1 else profitWinners[1], 0);
def profitLosers = compoundValue(1, if isNaN(profitLosers[1])  or barnumber()==1 then 0 else if isOrder and profitLoss < 0 then profitLosers[1] + 1 else profitLosers[1], 0);
def profitPush = compoundValue(1, if isNaN(profitPush[1])  or barnumber()==1 then 0 else if isOrder and profitLoss == 0 then profitPush[1] + 1 else profitPush[1], 0);

# Current Open Trade Profit or Loss
def TradePL = If isLong then Round(((close - orderprice)/TickSize())*TickValue()) else if isShort then Round(((orderPrice - close)/TickSize())*TickValue()) else 0;

# Convert to actual dollars based on Tick Value for bubbles
def dollarProfitLoss = if orderPRice[1]==0 or isNaN(orderPrice[1]) then 0 else round((profitLoss/Ticksize())*Tickvalue());

# Closed Orders dollar P/L
def dollarPLSum = round((profitLossSum/Ticksize())*Tickvalue());


# Split profits or losses by long and short trades
def profitLong = compoundValue(1, if isNan(profitLong[1])  or barnumber()==1 then 0 else if isOrder and isLong[1] then profitLong[1]+dollarProfitLoss else profitLong[1],0);
def profitShort = compoundValue(1, if isNan(profitShort[1])  or barnumber()==1 then 0 else if isOrder and isShort[1] then profitShort[1]+dollarProfitLoss else profitShort[1],0);
def countLong = compoundValue(1, if isNaN(countLong[1])  or barnumber()==1 then 0 else if isOrder and isLong[1] then countLong[1]+1 else countLong[1],0);
def countShort = compoundValue(1, if isNaN(countShort[1])  or barnumber()==1 then 0 else if isOrder and isShort[1] then countShort[1]+1 else countShort[1],0);

# What was the biggest winning and losing trade
def biggestWin = compoundValue(1, if isNaN(biggestWin[1]) or barnumber()==1 then 0 else if isOrder and (dollarProfitLoss > 0) and (dollarProfitLoss > biggestWin[1]) then dollarProfitLoss else biggestWin[1], 0);
def biggestLoss = compoundValue(1, if isNaN(biggestLoss[1]) or barnumber()==1 then 0 else if isOrder and (dollarProfitLoss < 0) and (dollarProfitLoss < biggestLoss[1]) then dollarProfitLoss else biggestLoss[1], 0);

def ClosedTradeCount = if (isLong or isShort) then orderCount-1 else orderCount;
def OpenTrades = if (isLong or isShort) then 1 else 0;


# What percent were winners
def PCTWin = if (OpenTrades and (TradePL < 0)) then round((profitWinners/(ClosedTradeCount+1))*100,2)
else if (OpenTrades and (TradePL > 0)) then round(((profitWinners+1)/(ClosedTradeCount+1))*100,2) else round(((profitWinners)/(ClosedTradeCount))*100,2) ;

# Average trade
def avgTrade = if (OpenTrades and (TradePL < 0)) then round(((dollarPLSum - TradePL)/(ClosedTradeCount+1)),2)
else if (OpenTrades and (TradePL > 0)) then round(((dollarPLSum + TradePL)/(ClosedTradeCount+1)),2) else round(((dollarPLSum)/(ClosedTradeCount)),2) ;


#######################################
##  Create Labels
#######################################


AddLabel(showLabels and isIntraDay, if MarketOpen then "Market Open" else "Market Closed", color.white);
AddLabel(showLabels, GetSymbol()+" Tick Size: "+TickSize()+" Value: "+TickValue(), color.white);
AddLabel(showLabels and (LongTrades and ShortTrades), "Long+Short Trades", color.white);
AddLabel(showLabels and (LongTrades and !ShortTrades),"Long Trades Only", color.white);
AddLabel(showLabels and (!LongTrades and ShortTrades),"Short Trades Only", color.white);
AddLabel(showLabels, "Closed Orders: " + ClosedTradeCount + " P/L: " + AsDollars(dollarPLSum), if dollarPLSum > 0 then Color.GREEN else if dollarPLSum< 0 then Color.RED else Color.GRAY);
AddLabel(if !IsNan(orderPrice) and showLabels then 1 else 0, "Closed+Open P/L: "+ AsDollars(TradePL+dollarPLSum), if ((TradePL+dollarPLSum) > 0) then color.green else if ((TradePL+dollarPLSum) < 0) then color.red else color.gray);

AddLabel(showLabels, "Avg per Trade: "+ AsDollars(avgTrade), if avgTrade > 0 then Color.Green else if avgTrade < 0 then Color.RED else Color.GRAY);
AddLabel(showLabels, "Winners: "+ PCTWin +"%",if PCTWin > 50 then color.green else if PCTWin > 40 then color.yellow else color.gray);

AddLabel(showLabels, "MaxUp: "+ AsDollars(biggestWin) +" MaxDown: "+AsDollars(biggestLoss), color.white);
AddLabel(showLabels, "Long Profit: " +AsDollars(profitLong), if profitLong > 0 then color.green else if profitLong < 0 then color.red else color.gray);
AddLabel(showLabels, "Short Profit: " +AsDollars(profitShort), if profitShort > 0 then color.green else if profitShort < 0 then color.red else color.gray);
AddLabel(if !IsNan(CurrentPosition) and showLabels and OpenTrades then 1 else 0, "Open: "+ (If isLong then "Bought" else "Sold") + " @ "+orderPrice, color.white);
AddLabel(if !IsNan(orderPrice) and showLabels and OpenTrades then 1 else 0, "Open Trade P/L: "+ AsDollars(TradePL), if (TradePL > 0) then color.green else if (TradePl < 0) then color.red else color.gray);



#######################################
##  Chart Bubbles for Profit/Loss
#######################################


AddChartBubble(showSignals and showBubbles and isOrder and isLong[1], low, "$"+dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else color.Red, 0);
AddChartBubble(showSignals and showBubbles and isOrder and isShort[1], high,  "$"+dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else color.Red, 1);

#AssignPriceColor(if CurrentPosition == 1 then color.green else if CurrentPosition == -1 then color.red else color.gray);
 
Last edited by a moderator:
thanks a lot, sir. I use this code and add some code(just copy from another thread ) for statistics. The code is as follows.
But I compare it with the original strategy CODE. there are huge differences.
do you have some ideas about my CODE ?
I have inserted the code into a strategy I'm currently working on to see the results. Looks interesting! Thank you for sharing! I'll check it out. :)
dLBwmda.png
 
Last edited by a moderator:
Please, I'd like to test how the indicator behaves on the Tick chart. Could someone help me to modify the code below. I want to define the "MarketOpen" time to just extend Hours. 16:00--17:00 and 18:00--09:30
Thanks.

Code:
input tradeDaytimeOnly = yes; #hint tradeDaytimeOnly: (IntraDay Only) Only perform trades during hours stated
input OpenTime = 0930; #hint OpenTime: Opening time of market
input CloseTime = 1600; #hint CloseTime: Closing time of market

def Begin = secondsfromTime(OpenTime);
def End = secondsTillTime(closetime);

# Only use market hours when using intraday timeframe
def isIntraDay = if getaggregationperiod() > 14400000 or getaggregationperiod()==0 then 0 else 1;
def MarketOpen = if !tradeDaytimeOnly or !isIntraDay then 1 else if tradeDaytimeOnly and isIntraDay and Begin > 0 and End > 0 then 1 else 0;
 
Just added 2 new strategies on pg.1 of the thread. The first is based on Ehler's Distant Coefficient Filter.
UHyFOuD.png

The second strategy is based off of the HiLo study.
x6GHOYa.png

Both strategies are adjustable. I hope everyone finds them useful. Happy trading!
Hi Christopher,

I hope you are doing good.

Are the above two strategies works for only /ES or will it work for any stock?

Can you please suggest the strategies you posted , which strategy is good for stocks?

Thanks
Madhu
 
I have inserted the code into a strategy I'm currently working on to see the results. Looks interesting! Thank you for sharing! I'll check it out. :)
dLBwmda.png
Sorry, Christopher, I make a mistake. when I test your EDCF strategy I didn't turn off the extended hours.
so I test again in 15Min . but there still is some difference.
Mk1THEf.jpg
 
Last edited by a moderator:
Sorry, Christopher, I make a mistake. when I test your EDCF strategy I didn't turn off the extended hours.
so I test again in 15Min . but there still is some difference.
EDCF strategy BackTest in 10Min and 5 Min
according to my back test(180 days) , the Best length setup for ES (day time ) :
15 Min Length= 20, (10 has the best P/L)
10 Min Length= 15 (15--27 are good)
5 MIn Length= 34
0nsiqoG.jpg

8EOGCTT.jpg
 
Last edited by a moderator:
Hi Christopher,

I hope you are doing good.

Are the above two strategies works for only /ES or will it work for any stock?

Can you please suggest the strategies you posted , which strategy is good for stocks?

Thanks
Madhu
Hi @Madhu!
The strategies can be adjusted to trade the asset and timeframe that you prefer. You can use the floating P/L study to get an idea of your strategy's performance on the asset you are trading. Happy trading!
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
368 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