A trend, momentum and cycle Trading System v3.0 (CSA)

can someone tell me what I am doing wrong? I copied the code on post 3 and it looks like nothing has changed with TOS?


y9A0VKT.png
Your timeline is on day bro... The D symbol on your frame. Save it turn it off and on and change the amount of time. Then your progam will load
We need to get together for a bug hunt and then we will cover all this later.
 
Doesn't that Multi Time Frame MTF portion work with the Heikin Ashi portion? I am very close to removing that myself... I don't believe I understand why HA MTF is valid in this Architecture... I am waiting for someone to explain why they favor it??? i understand @YungTraderFromMontana use 4 smooth auto-trading... Maybe because the High to Low & Open to Close nature helps shift weight away from just falling all into just a default candle.
In addition to your minute aggregation period the displacement term is meant to smooth out the HA MTF buuut it only changes the window in the top of the screen... Does not change the final result :oops:
Code:
AddLabel(showlabels and enableHAMTF, "HA",
if IsNan(HAMTF_sState) then COLOR.DARK_GRAY else
if HAMTF_sState[-displace] > 0 then COLOR.GREEN else
if HAMTF_sState[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
@hjc5812 I am working in the very short time frame... Because for the things spoken of looking on a 4 hour timeline won't let you see farther into the future it only deprives your computer information... A moving average line is worth zooming out to see the overall trend but here we are looking at immediate directions... What timeline and what kind of trading are you interested in @hjc5812 ???

The HA MTF is there so that you don't get whipsaws on smaller timeframes...if you trade the 1 min chart...set the HA MTF to 3 or 5 min...use other indicators as exits...Much better definition of the trend than on 1 minute HA with no MTF...
 
so what I am looking for if I understand this correctly is for everything to turn red or green? Btw this script looks awesome thanks so much for doing it and updating it!
 
@diazlaz I am going over each indicators one by one in the CSA to find the best possible combination and
I found an issue with FREMA. I have used FREMA before in combination with MACD and FREMA in the CSA plots different than in the MACD I was using it with...Please take a look at the pic below:


Is there a way to fix the FREMA in this CSA to reflect how it plots in the MACD script below? You can clearly see the difference based on the pic and how much faster the FREMA in MACD hits vs in the CSA. BTW: I have set the threshold to 1 and disabled all other indicators to NO to make sure that ONLY one indicator is being tested at a time.

Code:
# MACD with a more Normal Distribution
# Mobius
# V01.09.2015
#Hint: Plots a Gaussian distribution. If Normal Distribution is met, then at minimum, 68.2% of the close values should be inside a One Standard Deviation Envelope and 95.4% of the close values should be inside a 2 Standard Deviation Envelope.

# V11.01.2019 - netarchitech added standard TOS Breakout Signals per HighBredCloud request
# V11.01.2019 - netarchitech added Ehlers and Mobius Forward/Reverse EMA per HighBredCloud request

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input showBreakoutSignals = no;

# Four Pole Filter
script g{
input length = 4;
input betaDev = 2;
input price = OHLC4;
def c;
def w;
def beta;
def alpha;
def G;
c = price;
w = (2 * Double.Pi / length);
beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
alpha = (-beta + Sqrt(beta * beta + 2 * beta));
G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
plot Line = G;
}
# Modified MACD
plot Value = g(length = fastLength) - g(length = slowLength);
plot Avg = g(price = Value, length = MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
#Value.SetLineWeight(2);
Avg.SetDefaultColor(GetColor(8));
#Avg.SetLineWeight(2);
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


# Forward / Reverse EMA
# (c) 2017 John F. Ehlers
# Ported to TOS 07.16.2017
# Mobius

# Inputs:
input AA = .1;

# Vars:
def CC;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
plot Signal;
plot plot0;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * Close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

Signal = EMA – AA * RE8;
Signal.AssignValueColor(if Signal > Signal[1]
                        then Color.GREEN
                        else Color.RED);
Signal.SetLineWeight(3);
Plot0 = if isNaN(close) then double.nan else 0;
Plot0.SetDefaultColor(Color.GRAY);

#addCloud(0, Signal, color.RED, color.GREEN);

EDIT: It appears that the colors in the FREMA in the MACD script that I have posted above is set not based on the ZERO line crossing of FREMA hence the early entry/exit. I am not sure IF there is a way to replicate "Negative and Up" and or "Positive and Down" state in the CSA to reflect those of the FREMA found in the MACD script that I have provided.
Code:
#In the CSA version get rid of def FRE_zeroline = 0 Mobius Version is correct
def FRE_sfrema= if (FRE_ema_signal>FRE_ema_signal[1])
Over using the zero line function seems to be a big problem in TOS
 
so what I am looking for if I understand this correctly is for everything to turn red or green? Btw this script looks awesome thanks so much for doing it and updating it!
I believe so but you probably want something like the Trend Reversal Indicator or that Mobious True momentum Oscillator for identifying direction... I am hear to understand random motion vs trends...
 
Code:
#In the CSA version get rid of def FRE_zeroline = 0 Mobius Version is correct
def FRE_sfrema= if (FRE_ema_signal>FRE_ema_signal[1])
Over using the zero line function seems to be a big problem in TOS

can you all work out the logic you want to see?

GudKKWy.png


Note: there are a number of plots in this study.
  1. plot Line = G;
  2. plot Value = g(length = fastLength) - g(length = slowLength);
  3. plot Avg = g(price = Value, length = MACDLength);
  4. plot Diff = Value - Avg;
  5. plot ZeroLine = 0;
  6. plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
  7. plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;
  8. plot Signal;
  9. plot plot0;
 
can you all work out the logic you want to see?
Code:
#START OF FRE - Frema Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableFrema = yes; #FREMA
input FRE_aa = .1; #FREMA

def FRE_cc;
#def FRE_zeroline = 0; (Don't need zero command!!!)
def FRE_re1;
def FRE_re2;
def FRE_re3;
def FRE_re4;
def FRE_re5;
def FRE_re6;
def FRE_re7;
def FRE_re8;
def FRE_ema;
FRE_cc = if FRE_cc[1] == 0 then .9 else 1 – FRE_aa;
FRE_ema = FRE_aa * c + FRE_cc * FRE_ema[1];
FRE_re1 = FRE_cc * FRE_ema + FRE_ema[1];
FRE_re2 = Power(FRE_cc, 2) * FRE_re1 + FRE_re1[1];
FRE_re3 = Power(FRE_cc, 4) * FRE_re2 + FRE_re2[1];
FRE_re4 = Power(FRE_cc, 8) * FRE_re3 + FRE_re3[1];
FRE_re5 = Power(FRE_cc, 16) * FRE_re4 + FRE_re4[1];
FRE_re6 = Power(FRE_cc, 32) * FRE_re5 + FRE_re5[1];
FRE_re7 = Power(FRE_cc, 64) * FRE_re6 + FRE_re6[1];
FRE_re8 = Power(FRE_cc, 128) * FRE_re7 + FRE_re7[1];
def FRE_ema_signal = FRE_ema – FRE_aa * FRE_re8;
def FRE_sfrema = if (FRE_ema_signal >FRE_ema_signal[1] ) then 100 else -100;
def FRE_sbullish = enableFrema and FRE_sfrema == 100;
def FRE_sbearish = enableFrema and FRE_sfrema == -100;
def FRE_sneutral = 0;

AddLabel(showLabels and enableFrema, "Frema", if IsNaN(FRE_sfrema) then Color.DARK_GRAY else
if FRE_sfrema > 0 then Color.GREEN else
if FRE_sfrema < 0 then Color.RED
else Color.DARK_GRAY);
You are good Brother... We will need to do an overhaul later but for now just fix the TTM trend with the 1 line of code of adding input Compbars = # and fix Frema with the 1 line of code of using FRE_ema_signal[1]...
You will need to replace displace with a phase shift thinking more of a Sine Wave of an oscillator than the Sawing motions of being out of phase... You decrease the difference by adding to the greater oscillator which seems counter intuitive please watch that example video I put last page...

You seriously are a way better coder than me what is happened is it is more fun to solve problems writing code than it is to edit... Like I always have to bribe a family member to read my quarterly reports back in school because after I had written them I would rather take a beating than open them again...
What you wrote here could become the most powerful all around indicator I still believe.
 
Note: there are a number of plots in this study.
  1. plot Line = G;
  2. plot Value = g(length = fastLength) - g(length = slowLength);
  3. plot Avg = g(price = Value, length = MACDLength);
  4. plot Diff = Value - Avg;
  5. plot ZeroLine = 0;
  6. plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
  7. plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;
  8. plot Signal;
  9. plot plot0;
If you make that fix above Frema becomes very accurate get rid of ZeroLine...



I seriously am new here and have been busy so I haven't read over the Mobius lessons in archive...
What would help me is just shortcuts to the links Yungtrader wanted https://tos.mx/OIfXNfi did you guys talk about those? I haven't looked or loaded it yet but is there any history i should know before I start?
 
We can use those Newton Method math equations I posted earlier to balance all the indicators later once everything is functioning...
It works by taking a lot of guesses until the error is a small as possible...
The natural way to solve and equation is to use what is known:
X+X=2; X+Y=3 [You say hey X=1 cause 1+1=2 so the Y=2 cause 1+2=3]
our situation is we have more unknown than known
X+Y+Z=21 ; X+Z=3 [You must use Newtons Method]
Once you have that solution the Architecture will gain the intelligence to adjust before the trend for example the CCI term will be able to overpower Simple Moving Averages over the noise of a fake start ...
This will be very powerful it is great work...
 
Doesn't that Multi Time Frame MTF portion work with the Heikin Ashi portion? I am very close to removing that myself... I don't believe I understand why HA MTF is valid in this Architecture... I am waiting for someone to explain why they favor it??? i understand @YungTraderFromMontana use 4 smooth auto-trading... Maybe because the High to Low & Open to Close nature helps shift weight away from just falling all into just a default candle.
In addition to your minute aggregation period the displacement term is meant to smooth out the HA MTF buuut it only changes the window in the top of the screen... Does not change the final result :oops:
Code:
AddLabel(showlabels and enableHAMTF, "HA",
if IsNan(HAMTF_sState) then COLOR.DARK_GRAY else
if HAMTF_sState[-displace] > 0 then COLOR.GREEN else
if HAMTF_sState[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
@hjc5812 I am working in the very short time frame... Because for the things spoken of looking on a 4 hour timeline won't let you see farther into the future it only deprives your computer information... A moving average line is worth zooming out to see the overall trend but here we are looking at immediate directions... What timeline and what kind of trading are you interested in @hjc5812 ???

mainly 5min chart. I am still curious if it's unique error on my TOS or was design by the coder. But anything higher than 5min timeframe wont display CAS and my chart will go back to the 'normal look'
 
If you make that fix above Frema becomes very accurate get rid of ZeroLine...



I seriously am new here and have been busy so I haven't read over the Mobius lessons in archive...
What would help me is just shortcuts to the links Yungtrader wanted https://tos.mx/OIfXNfi did you guys talk about those? I haven't looked or loaded it yet but is there any history i should know before I start?

Thanks MattATM - i made a quick comparison, left is updated using slope (your suggestion and latest), the right is utilizing the zeroline as a trigger, here is the 20D 1H chart for comparison.

DaebqJF.png
 
We can use those Newton Method math equations I posted earlier to balance all the indicators later once everything is functioning...
It works by taking a lot of guesses until the error is a small as possible...
The natural way to solve and equation is to use what is known:
X+X=2; X+Y=3 [You say hey X=1 cause 1+1=2 so the Y=2 cause 1+2=3]
our situation is we have more unknown than known
X+Y+Z=21 ; X+Z=3 [You must use Newtons Method]
Once you have that solution the Architecture will gain the intelligence to adjust before the trend for example the CCI term will be able to overpower Simple Moving Averages over the noise of a fake start ...
This will be very powerful it is great work...

@MattATM Could you link to (or explain) some resources on using the Newton method as you mentioned. I get the basics of the Newton Method from some google searches. I want to try to implement it in Python but I am not the best at Calc.
 
@Tostechnical Yes Newton's Method will be a series of guesses that will be controlled until a valid solution is found that remains correct no matter what bearish or bullish actions occur in the future...
Once we have a logical model we can run our guesses by setting the weight of each variable against the P/L or better yet have the computer guess until there are no Losses at all... We need the computer because my human mind cannot imagine every single market action in every single Financial Product for every minute going back to 2008. Some say the markets behaved the way they do now up until 2006. I don't know so I would just do 2008. The weights of each indicator can all be related to Volatilty "VIX" or whatever you start you can never stop. The solution doesn't need to be incredibly sensitive it just needs to all end in the same units "inches = inches ; kilograms = kilograms etc" http://www.nabla.hr/FU-DerivativeF3.htm I don't know why Python code would be used?
This is easy but cannot be done without all our logic assembled. People have looked for models to correct logic they haven't tested since the 1st Mathematicians and we know we will only receive unpleasant surprises going down that path... You will receive many good results that earn your trust until you receive a terrible result...
 
@Tostechnical Yes Newton's Method will be a series of guesses that will be controlled until a valid solution is found that remains correct no matter what bearish or bullish actions occur in the future...
Once we have a logical model we can run our guesses by setting the weight of each variable against the P/L or better yet have the computer guess until there are no Losses at all... We need the computer because my human mind cannot imagine every single market action in every single Financial Product for every minute going back to 2008. Some say the markets behaved the way they do now up until 2006. I don't know so I would just do 2008. The weights of each indicator can all be related to Volatilty "VIX" or whatever you start you can never stop. The solution doesn't need to be incredibly sensitive it just needs to all end in the same units "inches = inches ; kilograms = kilograms etc" http://www.nabla.hr/FU-DerivativeF3.htm I don't know why Python code would be used?
This is easy but cannot be done without all our logic assembled. People have looked for models to correct logic they haven't tested since the 1st Mathematicians and we know we will only receive unpleasant surprises going down that path... You will receive many good results that earn your trust until you receive a terrible result...


@MattATM Thanks a lot!! I was able to understand the basic math behind Newton's model. So for the model would f{x] be a trading signal, ie CCI crosses above 100, with the output being the a stat like expectancy or P/L over a certain time period? How would you find the derivative for that? I understand that you should change the weights depending on VOL. But to find the initial values for the weighting do we derive them from the Newton model?

My experience with signal weighting is some real basic Fuzzy Logic I did by hand.

I mentioned python because I use it and AlphaVantage's free API to backtest strategies. Also its a lot easier to work with data in python than in excel.
 
@MattATM Thanks a lot!! I was able to understand the basic math behind Newton's model. So for the model would f{x] be a trading signal, ie CCI crosses above 100, with the output being the a stat like expectancy or P/L over a certain time period? How would you find the derivative for that? I understand that you should change the weights depending on VOL. But to find the initial values for the weighting do we derive them from the Newton model?

My experience with signal weighting is some real basic Fuzzy Logic I did by hand.

I mentioned python because I use it and AlphaVantage's free API to backtest strategies. Also its a lot easier to work with data in python than in excel.
It would be crazy difficult to find the derivative for every move of every ticker going back to 2008 it would take a team, machine learning, and serious funding!
But not to worry! The Slope of the Line is ALWAYS the derivative :D ALWAYS ALWAYS ALWAYS!!!! So don't worry the derivative is already handed to us... But we need to minimize the unknowns before we start guessing or I will have a grey beard before it gives the answer...
So you want to standardize around volatility?
Minimize Loss ::: 2ndGuessWeight=1stGuessWeight+(Value1stGuess@VIX/SlopeValue1stGuess@VIX)
then 3rd Guess Weight = ....
.
.
.
100,000,000thGuessWeight=...


Looks difficult but it will solve overnight... What is impossible for a man is easy for a computer. Like when I drove a crane for the Army funny story, I started moving concrete supports by segments by hand. I didn't know I had a 50 ft crane... That could be remote operated. 🤣

What program in Python???
 
that's the Frema plotted in a lower study graph. what did you have in mind?
Can you share which Frema? Yes Frema knows on the left that those Bullish candles are really Bearish and Vice Versa... Do you like it in all timeframes? I haven't looked.

Right now I have Frema with the slope & adaptive moving averages...
I know all our lives are disrupted recently but I really was not well prepared. I thank everyone for your patience!
 

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