a1cturner
Well-known member
Here is what I have so far (below)... Just need some tweaks. As much as I've coded and tried to plot a STRAIGHT line I cannot figure it out. I also can't figure out how to only see one Buy Bubble until the Close Bubble or Stop Bubble. I can only seem to accomplish this if they are directly next to each other.
This is my request by priority:
Priority 1. Once I get a long signal bubble I don't want to SEE additional long signal bubbles again until after a sell or stop signal (stop signal still needs work, that is priority 2). I still want the long criteria to be there in a "def =" I just don't want to see any additional bubbles past the first (I still want the signal just not the bubble because that affects priority 2). Once I get a SellLong or StopLong signal, then the next trend begins and I want that Long Signal Bubble again. This applies to Short as well.
Priority 2. I am trying to plot a stop loss line from the high (for now) of the candle that gives me the signal. i.e.
I want this line to continue until I either get stopped out OR until I get a sell signal. In addition I would like to have it automatically adjust, if possible to the new low for a long position or high for a short position if I get another long or short signal (not bubble)
I hope this makes since. I believe it will be easy for some of the experienced guys. It's frustrating to me that I can't wrap my head around it.
Code:
#JT Trend V1
#08/10/2022
declare upper;
input ShowEMA = no;
input ShowVWAP = no;
input ShowHMA = no;
input ShowSMA = no;
#VWAP
input VwapNumDevDn = -2.0;
input VwapNumDevUp = 2.0;
def isPeriodRolled = compoundValue(1, getYyyyMmDd()!= getYyyyMmDd()[1], yes);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);
} else {
volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));
plot VWAP = price;
plot UpperBand = price + VwapNumDevUp * deviation;
plot LowerBand = price + VwapNumDevDn * deviation;
VWAP.setDefaultColor(color.orange);
VWAP.sethiding(!ShowVWAP);
UpperBand.setDefaultColor(color.red);
UpperBand.sethiding(!ShowVWAP);
LowerBand.setDefaultColor(color.green);
LowerBand.sethiding(!ShowVWAP);
#HMA
input HMAPrice = close;
input HMALength = 10;
input HMADisplace = 0;
plot HMA = MovingAverage(AverageType.HULL, HMAprice, HMAlength)[-HMAdisplace];
HMA.DefineColor("Up", color.green);
HMA.DefineColor("Down", color.red);
HMA.SetLineWeight(3);
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));
HMA.sethiding(!ShowHMA);
def HMA_VWAP_Close_Short = low < LowerBand within 3 bars and HMA > HMA[1];
def HMA_VWAP_Close_Long = high > UpperBand within 3 bars and HMA < HMA[1];
#SMA
input SMAPrice = close;
input SMALength = 20;
input SMADisplace = 0;
plot SMA = Average(SMAprice[-SMAdisplace], SMAlength);
SMA.SetDefaultColor(color.blue);
SMA.SetStyle(curve.short_dash);
SMA.SetLineWeight(3);
SMA.sethiding(!ShowSMA);
#EMA
input EMALength = 5;
plot EMA = ExpAverage(close, EMALength);
EMA.SetStyle(Curve.Short_Dash);
EMA.SetDefaultColor(color.green);
EMA.HideBubble();
EMA.sethiding(!ShowEMA);
#TSI
input TSILongLength = 25;
input TSIShortLength = 13;
input TSISignalLength = 8;
def TSIDiff = close - close[1];
def DoubleSmoothedAbsDiff = ExpAverage(ExpAverage(AbsValue(TSIDiff), TSILongLength), TSIShortLength);
def TSIRound = Round((100 * (ExpAverage(ExpAverage(TSIDiff, TSILongLength), TSIShortLength)) / DoubleSmoothedAbsDiff), 2);
#Volume (By RIPSTER)
input Show30DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 110;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;
input ShowPercentOf30BarAvg = yes;
input ShowSellVolumePercent = yes;
def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def buying = V*(C-L)/(H-L);
def selling = V*(H-C)/(H-L);
# Selling Volume
def SellVol = selling;
# Total Volume
def BuyVol = volume;
#Volume Data
def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
def curVolume = volume;
def percentOf30Bar = Round((curVolume / avg30Bars) * 100, 0);
def SellVolPercent = Round((Selling / Volume) * 100, 0);
# Labels
AddLabel(Show30DayAvg, "Avg 30 Days: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if percentOf30Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf30Bar >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf30BarAvg, PercentOf30Bar + "%", (if PercentOf30Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf30Bar >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(ShowSellVolumePercent, "Cur Bar Sell %: " + SellVolPercent, (if SellVolPercent > 51 then Color.pink else if SellVolPercent < 49 then Color.GREEN else Color.ORANGE));
input length = 50;
def Vol = volume;
def VolAvg = Average(volume, length);
###############################################
#Buy/Sell Signals
input ShowBuySellBubbles = yes;
def PerfectLong = (EMA > SMA) and (close > SMA) and (HMA > HMA[1]) and (TSIRound >= 3) and (Buying > Selling) and (high < UpperBand);
addchartbubble(ShowBuySellBubbles and PerfectLong and !PerfectLong[1], Low * 0.995, "Long", color.green, no);
def PerfectShort = (EMA < SMA) and (close < SMA) and HMA < HMA[1] and (TSIRound <= -3) and (Selling > Buying) and (low > LowerBand);
addchartbubble(ShowBuySellBubbles and PerfectShort and !PerfectShort[1], High * 1.005, "Short", color.green, yes);
def ClosePerfectLong = (close < SMA) or ((high > VWAP) within 3 bars and (HMA < HMA[1]) and (HMA[1] < HMA[2])) or ((high > UpperBand) within 3 bars and (HMA < HMA[1]) and (HMA[1] < HMA[2]));
addchartbubble(ShowBuySellBubbles and ClosePerfectLong and !ClosePerfectLong[1], Low * 0.995, "CloseLong", color.red, no);
def ClosePerfectShort = (close > SMA) or ((high < VWAP) within 3 bars and (HMA > HMA[1]) and (HMA[1] > HMA[2])) or ((high < LowerBand) within 3 bars and (HMA > HMA[1]) and (HMA[1] > HMA[2]));
addchartbubble(ShowBuySellBubbles and ClosePerfectShort and !ClosePerfectShort[1], High * 1.005, "CloseShort", color.red, yes);
plot StopPerfectLong = if PerfectLong then low else double.nan;
addchartbubble(ShowBuySellBubbles and low < StopPerfectLong, Low * 0.995, "StopLong", color.cyan, no);
plot StopPerfectShort = if PerfectShort then high else double.nan;
addchartbubble(ShowBuySellBubbles and high > StopPerfectShort, High * 1.005, "StopShort", color.cyan, yes);
#BUY ORDERS
input ShowOrders = no;
AddOrder(OrderType.BUY_TO_OPEN, ShowOrders and PerfectLong, open[-1], 100, Color.GREEN, Color.LIGHT_GREEN);
AddOrder(OrderType.SELL_TO_OPEN, ShowOrders and PerfectShort, open[-1], 100, Color.GREEN, Color.LIGHT_GREEN);
#SELL ORDERS
AddOrder(OrderType.SELL_TO_CLOSE, ShowOrders and ClosePerfectLong, close, 100, Color.RED, Color.LIGHT_RED);
AddOrder(OrderType.SELL_TO_CLOSE, ShowOrders and low < StopPerfectLong, close, 100, Color.RED, Color.LIGHT_RED);
AddOrder(OrderType.BUY_TO_CLOSE, ShowOrders and ClosePerfectShort, close, 100, Color.RED, Color.LIGHT_RED);
AddOrder(OrderType.BUY_TO_CLOSE, ShowOrders and high > StopPerfectShort, close, 100, Color.RED, Color.LIGHT_RED);
This is my request by priority:
Priority 1. Once I get a long signal bubble I don't want to SEE additional long signal bubbles again until after a sell or stop signal (stop signal still needs work, that is priority 2). I still want the long criteria to be there in a "def =" I just don't want to see any additional bubbles past the first (I still want the signal just not the bubble because that affects priority 2). Once I get a SellLong or StopLong signal, then the next trend begins and I want that Long Signal Bubble again. This applies to Short as well.
Priority 2. I am trying to plot a stop loss line from the high (for now) of the candle that gives me the signal. i.e.
Code:
plot StopPerfectLong = if PerfectLong then low else double.nan;
plot StopPerfectShort = if PerfectShort then high else double.nan;
I want this line to continue until I either get stopped out OR until I get a sell signal. In addition I would like to have it automatically adjust, if possible to the new low for a long position or high for a short position if I get another long or short signal (not bubble)
I hope this makes since. I believe it will be easy for some of the experienced guys. It's frustrating to me that I can't wrap my head around it.