How to program a stop loss

Questions about MultiCharts and user contributed studies.
sips kk
Posts: 2
Joined: 17 Jun 2008
Location: Breda, The Netherlands

How to program a stop loss

Postby sips kk » 18 Jun 2008

Hi all!

I'm new to MultiCharts & EasyLanguage (I'm moving from the Metastock world into the ELA world). Please allow me to address the following... TS Chat Support indicated to me that special coding would be neccessary for this to accomplish...

Here we go.

What I want to do is this: I got a setup day. It has a low for the day of course :wink: . Let's say this was yesterday (the trade setup day). Now I want to enter the market long if today's high goes above yesterday's high. When I enter the market I immediately place a protective stop loss at yesterday's low - (minus) 2 pips.

The same goes for shorts: enter the market below the setup day's low, but buy to cover when the setup day's high is exceeded afterwards...

So when going long I want to place a SELL STOP order. Within EasyLanguage of MC I am only able to:
- either "Sell This Bar[On]Close"
- OR ... to "SetStopLoss(Amount)"

However... when (back)testing a system I do NOT want to exit on the day's close (no, I want to exit INTRADAY as soon as the stop level is hit!) NOR do I want to set a fixed amount for my stop loss (c'mon, that's pretty weird... and not the way most people would be trading in real life!)

In all: how would I program such a stop loss into the MC EasyLanguage? (I've fount that in TS there is a standard "ExitLong" function, but errrr.... that one does not exist in MC!)

Please help, I very much appreciate it!

(In case my description of the trades is not clear to you: please see the two screendumps EURUSD attached, one long where the stop loss was not triggered, one short where the stop loss did trigger.)
Attachments
nostoplosstrigger.JPG
Example with NO stop loss triggered
nostoplosstrigger.JPG (184.04 KiB) Viewed 486 times
stoplosstriggered.JPG
Example where stop loss did trigger
stoplosstriggered.JPG (114.68 KiB) Viewed 491 times

fs

Postby fs » 18 Jun 2008

As far as I know, what you are trying to do is not possible on daily bars. Limit and Stop orders can only be placed for the next bar, so you cannot exit on a stop on the same bar of entry and is limited to exit on close.

Also, ExitLong, you refer to was used in the older versions of EL In the older versions for Buys you used:
Buy and ExitLong
For shorts: Sell and ExitShort.

In the latest versions you use for buys:
Buy and Sell

For shorts: SellShort and BuyToCover or "Sell Short" and "Buy to Cover"

The only way I can think of doing what you are trying to do is to plot the symbol both in daily and intra day intervals, a 5 minute chart for example. Then you generate your signals based on the daily chart, but use the intraday chart to place the orders. So if you use 5 minute bars and the current 5 minute bar reach the high of yesterday and you go long, at the close of the 5 minute bar, you can place a stop order to exit your long at the low of yesterday. If you are not comfortable waiting up to 5 minutes to place your stop order, reduce the interval. Of course this will mean that you need to have access to intraday data.

- Fanus

PS: In AB this is possible to do what you want to do on daily bars, but the learning curve to program in AB is much, much steeper than to learn EL.


Return to “MultiCharts”