#### PennyFlipper101

##### New member
how do I add an indicator that simply plots the words buy and sell on the main chart when certain conditions are met

I need input on this code it will not work, what is wrong?

# Trend Indicator for ToS

def Currentsum ;
def SDevCurrent;
def BBCurrentAve;
def Currentsumdirection;
#def CurrentSumPosture;

Currentsum = If(ExpAverage(close, 3) > ExpAverage(close, 7), 1,0) +
If(ExpAverage(close, 2) < ExpAverage(close, 5),-1,0)
+Currentsum[1];
Currentsumdirection = Currentsum - Currentsum[1];
BBCurrentAve = Average(Currentsum, 10);
SDevCurrent = StandardDeviation(Currentsum, length = 10);

plot Trendline = Currentsum ;

plot BBlower = BBCurrentAve - SDevCurrent * 1;
plot BBUpper = BBCurrentAve + SDevCurrent * 1;

#CurrentSumPosture = If(BBlower+Currentsum<0,BBlower+Currentsum,If((BBLower+Currentsum>=0 and Currentsum+BBUpper<=0),0,If(Currentsum+BBUpper>0,BBUpper-Currentsum,0)));

@PSandy Where did the code come from and is it related to this topic...??? Is this code you wrote, or did you find it elsewhere...??? All you've said is it doesn't work without any background as to what it should be doing... The more information we have the better we can be of assistance...

@PSandy Trying to get your logic in this, are you looking for the start of a downtrend?
It seems this event will only occur occasionally, I am not sure how you get a trend line from it. I think you need to plot an arrow where this condition currentsum is true. And maybe replace the " + " in your equation with an " and ".

@PSandy Where did the code come from and is it related to this topic...??? Is this code you wrote, or did you find it elsewhere...??? All you've said is it doesn't work without any background as to what it should be doing... The more information we have the better we can be of assistance...
This code was given to me, it is supposed to indicate when money goes into a stock and when money is flowing out.
@PSandy Trying to get your logic in this, are you looking for the start of a downtrend?
It seems this event will only occur occasionally, I am not sure how you get a trend line from it. I think you need to plot an arrow where this condition currentsum is true. And maybe replace the " + " in your equation with an " and ".
This indicator is supposed to show money going in and money going out.

I need input on this code it will not work, what is wrong?

I think the issue here is that this is meant to be a lower study but it doesn't declare that in the code. If you put it in the upper area of the chart the values aren't scaled to be relevant to current prices and it only appears near price coincidentally on some symbols.

Add a line to the code that says...
Ruby:
``declare lower;``
...and in your studies, drag it to one of the study slots labeled `Lower`.

I think the issue here is that this is meant to be a lower study but it doesn't declare that in the code. If you put it in the upper area of the chart the values aren't scaled to be relevant to current prices and it only appears near price coincidentally on some symbols.

Add a line to the code that says...
Ruby:
``declare lower;``
...and in your studies, drag it to one of the study slots labeled `Lower`.
I think the issue here is that this is meant to be a lower study but it doesn't declare that in the code. If you put it in the upper area of the chart the values aren't scaled to be relevant to current prices and it only appears near price coincidentally on some symbols.

Add a line to the code that says...
Ruby:
``declare lower;``
...and in your studies, drag it to one of the study slots labeled `Lower`.
Where would you recommend to put this line code?

@PSandy Anywhere. But it is usually placed as the first line of code.

87k+ Posts
278 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?