Monetary Stop Loss in Opening Position Bar (without "setstoploss")

Questions about MultiCharts and user contributed studies.
fringe
Posts: 19
Joined: 17 Jan 2011
Been thanked: 2 times

Monetary Stop Loss in Opening Position Bar (without "setstoploss")

Postby fringe » 08 Jan 2019

Hello,
I have a problem with the reserved word "setstoploss".

If I use, in real trading, SA auto trading setting, I have no problem: the stop loss indicated in "setstoploss" is calculated from the theoretical entry price of the strategy (regardless of slippage) and, if the stop conditions occur, it can also trigger in the same bar where the position has been opened.

But, If I use the AA auto trading setting, "setstoploss" will refer to the real price (at the broker) of opening position, so stop loss order in incorrect due to slippage.
So, in this case, I've to express the stop loss not using "setstoploss".
Forse example, if I want a stop loss of 1,000$, instead of writing "setstoploss(1000);" I can write:
" Sell 1 contract next bar at (entryprice - 1000/bigpointvalue) stop;"

The problem is that, in this way, the stop loss will always start from the bar following the opening position bar.
Is there a way to trigger the monetary stop loss in the same bar where the position has been opened (without using "setstoploss")?

Thank you very much for the help!

User avatar
Anna MultiCharts
Posts: 457
Joined: 14 Jul 2017
Has thanked: 31 times
Been thanked: 112 times

Re: Monetary Stop Loss in Opening Position Bar (without "setstoploss")

Postby Anna MultiCharts » 17 Jan 2019

Hello, fringe!

In both AA and SA the price for setstoploss (and other algorithmic orders) is calculated from the entry order fill price (real price on the broker). Your workaround – "Sell 1 contract next bar at (entryprice - 1000/bigpointvalue) stop;" – will not be of much help as entryprice will return 0 until the entry order is filled.

You can either use IOG (https://www.multicharts.com/trading-sof ... Generation), or resort to this:

Code: Select all

if marketposition>0 and entryprice>0 then Sell 1 contract next bar at (entryprice - 1000/bigpointvalue) else setstoploss(1000);
Something similar is discussed in this Forum thread:
viewtopic.php?f=19&t=51667

fringe
Posts: 19
Joined: 17 Jan 2011
Been thanked: 2 times

Re: Monetary Stop Loss in Opening Position Bar (without "setstoploss")

Postby fringe » 23 Jan 2019

Hello Anna!
Thank you very much for your answer!
Just another question: using "entryprice" in the AA auto trading settings, does MC take theoretical entry price (to calculate the stops) or real execution price at the broker?
I ask you this because I detected a similar problem with a stop loss linked to the ATR.

My stop loss is:
If MP = 1 then sell ("SLl_1") Next Bar at (EntryPrice-0.20 * AvgTrueRange (10) of Data3) stop;

During real trading, yesterday MC used as "entryprice", the real entry price at the broker, not the theoretical one and in this way it calculated a wrong stop level!It's normal?

Thank you very much for the help!

User avatar
Anna MultiCharts
Posts: 457
Joined: 14 Jul 2017
Has thanked: 31 times
Been thanked: 112 times

Re: Monetary Stop Loss in Opening Position Bar (without "setstoploss")

Postby Anna MultiCharts » 14 Feb 2019

fringe,

EntryPrice Returns a numerical value, indicating the price at the initial entry into the specified position. The value is taken from the chart (from the strategy order).
In the SA mode EntryPrice (as well as the value on the chart) will coincide with the real FillPrice on the broker.
In the AA mode EntryPrice (the value on the chart) might be different from the real FillPrice on the broker.
If this is not what you experience, please insert Print statements to the code to output these prices and come to our Live Chat to demonstrate this on a Sim broker account.


Return to “MultiCharts”