# Laguerre Used for Stop Placement

##### New member
Here's a great way to use Laguerre for stop placement.

Code:
``````#Laguerre Filter created by TradeScripter

AssignBackgroundColor(CreateColor(8, 0, 15));

input price = close;
input gamma = 0.2;

rec L0 = (1 - gamma) * price + gamma * L0[1];
rec L1 = -gamma * L0 + L0[1] + gamma * L1[1];
rec L2 = -gamma * L1 + L1[1] + gamma * L2[1];
rec L3 = -gamma * L2 + L2[1] + gamma * L3[1];
def FIlt = (L0 + 2 * L1 + 2 * L2 + L3) / 6;
def FIR = (price + 2 * price[1] + 2 * price[2] + price[3]) / 6;

plot Plot1 = FIlt;
plot Plot2 = FIR;

#Plot1.SetDefaultColor(color.red);
#Plot2.SetDefaultColor(color.blue);
Plot1.AssignValueColor(if Filt > FIlt[1] then Color.GREEN else Color.RED);

Plot2.AssignValueColor(if FIR  > FIlt and FIR > FIR[1]  then Color.GREEN else if FIR < FIlt and FIR < FIR[1] then Color.RED else Color.WHITE);

#AssignPriceColor(if FIR  > FIlt and FIR > FIR[1]  then Color.GREEN else if FIR < FIlt and FIR < FIR[1] then Color.RED else Color.WHITE);``````

#### Attachments

• UuKHZ0U.png
71.2 KB · Views: 194
Last edited:
thanks for sharing @ebtrader seems has potential! - Applicable across all time frames. Nice work and thanks again!

thanks for sharing @ebtrader seems has potential! - Applicable across all time frames. Nice work and thanks again!

i love studies that work across all time frames like this one. i you have any tweaks to it, please let me know.

@ebtrader just curious, why do you have Gamma at 0.2 vs 0.5 or higher?

@ebtrader just curious, why do you have Gamma at 0.2 vs 0.5 or higher?

it has been ages since i tweaked it, but i guess that's the setting that helped me get what i wanted. Is 0.5 the standard out there?

Not necessarily, I have seen it in other scripts this low, but more often, I've seen it above 70. It may be script dependent,

Seems a value of 0.5 to 0.8 seems to work better in shorter timeframes.

I just tried 0.5 and it is really neat - shows the turns sooner, but not confirmed until crosses over - so basically shows the countertrend trades until the crossover.

It might be best to have both 0.5 and 0.2 on the same chart to keep you in the trade.

here is a version that can put more than one gamma setting on the same chart.

Code:
``````#Laguerre Filter created by TradeScripter

AssignBackgroundColor(CreateColor(8, 0, 15));

input price = close;
input gamma = 0.2;

rec L0 = (1 - gamma) * price + gamma * L0[1];
rec L1 = -gamma * L0 + L0[1] + gamma * L1[1];
rec L2 = -gamma * L1 + L1[1] + gamma * L2[1];
rec L3 = -gamma * L2 + L2[1] + gamma * L3[1];
def FIlt = (L0 + 2 * L1 + 2 * L2 + L3) / 6;
def FIR = (price + 2 * price[1] + 2 * price[2] + price[3]) / 6;

plot Plot1 = FIlt;
plot Plot2 = FIR;

Plot1.AssignValueColor(if Filt > FIlt[1] then Color.GREEN else Color.RED);

Plot2.AssignValueColor(if FIR  > FIlt and FIR > FIR[1]  then Color.GREEN else if FIR < FIlt and FIR < FIR[1] then Color.RED else Color.WHITE);

#Laguerre 2

input price2 = close;
input gamma2 = 0.2;

rec L00 = (1 - gamma2) * price2 + gamma2 * L00[1];
rec L11 = -gamma2 * L00 + L00[1] + gamma2 * L11[1];
rec L22 = -gamma2 * L11 + L11[1] + gamma2 * L22[1];
rec L33 = -gamma2 * L22 + L22[1] + gamma2 * L33[1];
def FIlt2 = (L00 + 2 * L11 + 2 * L22 + L33) / 6;
def FIR2 = (price2 + 2 * price2[1] + 2 * price2[2] + price2[3]) / 6;

