GenerateStopLoss amount argument  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
gvandenbosch
Posts: 30
Joined: 24 Oct 2013
Has thanked: 9 times
Been thanked: 3 times

GenerateStopLoss amount argument

Postby gvandenbosch » 21 Nov 2013

Hi,

I want to set a stoploss according to an input.
For example on a session the loss is set to 1 dollar. Then I want to put the stoploss on the Bars price minus the stop loss.

I found this page https://www.multicharts.com/trading-sof ... ial_Orders describing the formula that calculate from amount to a price.

So in order to get the amount I want to pass with the GenerateStopLoss function I came up with this:

Code: Select all

this.dStopAmount = (dStopPrice - dClosePrice) * Bars.Info.BigPointValue;
However it generate the stop much earlier than the price I set.
Can someone give me a pointer what I am doing wrong?

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: GenerateStopLoss amount argument

Postby JoshM » 21 Nov 2013

(..)
However it generate the stop much earlier than the price I set.
Can someone give me a pointer what I am doing wrong?
That depends on which conditions trigger the stop-loss order submittance; you now have only shown how you calculate the stop amount, but not when these orders are send.
Last edited by JoshM on 21 Nov 2013, edited 1 time in total.

gvandenbosch
Posts: 30
Joined: 24 Oct 2013
Has thanked: 9 times
Been thanked: 3 times

Re: GenerateStopLoss amount argument

Postby gvandenbosch » 21 Nov 2013

I do the calculation once and then save it in an object property (this.dStopAmount).

Then on every calcbar I do:

Code: Select all

GenerateStopLoss(this.dStopAmount);

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: GenerateStopLoss amount argument

Postby JoshM » 21 Nov 2013

I do the calculation once and then save it in an object property (this.dStopAmount).

Then on every calcbar I do:

Code: Select all

GenerateStopLoss(this.dStopAmount);
If I look at the examples from the page you mentioned in your first post, I see methods that have parameters with positive values.

This calculation will not always return positive values:

Code: Select all

this.dStopAmount = (dStopPrice - dClosePrice) * Bars.Info.BigPointValue;
Try this instead:

Code: Select all

dStopAmount = Math.Abs(dStopPrice - dClosePrice) * Bars.Info.BigPointValue;
..
..
GenerateStopLoss(dStopAmount);

gvandenbosch
Posts: 30
Joined: 24 Oct 2013
Has thanked: 9 times
Been thanked: 3 times

Re: GenerateStopLoss amount argument

Postby gvandenbosch » 21 Nov 2013

It is not helping. I have made the stop price 1 dollar higher than closeprice.

But this is the result:
Image

It just has a few cents difference.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: GenerateStopLoss amount argument

Postby JoshM » 22 Nov 2013

It is not helping. I have made the stop price 1 dollar higher than closeprice.

(..)

It just has a few cents difference.
Have you set CurSpecOrdersMode to PerPosition or PerContract? See information about that here.

gvandenbosch
Posts: 30
Joined: 24 Oct 2013
Has thanked: 9 times
Been thanked: 3 times

Re: GenerateStopLoss amount argument

Postby gvandenbosch » 22 Nov 2013

It is on PerPosition, should this be PerContract to reach my goal?

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: GenerateStopLoss amount argument

Postby JoshM » 22 Nov 2013

It is on PerPosition, should this be PerContract to reach my goal?
Based on what I understand from your goal, it should be on PerContract.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: GenerateStopLoss amount argument

Postby Henry MultiСharts » 25 Nov 2013

Hi,

I want to set a stoploss according to an input.
For example on a session the loss is set to 1 dollar. Then I want to put the stoploss on the Bars price minus the stop loss.

I found this page https://www.multicharts.com/trading-sof ... ial_Orders describing the formula that calculate from amount to a price.

So in order to get the amount I want to pass with the GenerateStopLoss function I came up with this:

Code: Select all

this.dStopAmount = (dStopPrice - dClosePrice) * Bars.Info.BigPointValue;
However it generate the stop much earlier than the price I set.
Can someone give me a pointer what I am doing wrong?
Hello gvandenbosch,

We were unable to replicate this behavior with the formula. It works as expected on our end.
Image
Attachments
2013-11-25_104035_Stop.png
(159.53 KiB) Downloaded 972 times

gvandenbosch
Posts: 30
Joined: 24 Oct 2013
Has thanked: 9 times
Been thanked: 3 times

Re: GenerateStopLoss amount argument  [SOLVED]

Postby gvandenbosch » 25 Nov 2013

Thanks for the replies.

Changing it from PerPosition to PerContract and adding the Math.Abs helped solving the problem.
It is working as expected now.


Return to “MultiCharts .NET”