Adding a cloud between two signals

Reasonable_Drag

New member
Hi, I've amalgamated a custom study that gives me either a long or short signal whenever two conditions are met. I currently have it set up to add an up arrow and down arrow to the chart, but I'm trying to figure out a way to create a cloud overlay that shows either a green cloud if I've gotten a long signal and there has not been a subsequent short signal, or a red cloud for the opposite conditions. Can anyone help me?

I've posted the code below. And to clarify, I'm not wanting to create a cloud between the two different HMA lengths, but rather the signals that are generated from the different variables of the HMA lengths. Thanks in advance for any help that can be offered!

Code:
############
# Second Derivative of HMA on 100 Length
############

input HMAprice = HL2;
input HMA_Length = 100;
input lookback = 2;

def HMA = HullMovingAvg(price = HMAprice, length = HMA_Length);

def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;

def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;
def turning_point = if concavity[1] != concavity then HMA else double.nan;

def HMAsellSig = if turning_point and concavity == -1 then high else double.nan;
def HMAbuySig = if turning_point and concavity == 1 then low else double.nan;

def SlowHMABuy; if (HMABuysig) {SlowHMABuy = 1;} else if (HMASellSig) {SlowHMABuy = 0;} else {SlowHMABuy = SlowHMABuy [1];}
def SlowHMASell; if (HMASellSig) {SlowHMASell = 1;} else if (HMABuySig) {SlowHMASell = 0;} else {SlowHMASell = SlowHMASell[1];}

############
# Max and Min Point HMA on 22 Length
############

input HMA22price = HL2;
input HMA22_Length = 22;
input lookback22 = 2;

def HMA22 = HullMovingAvg(price = HMA22price, length = HMA22_Length);

def HMA22sellSig = if HMA22[-1] < HMA22 and HMA22 > HMA22[1] then HMA22 else Double.NaN;
def HMA22buySig = if HMA22[-1] > HMA22 and HMA22 < HMA22[1] then HMA22 else Double.Nan;

def HMA22Buy; if (HMA22Buysig) {HMA22Buy = 1;} else if (HMA22SellSig) {HMA22Buy = 0;} else {HMA22Buy = HMA22Buy [1];}
def HMA22Sell; if (HMA22SellSig) {HMA22Sell = 1;} else if (HMA22BuySig) {HMA22Sell = 0;} else {HMA22Sell = HMA22Sell[1];}


def HMABuy = (SlowHMABuy and HMA22Buy);
def HMASell = (SlowHMASell and HMA22Sell);

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

def up = HMABuy;
def down = HMASell;

def Hold_Up_Value = if up then 1 else if !down then Hold_Up_Value[1] else 0;
def Hold_Dn_Value = if down then 1 else if !up then Hold_Dn_Value[1] else 0;

#########
# Plots #
#########

plot Signal_Up = if up and Hold_Dn_Value[1] == 1 then low else Double.NaN;
Signal_Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal_Up.SetDefaultColor (color.GREEN);
Signal_Up.SetLineWeight(5);
plot Signal_Dn = if down and Hold_Up_Value[1] == 1 then high else Double.NaN;
Signal_Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Signal_Dn.SetDefaultColor (color.RED);
Signal_Dn.SetLineWeight(5);
 
Solution
Hi, I've amalgamated a custom study that gives me either a long or short signal whenever two conditions are met. I currently have it set up to add an up arrow and down arrow to the chart, but I'm trying to figure out a way to create a cloud overlay that shows either a green cloud if I've gotten a long signal and there has not been a subsequent short signal, or a red cloud for the opposite conditions. Can anyone help me?

I've posted the code below. And to clarify, I'm not wanting to create a cloud between the two different HMA lengths, but rather the signals that are generated from the different variables of the HMA lengths. Thanks in advance for any help that can be offered!

Code:
############
# Second Derivative of HMA on 100 Length...
@Reasonable_Drag When coding AddCloud() the first two parameters would be your triggers, the smaller being the first and the higher being the second...

Example: AddCloud(parameter1, parameter2, Color.GREEN, Color.RED);

This example would paint a Green cloud when fastHMA is greater than slowHMA and a Red cloud if slowHMA is greater than fastHMA...

Does this help in resolving your issue...???

You can find more information at https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddCloud
 
i think you misspoke @rad14733 , if the first cloud price parameter is bigger than the 2nd price parameter, then the first color is used, else the 2nd color.

test code
Code:
input top2 = 41.0;
input bot2 = 39.0;
addcloud(top2,bot2, color.green, color.red);
 