plot Plot3 = FIlt2;
plot Plot4 = FIR2;

Plot3.AssignValueColor(if Filt2 > FIlt2[1] then Color.GREEN else Color.RED);

Plot4.AssignValueColor(if FIR2  > FIlt2 and FIR2 > FIR2[1]  then Color.GREEN else if FIR2 < FIlt2 and FIR2 < FIR2[1] then Color.RED else Color.WHITE);``````

here is a version that can put more than one gamma setting on the same chart.

Code:
``````#Laguerre Filter created by TradeScripter

AssignBackgroundColor(CreateColor(8, 0, 15));

input price = close;
input gamma = 0.2;

rec L0 = (1 - gamma) * price + gamma * L0[1];
rec L1 = -gamma * L0 + L0[1] + gamma * L1[1];
rec L2 = -gamma * L1 + L1[1] + gamma * L2[1];
rec L3 = -gamma * L2 + L2[1] + gamma * L3[1];
def FIlt = (L0 + 2 * L1 + 2 * L2 + L3) / 6;
def FIR = (price + 2 * price[1] + 2 * price[2] + price[3]) / 6;

plot Plot1 = FIlt;
plot Plot2 = FIR;

Plot1.AssignValueColor(if Filt > FIlt[1] then Color.GREEN else Color.RED);

Plot2.AssignValueColor(if FIR  > FIlt and FIR > FIR[1]  then Color.GREEN else if FIR < FIlt and FIR < FIR[1] then Color.RED else Color.WHITE);

#Laguerre 2

input price2 = close;
input gamma2 = 0.2;

rec L00 = (1 - gamma2) * price2 + gamma2 * L00[1];
rec L11 = -gamma2 * L00 + L00[1] + gamma2 * L11[1];
rec L22 = -gamma2 * L11 + L11[1] + gamma2 * L22[1];
rec L33 = -gamma2 * L22 + L22[1] + gamma2 * L33[1];
def FIlt2 = (L00 + 2 * L11 + 2 * L22 + L33) / 6;
def FIR2 = (price2 + 2 * price2[1] + 2 * price2[2] + price2[3]) / 6;

plot Plot3 = FIlt2;
plot Plot4 = FIR2;

Plot3.AssignValueColor(if Filt2 > FIlt2[1] then Color.GREEN else Color.RED);

Plot4.AssignValueColor(if FIR2  > FIlt2 and FIR2 > FIR2[1]  then Color.GREEN else if FIR2 < FIlt2 and FIR2 < FIR2[1] then Color.RED else Color.WHITE);``````
That's ok for testing purposes.

it has been ages since i tweaked it, but i guess that's the setting that helped me get what i wanted. Is 0.5 the standard out there?
ebtrader curious if you used any other complimentary indicator with this that was not redundant. Thanks

I made some visual enhancement to this and fixed code duplication: cannot stand non pretty code lol.
https://tos.mx/T7ASwHJ

I made some visual enhancement to this and fixed code duplication: cannot stand non pretty code lol.
https://tos.mx/T7ASwHJ

I didn't want redundancy as mentione in this tread so tried to get this code but TOS says this URL appears to be broken please check and try again

Added this script to my chart but nothing shows up but it is the weekend. Does it only show up during market hours? Thanks

Seems a value of 0.5 to 0.8 seems to work better in shorter timeframes.
.08-.13 are original parameters...

I just tried 0.5 and it is really neat - shows the turns sooner, but not confirmed until crosses over - so basically shows the countertrend trades until the crossover.

I think you created some very interesting indicators I've discovered.

I didn't want redundancy as mentione in this tread so tried to get this code but TOS says this URL appears to be broken please check and try again
The code works,...copy/paste,...if it doesn't work, scratch last letter....

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
234 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• 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?