Setstoploss not working for me  [SOLVED]

Questions about MultiCharts and user contributed studies.
albevier
Posts: 24
Joined: 13 Nov 2005
Has thanked: 5 times
Been thanked: 3 times

Setstoploss not working for me

Postby albevier » 07 Jul 2022

When I started using EL and PL I couldn't get "setstoploss" to work and I simply created my own stop loss code. But now I would like to start using the reserve word "setstoploss" but I cannot get past either of two problems. This is a "me" problem, not an MC problem -- at least I can't believe it is an MC issue.

The code snippet can demonstrate the two problems.

Problem 1: setstoploss only works if it is hardcoded -- i.e. when an Input or a variable are used to hand over a value to setstoploss, the stop loss is triggered on the same bar and same price as the entry.

Problem 2: setstoploss uses only multiples of 100 to move the stop loss of a stock $0.50. E.g. the code snippet opens a long SPY position on 6/23 at 377.02. And setstoploss(600) exits the position several bars and 3pts later at 374.02.

I've found no mention of either of these issues on the forum, setstoploss seems to be a well proven and often used so it has to be something I'm just not seeing -- something simple, fundamental -- like looking for your glasses when they're on your head.

Can anyone point me in a direction?

Code: Select all

// // [IntrabarOrderGeneration = true] // IOG is not the issue. Inputs: StopAmount( 600 ); If time = 1015 then Buy next bar at open; //setstoploss(StopAmount) ; // Use one or the other, not both at the same time. setstoploss(600) ; setexitonclose; // This just keeps the chart organized

User avatar
Kate MultiCharts
Posts: 591
Joined: 21 Oct 2020
Has thanked: 9 times
Been thanked: 148 times

Re: Setstoploss not working for me

Postby Kate MultiCharts » 13 Jul 2022

Hello albevier,

Strategy only places 1 special setstoploss order. The amount set in the last setstoploss call executed by the script is applied. In your case, it’ll always be setstoploss(600) as it is your second call.

When changing the Inputs: StopAmount( 600 ); line of your script, please bear in mind that the StopAmount input value is taken from the signal’s settings (main MC window -> Format -> Study):
Please check this page for more info about setstoploss.

Here are some main points:
  • Amount is set in the symbol’s currency
  • Note the difference when using SetStopPosition and SetStopContract
  • In Format -> Strategy Properties -> Properties tab set Base Currency = None
  • Check the symbol’s parameters in QuoteManager (double-click the symbol -> Settings tab), for SPY it’s usually: PriceScale = 1/100; BigPointValie = 1; Min. movement = 1; Currency = USD
Also, you might want to check the setstoploss_pt keyword (amount is set in points), it might be more convenient to use.

albevier
Posts: 24
Joined: 13 Nov 2005
Has thanked: 5 times
Been thanked: 3 times

Re: Setstoploss not working for me

Postby albevier » 14 Jul 2022

Thanks Kate.

The problem was with the setstopposition. If I use "setstopshare" or "setstopcontract" everything works as I would expect.

As far as I'm concerned, problem solved.

But out of pure curiosity, (no response expected) I'd be interested to know why using, setstopposition gives the following results in the following code snippet.:

When setstopposition is set, the results of setstoploss are as follows:

Setstoploss at 1 and the stop is $0.01;
10 and the stop is $0.05;
50 and the stop is $0.25;
100 and the stop is $0.50;
600 and the stop is $3.00.

Symbol settings of default or custom (see attached) do not alter the above results.
And I see nothing out of the ordinary for the Instrument Properties (see attached).

Code: Select all

setstopposition; If time = 1015 then Buy next bar at open; Var: StopAmount(600) ; setstoploss(StopAmount) ; setexitonclose; // One trade per day makes easy troubleshooting
Instrument Properties.PNG
(19.25 KiB) Not downloaded yet
Symbol Settings.PNG
(12.1 KiB) Not downloaded yet

User avatar
Kate MultiCharts
Posts: 591
Joined: 21 Oct 2020
Has thanked: 9 times
Been thanked: 148 times

Re: Setstoploss not working for me

Postby Kate MultiCharts » 15 Jul 2022

albevier,

Most likely, you’re using stoploss + setstopposition for a 200 contract position. In that case with Setstoploss at 1 and the stop is $0.01 the order price is the same as with Setstoploss at 2 and the stop is $0.01.

That’s because the order price is rounded up or down according to the symbol settings. With such Stop Loss settings it is impossible to lose less than $2.

Take 10 and the stop is $0.05; for example.
Let’s say you have a long position with 200 contracts. You trade with setstopposition the amount of 10, with a Commission of 0.

The Stop price will be = AvgEntryPrice - 10 / BigPointValue/ CurrentShares
This price is rounded down with a step = PriceScale * MinMove

albevier
Posts: 24
Joined: 13 Nov 2005
Has thanked: 5 times
Been thanked: 3 times

Re: Setstoploss not working for me  [SOLVED]

Postby albevier » 15 Jul 2022

Thanks Kate! Makes sense.


Return to “MultiCharts”