Help with some coding please

BBDPDC

Member
Hello folks

Long story short I'm stuck. The way i've cobbled this together has resulted in more signals (up arrows) than i want and i can't work out how to just get the signal to fire when the histogram starts to move back in a positive direction.

How do I amend the Upsignal instruction to only show on the first bar when momentum switches from negative to positive? It continues to fire until momentum turns negative.

I'd very much appreciate some advice from those of you with more experience if you have time please

Code:
declare upper;

input fastLength = 6;
input slowLength = 13;
input MACDLength = 5;
input averageType = AverageType.EXPONENTIAL;

def Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
def Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
def ZeroLine = 0;

def pos         = Value >= 0;
def neg         = Value < 0;
def up         = Value >= Value[1];
def dn         = Value < Value[1];

def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;

def pos1         = Avg >= 0;
def neg1         = Avg < 0;
def up1        = Avg >= Avg[1];
def dn1         = Avg < Avg[1];

def PosUp1 = pos1 and up1;
def PosDn1 = pos1 and dn1;
def NegDn1 = neg1 and dn1;
def NegUp1 = neg1 and up1;

#cloud
AddCloud(if Value < 0 then Double.POSITIVE_INFINITY else Double.NaN, if Value < 0 then Double.NEGATIVE_INFINITY else Double.NaN, Color.RED);
#AddCloud(if Value >= 0 then Double.POSITIVE_INFINITY else Double.NaN, if Value < 0 then Double.NEGATIVE_INFINITY else Double.NaN, Color.GREEN);

#Labels

#AddLabel (yes, if pos or up then " BULL " else "", Color.GREEN);
#AddLabel (yes, if pos1 or up1 then " BULL " else "", Color.GREEN);

#signals

input Klength = 10;
input price = close;

def K = (Highest(high, Klength) + Lowest(low, Klength)) /
2 + ExpAverage(close, Klength);
def Momo = Inertia(price - K / 2, Klength);

plot Upsignal = if Momo > Momo[1] and up then Momo else double.NaN;
Upsignal.SetDefaultColor(Color.WHITE);
upsignal.SetPaintingStrategy(PaintingStrategy.boolean_points);
upsignal.SetLineWeight(5);
 
Your condition for momentum:
Code:
plot Upsignal = if Momo > Momo[1] and up then Momo else double.NaN;
needs to be altered. It's firing on every candle where the condition (momentum is rising) it true, just as you described. You can look for minimums by adding an additional condition:
Code:
plot Upsignal = if Momo > Momo[1] and momo[1] < momo[2] and up then Momo else double.NaN;
See how that says 'only when the latest value is higher than the previous AND that previous is lower than the one before it'? We're looking for a low point, so momo[1] has to be the lowest of the three (momo, momo[1], and momo[2])

Perhaps that gets you going in the right direction. Good luck,

happy trading,
mashume
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Your condition for momentum:
Code:
plot Upsignal = if Momo > Momo[1] and up then Momo else double.NaN;
needs to be altered. It's firing on every candle where the condition (momentum is rising) it true, just as you described. You can look for minimums by adding an additional condition:
Code:
plot Upsignal = if Momo > Momo[1] and momo[1] < momo[2] and up then Momo else double.NaN;
See how that says 'only when the latest value is higher than the previous AND that previous is lower than the one before it'? We're looking for a low point, so momo[1] has to be the lowest of the three (momo, momo[1], and momo[2])

Perhaps that gets you going in the right direction. Good luck,

happy trading,
mashume

@mashume thank you sir, this is exactly what I needed and I've now learned something new!

I should mention I use this strategy along with your Hull Concavity Turning Points indicator with great success!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
633 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