# GaussianMeanCrossWithProfitability_JQ
declare lower;
#plot Data = close;
input GaussianLength = 5;
input GaussianLengthLong = 20;
input betaDev = 7.0; #hint betaDev: adjust this value till the label indicates a minimum of 68.2% of closes
# Trying to achieve Normal Distribution
# Mobius
# V01.09.2015
def c;
def w;
def beta;
def alpha;
def G;
plot GaussianMean;
GaussianMean.SetDefaultColor(Color.WHITE);
GaussianMean.SetLineWeight(2);
c = close;
w = (2 * Double.Pi / GaussianLength);
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];
GaussianMean = G;
#*******************************************************************************;
# Trying to achieve Normal Distribution
# Mobius
# V01.09.2015
def c2;
def w2;
def beta2;
def alpha2;
def G2;
plot GaussianMeanLong;
GaussianMeanLong.SetDefaultColor(Color.YELLOW);
GaussianMeanLong.SetLineWeight(2);
c2 = close;
w2 = (2 * Double.Pi / GaussianLengthLong);
beta2 = (1 - Cos(w2)) / (Power(1.414, 2.0 / betaDev) - 1 );
alpha2 = (-beta2 + Sqrt(beta2 * beta2 + 2 * beta2));
G2 = Power(alpha2, 4) * c2 +
4 * (1 – alpha2) * G2[1] – 6 * Power( 1 - alpha2, 2 ) * G2[2] +
4 * Power( 1 - alpha2, 3 ) * G2[3] - Power( 1 - alpha2, 4 ) * G2[4];
GaussianMeanLong = G2;
## End Gaussian Codes
# ---------------------------------------------------
## Begin Plots
plot BullishCross = GaussianMean crosses above GaussianMeanLong;
BullishCross.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BullishCross.SetDefaultColor(Color.UPTICK);
plot BearishCross = GaussianMean crosses below GaussianMeanLong;
BearishCross.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BearishCross.SetDefaultColor(Color.DOWNTICK);
# Total Cross Count in Bubbles
# TsL for fredw
# Nube 9.24.18
# universals
def bn = BarNumber();
#def c = close;
def na = Double.NaN;
# variables
def upCross = GaussianMean crosses above GaussianMeanLong;
def upCrossCt = CompoundValue(1,
if upCross
then upCrossCt[1] + 1
else upCrossCt[1], 0);
def currentUpCrossCount = HighestAll(if !IsNaN(c) && IsNaN(c[-1])
then upCrossCt else na);
def upCrossBar = if upCross
then bn else upCrossBar[1];
# plots
#AddChartBubble(bn == highestall(upCrossBar), low,""+currentUpCrossCount, Color.Gray,0);
# alternative version for those who prefer to also use GetValue()
#def currentBar = HighestAll(if !IsNaN(c) && IsNaN(c[-1])
# then bn else na);
#def getUpCount = GetValue(upCrossCt, bn - currentBar);
#AddChartBubble(bn == upCrossBar, high,""+getUpCount, Color.Light_Gray);
## ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
## ProfitLossSnippet_v04_JQ
## Profit Loss Code Snippet
## This snippet should be appendable to most studies will little effort
## Signal COde portion should be adjusted to capture buy/sell open/close signals
## v04 Splitting into Long only and short only sections
## V03 - 10.20.2018 - JQ - Correct calculation of Profit Loss yet again
## V02.1 - 071715 - Dilbert - Correct calculation of profitLoss again
## V02 - 071515 - Dilbert - Correct calculation of profitLoss
## Profit/Loss label and bubbles, added by linus (2014-07-31)
## Note: Insert at the bottom of Mobius' RSI in Laguerre Time V02.07.2014 study.
## Signal Code
## Signal Code needs to be adjusted to the script to which this snippet is appended
# End Profit/Loss Code