# help with a code

Questions about MultiCharts and user contributed studies.
karlelias
Posts: 7
Joined: 23 Nov 2013

### help with a code

Can someone help me to code a signal?

Its a ATR trailing stop. Period 10 and 3 % down.

Also a indicator that plot this on the chart

Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

### Re: help with a code

When you say, period 10 and 3% down, what does that mean? Do you mean that you're using a 10 period ATR? Also, what does 3% down mean?

karlelias
Posts: 7
Joined: 23 Nov 2013

### Re: help with a code

Hi,

Yes i mean 10 ATR and a stop 3% down from where i bought. In daily chart.

Im sorry if i explain bad but im new in MC

Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

### Re: help with a code

It sounds like you're talking about two different stops:

1. Stop based on a 10-period ATR; and
2. Stop based on a 3% maximum loss.

Is that the case?

karlelias
Posts: 7
Joined: 23 Nov 2013

### Re: help with a code

I mean stop -3*ATR highest since position taken

thanks

Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

### Re: help with a code

A really easy way to do this (if you're long) is:

Code: Select all

`If MarketPosition = 1 Then Sell Next Bar At Highest(High,BarsSinceEntry(0)) - (3 * AvgTrueRange(10)) Stop;`

Note that this will not work a stop on the first day you're entered because it calculates the stop for the next bar; therefore, you may want to have some kind of fixed stop for the first day a trade is taken.

To use this with a short position, it's:

Code: Select all

`If MarketPosition = -1 Then BuyToCover Next Bar At Lowest(Low,BarsSinceEntry(0)) + (3 * AvgTrueRange(10)) Stop;`

Let me know if you have any problems with this.

karlelias
Posts: 7
Joined: 23 Nov 2013

### Re: help with a code

Thank you very much!!

I have another question:

How to plot this on the chart as dots? So i can visualy see where the stop is

thanks

Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

### Re: help with a code

See the help information on the TL_ keywords - these are used for drawing trendlines.

TL_New
TL_Delete
TL_SetSize
TL_SetStyle

...

In your case, you will need to "update" the trendline as your stop changes. What I would do is calculate the level of the stop as a separate variable and then use that variable for placing your stop order as well as plotting the trendline.

Check out the samples in the help file regarding trendlines and this should help. If you have any problems, post them here and hopefully we can figure it out.

ABC
Posts: 626
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 355 times
Contact:

### Re: help with a code

Since MC 9 you can use i_setplotvalue and i_getplotvalue to send plot values from a signal to an indicator and plot them from there. This might be a slightly simpler way to accomplish what you have in mind without having to use trendlines.

Regards,
ABC

karlelias
Posts: 7
Joined: 23 Nov 2013

### Re: help with a code

Thank you very much for your help!

Can you please explain how to use -i_setplotvalue and i_getplotvalue

Im really a beginner in MC

ABC
Posts: 626
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 355 times
Contact:

### Re: help with a code

This should provide you with all the information you need: https://www.multicharts.com/trading-soft ... tplotvalue