help with a code

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

help with a code

Postby karlelias » 23 Oct 2014

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

Thanks in advance!!

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: help with a code

Postby furytrader » 23 Oct 2014

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

Postby karlelias » 23 Oct 2014

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

Thank you for your responce!

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: help with a code

Postby furytrader » 23 Oct 2014

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

Postby karlelias » 23 Oct 2014

I mean stop -3*ATR highest since position taken

thanks

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: help with a code

Postby furytrader » 23 Oct 2014

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

Postby karlelias » 24 Oct 2014

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

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: help with a code

Postby furytrader » 24 Oct 2014

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.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: help with a code

Postby ABC » 27 Oct 2014

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

Postby karlelias » 27 Oct 2014

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

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: help with a code

Postby ABC » 27 Oct 2014

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


Return to “MultiCharts”