Hi, I've amalgamated a custom study that gives me either a long or short signal whenever two conditions are met. I currently have it set up to add an up arrow and down arrow to the chart, but I'm trying to figure out a way to create a cloud overlay that shows either a green cloud if I've gotten a long signal and there has not been a subsequent short signal, or a red cloud for the opposite conditions. Can anyone help me?

I've posted the code below. And to clarify, I'm not wanting to create a cloud between the two different HMA lengths, but rather the signals that are generated from the different variables of the HMA lengths. Thanks in advance for any help that can be offered!

Code:
############
# Second Derivative of HMA on 100 Length
############

input HMAprice = HL2;
input HMA_Length = 100;
input lookback = 2;

def HMA = HullMovingAvg(price = HMAprice, length = HMA_Length);

def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;

def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;
def turning_point = if concavity[1] != concavity then HMA else double.nan;

def HMAsellSig = if turning_point and concavity == -1 then high else double.nan;
def HMAbuySig = if turning_point and concavity == 1 then low else double.nan;

def SlowHMABuy; if (HMABuysig) {SlowHMABuy = 1;} else if (HMASellSig) {SlowHMABuy = 0;} else {SlowHMABuy = SlowHMABuy [1];}
def SlowHMASell; if (HMASellSig) {SlowHMASell = 1;} else if (HMABuySig) {SlowHMASell = 0;} else {SlowHMASell = SlowHMASell[1];}

############
# Max and Min Point HMA on 22 Length
############

input HMA22price = HL2;
input HMA22_Length = 22;
input lookback22 = 2;

def HMA22 = HullMovingAvg(price = HMA22price, length = HMA22_Length);

def HMA22sellSig = if HMA22[-1] < HMA22 and HMA22 > HMA22[1] then HMA22 else Double.NaN;
def HMA22buySig = if HMA22[-1] > HMA22 and HMA22 < HMA22[1] then HMA22 else Double.Nan;

def HMA22Buy; if (HMA22Buysig) {HMA22Buy = 1;} else if (HMA22SellSig) {HMA22Buy = 0;} else {HMA22Buy = HMA22Buy [1];}
def HMA22Sell; if (HMA22SellSig) {HMA22Sell = 1;} else if (HMA22BuySig) {HMA22Sell = 0;} else {HMA22Sell = HMA22Sell[1];}


def HMABuy = (SlowHMABuy and HMA22Buy);
def HMASell = (SlowHMASell and HMA22Sell);

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

def up = HMABuy;
def down = HMASell;

def Hold_Up_Value = if up then 1 else if !down then Hold_Up_Value[1] else 0;
def Hold_Dn_Value = if down then 1 else if !up then Hold_Dn_Value[1] else 0;

#########
# Plots #
#########

plot Signal_Up = if up and Hold_Dn_Value[1] == 1 then low else Double.NaN;
Signal_Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal_Up.SetDefaultColor (color.GREEN);
Signal_Up.SetLineWeight(5);
plot Signal_Dn = if down and Hold_Up_Value[1] == 1 then high else Double.NaN;
Signal_Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Signal_Dn.SetDefaultColor (color.RED);
Signal_Dn.SetLineWeight(5);

i think this is what you are asking for,
this draws clouds, over 3 bars, centered around signal bars.


make a set of rules to program
add a cloud when arrows appear, signal
cant have a cloud on 1 bar, so will make a cloud from the bar before a signal , to the bar after signal ( 3 bars )
if an opposite signal happens on next bar, then ignore the first signal
draw cloud from high and low, of signal bar
if a up arrow, up signal, then green cloud
if a down arrow, down signal, then red cloud


Code:
#hma_deriv_cloud
#https://usethinkscript.com/threads/adding-a-cloud-between-two-signals.20954/
#Adding a cloud between two signals

############
# Second Derivative of HMA on 100 Length
############

input HMAprice = HL2;
input HMA_Length = 100;
input lookback = 2;

def HMA = HullMovingAvg(price = HMAprice, length = HMA_Length);

def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;

def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;
def turning_point = if concavity[1] != concavity then HMA else double.nan;

def HMAsellSig = if turning_point and concavity == -1 then high else double.nan;
def HMAbuySig = if turning_point and concavity == 1 then low else double.nan;

def SlowHMABuy; if (HMABuysig) {SlowHMABuy = 1;} else if (HMASellSig) {SlowHMABuy = 0;} else {SlowHMABuy = SlowHMABuy [1];}
def SlowHMASell; if (HMASellSig) {SlowHMASell = 1;} else if (HMABuySig) {SlowHMASell = 0;} else {SlowHMASell = SlowHMASell[1];}

############
# Max and Min Point HMA on 22 Length
############

input HMA22price = HL2;
input HMA22_Length = 22;
input lookback22 = 2;

def HMA22 = HullMovingAvg(price = HMA22price, length = HMA22_Length);

def HMA22sellSig = if HMA22[-1] < HMA22 and HMA22 > HMA22[1] then HMA22 else Double.NaN;
def HMA22buySig = if HMA22[-1] > HMA22 and HMA22 < HMA22[1] then HMA22 else Double.Nan;

def HMA22Buy; if (HMA22Buysig) {HMA22Buy = 1;} else if (HMA22SellSig) {HMA22Buy = 0;} else {HMA22Buy = HMA22Buy [1];}
def HMA22Sell; if (HMA22SellSig) {HMA22Sell = 1;} else if (HMA22BuySig) {HMA22Sell = 0;} else {HMA22Sell = HMA22Sell[1];}


def HMABuy = (SlowHMABuy and HMA22Buy);
def HMASell = (SlowHMASell and HMA22Sell);

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

def up = HMABuy;
def down = HMASell;

def Hold_Up_Value = if up then 1 else if !down then Hold_Up_Value[1] else 0;
def Hold_Dn_Value = if down then 1 else if !up then Hold_Dn_Value[1] else 0;

#########
# Plots #
#########

input show_arrows = yes;
plot Signal_Up = if show_arrows and up and Hold_Dn_Value[1] == 1 then low else Double.NaN;
Signal_Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal_Up.SetDefaultColor (color.GREEN);
Signal_Up.SetLineWeight(5);
plot Signal_Dn = if show_arrows and down and Hold_Up_Value[1] == 1 then high else Double.NaN;
Signal_Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Signal_Dn.SetDefaultColor (color.RED);
Signal_Dn.SetLineWeight(5);

#-----------------------------

#    make a set of rules to program
# add a cloud when arrows appear, signal
# cant have a cloud on 1 bar, so will make a cloud from the bar before a signal , to the bar after signal ( 3 bars )
# if an opposite signal happens on next bar, then ignore the first signal
# draw cloud from high and low, of signal bar
# if a up arrow, up signal, then green cloud
# if a down arrow, down signal, then red cloud


def na = double.nan;
def bn = barnumber();

def arrow_up = up and Hold_Dn_Value[1] == 1;
def arrow_dwn = down and Hold_Up_Value[1] == 1;

input show_signal_clouds = yes;

#-----------------------
# up signals

def uphi;
def uplo;
if arrow_up[-1] and !arrow_dwn[-2] then {
# up cloud , up signal on next bar
 uphi = high[-1];
 uplo = low[-1];
} else if arrow_up[0] or arrow_up[1] then {
 uphi = uphi[1];
 uplo = uplo[1];
} else {
 uphi = 0;
 uplo = 0;
}


input test1_up_lines = no;
plot zuphi = if test1_up_lines and uphi > 0 then uphi else na;
plot zuplo = if test1_up_lines and uplo > 0 then uplo else na;
zuphi.SetDefaultColor(Color.green);
zuphi.hidebubble();
zuplo.SetDefaultColor(Color.green);
zuplo.hidebubble();


def upcldtop = if show_signal_clouds and uphi > 0 then uphi else na;
def upcldbot = if show_signal_clouds and uplo > 0 then uplo else na;
addcloud(upcldtop, upcldbot, color.green);


#-----------------------
# down signals

def dwnhi;
def dwnlo;
if arrow_dwn[-1] and !arrow_up[-2] then {
# down cloud , down signal on next bar
 dwnhi = high[-1];
 dwnlo = low[-1];
} else if arrow_dwn[0] or arrow_dwn[1] then {
 dwnhi = dwnhi[1];
 dwnlo = dwnlo[1];
} else {
 dwnhi = 0;
 dwnlo = 0;
}


input test2_down_lines = no;
plot zdwnhi = if test2_down_lines and dwnhi > 0 then dwnhi else na;
plot zdwnlo = if test2_down_lines and dwnlo > 0 then dwnlo else na;
zdwnhi.SetDefaultColor(Color.green);
zdwnhi.hidebubble();
zdwnlo.SetDefaultColor(Color.green);
zdwnlo.hidebubble();


def dwncldtop = if show_signal_clouds and dwnhi > 0 then dwnhi else na;
def dwncldbot = if show_signal_clouds and dwnlo > 0 then dwnlo else na;
addcloud(dwncldtop, dwncldbot, color.red);
#
 

Attachments

  • img1.JPG
    img1.JPG
    59.8 KB · Views: 31
Solution

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
372 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