Creating a trailing entry stop

Questions about MultiCharts and user contributed studies.
NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

Creating a trailing entry stop

Postby NW27 » 30 Dec 2011

Seasons Greetings to all,

How do you code a trailing entry stop?
Say the price is going up and I want a Sellshort stop order 3 points below the price.
I'm using intrabarordergeneration and the bar sizes could be 1..5 points in size.

Neil.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Creating a trailing entry stop

Postby TJ » 30 Dec 2011

Seasons Greetings to all,

How do you code a trailing entry stop?
Say the price is going up and I want a Sellshort stop order 3 points below the price.
I'm using intrabarordergeneration and the bar sizes could be 1..5 points in size.

Neil.
Have you tried the manual?

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

Re: Creating a trailing entry stop

Postby NW27 » 31 Dec 2011

TJ,

What manual? There isn't one for version 7.4, 7 or 6...
Or do you mean the TS EasyLanguage reference that has functions like "TrailingStopOrder" that don't exist in MC.

My question relaates to a Trailing entry order. I'm not sure that the above if it existed in MC would even work.

But thanks for the help.
Perhaps you could email me the Ver7.4 manual.

Neil.

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

Re: Creating a trailing entry stop

Postby JoshM » 31 Dec 2011

I can understand your frustration Neil with some undocumented aspects of MultiCharts, and perhaps you spend already too much time trying to solve the problem, but I don't think it's very constructive to make an unfriendly (that's how I read it) response to the first helpful comment in the thread. Before you know it, other users don't chime in with their possible helpful comments, or you get comments that are off-topic and not helpful at all (like this one :) ).

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

Re: Creating a trailing entry stop

Postby NW27 » 31 Dec 2011

Josh,

Fair enough comment on your behalf. Perhaps I was a put off a bit by TJ's responce.
But seriously, a responce of "look in the manual" is not a helpful responce.
As I put in my post, there is nothing that I can find in the old out dated manuals or help files, hence the reason I ask on the board.

I beleive the answer to the question that I have asked is not in a manual but more of a multi line coding requirement.

Neil.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Creating a trailing entry stop

Postby TJ » 31 Dec 2011

Josh,

Fair enough comment on your behalf. Perhaps I was a put off a bit by TJ's responce.
But seriously, a responce of "look in the manual" is not a helpful responce.
As I put in my post, there is nothing that I can find in the old out dated manuals or help files, hence the reason I ask on the board.

I beleive the answer to the question that I have asked is not in a manual but more of a multi line coding requirement.

Neil.
then you could have said.... "I have looked into xxx book, pg xxxx, and found nothing there."

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

Re: Creating a trailing entry stop

Postby NW27 » 31 Dec 2011

So TJ,

In regard to "Have you tried the manual?", what xxxx book and pg xxx should I be looking at?

Neil.

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

Re: Creating a trailing entry stop

Postby JoshM » 01 Jan 2012

As I put in my post, there is nothing that I can find in the old out dated manuals or help files, hence the reason I ask on the board.

I beleive the answer to the question that I have asked is not in a manual but more of a multi line coding requirement.
I think you're right, at least I couldn't find anything about a 'trailing entry stop'-order in the manuals.

In a related thread you asked..
Using the Intrabarordergeneration, it allows you to get into a trade a minute into a five bar but the creation of the orders for the exits (MC Setprofittarget or setbreakeven or setstoploss etc etc), do not appear until the 5min bar has completed. So any price movement in the next 4min could kill you.
However, on pdf page 92 from the EasyLanguage Essentials manual regarding IntraBarOrderGeneration:
Creating an intra-bar order strategy is exactly the same as a close of bar strategy;
it’s only the calculation procedure which is different. (...)
When intra-bar order generation turned on, next bar really means next tick.
So, when you submit a stop loss order "next bar" it does get executed on the same bar (if necessary) with IOG on.

Also, for the SetStopLoss commands and it's brothers:
EasyLanguage includes built-in exit commands that may be included directly in your strategies. These special commands will be active even on the bar of entry; that is, they are evaluated on each tick (regardless of any setting for Intrabar Order Generation on the Calculation tab of the Format Strategy dialog).
(p. 100, same manual)


That being said, that won't give yet an 'trailing entry stop'-position entry. However, such logic can be coded with with the IOG turned on. Because each tick gets evaluated with IOG on, you can submit a conditional market order which would act as a stop.

PS: I'm quite doubtful if the part below is correct, because wouldn't be an 'entry trailing stop' the same as a regular conditional market order? Hmm. The more I think about it, the more confused I get. :)

Anyway, let's say you want to enter when the Fast MA is below the Slow MA (short condition), and the price reaches a new low (trailing entry condition):

Image

Won't the following code (with 'one entry per bar' setting) be in effect an 'entry trailing stop'?

Code: Select all

[IntraBarOrderGeneration = TRUE]

Variables:
maFast(0), maSlow(0), lowestPrice(0), shortCondition(False);


// Short conditions, evaluated on the end of the bar
if (BarStatus(1) = 2) then begin

maFast = Average(Close, 9);
maSlow = Average(Close, 18);


if (maFast < maSlow) then
shortCondition = True
else
shortCondition = False;

if (MarketPosition(0) = -1) and (BarsSinceEntry(0) = 10) then
BuyToCover ("XS#1") all contracts next bar at market;

end;

lowestPrice = Lowest(Low, 30)[1]; // this would be the trailing part

// Submit a market order if the current tick is lower then
// the low of the previous 30 bars
if (shortCondition = True) and (Close < lowestPrice) then
SellShort ("ES#1") 1000 contracts next bar at market;
Which would give:
Image
Attachments
scr.222.png
Example2
(24.11 KiB) Downloaded 1362 times
scr.221.png
Example1
(16.43 KiB) Downloaded 1355 times

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

Re: Creating a trailing entry stop

Postby NW27 » 01 Jan 2012

Josh,
First, thank you for the huge responce.

In regard to the Intrabarordergeneration (IOG) - I created a signal and applied it to my IB account. Using the IOG, trades were entered in the first minute of a five minute bar, it was not until the bar had been completed that MC then created the StopLoss order and the ProfitTarget order. These then sat on the IB account. So whilst I watched the trade for the next 4 minutes of the entry bar, I was not protected. This I've seen on a real live account with my own eyes.
Once these orders are in play, they are now live market Stop or Limit orders, so thus can be filled intrabar.


In regard to the entry trailing stop order - Using your chart examples and a short trade example.
Please refer to the time of 12:14:30 and the minor correction towards price of 84100.
The idea is that I want to take a short position after the price has moved up and then returns back down. So when the price starts going up at the above time, I want to trail a 70pip stop below the high of the bars. This means that about midway on the 3rd red down bar, I will be short with a Sell stop order. So again its is another IOG.
The reality is that I see the 84100 as a significant price level that I'm expecting a correction against. This correction could have a 100pip window. So when the price goes north above 84050 and remains less then 84150 then I want a trailing Sell stop order 70 points below the current high. Using normal orders does not work. I need a definitive trailing price level. Potentially some inside bars and small reversals could also happen inside this window. They should not effect this order. As opposed to a normal order that would work at the bars close price.
Using IOG, every tick appears as the bar close not nessasarily the high/low of the current action. BUT at some stage, the close should also equal the high/low price. However, in testing this does not appear to be the case. If I create a variable and record the highest high of the close, after entering the range, this is different to the displayed 5min bar highs.
Again using your chart, it would appear that the highest high for the correction was 84110 yet in recording of the highest close, it may only get to 84095.

Thanks,
Neil.

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

Re: Creating a trailing entry stop

Postby JoshM » 02 Jan 2012

Thanks for your further clarification Neil. Now I understand what you're trying to do, but I don't know how this might be implemented. Would be interesting to hear what other users and MC Support think, especially for the quote below.
In regard to the Intrabarordergeneration (IOG) - I created a signal and applied it to my IB account. Using the IOG, trades were entered in the first minute of a five minute bar, it was not until the bar had been completed that MC then created the StopLoss order and the ProfitTarget order. These then sat on the IB account. So whilst I watched the trade for the next 4 minutes of the entry bar, I was not protected. This I've seen on a real live account with my own eyes.
Once these orders are in play, they are now live market Stop or Limit orders, so thus can be filled intrabar.
Regards,
Josh

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

Re: Creating a trailing entry stop

Postby NW27 » 02 Jan 2012

TJ,

We are at a loss. What manual and page do you refer to???

Neil.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: Creating a trailing entry stop

Postby SUPER » 02 Jan 2012

Using IOG, every tick appears as the bar close not nessasarily the high/low of the current action. BUT at some stage, the close should also equal the high/low price. However, in testing this does not appear to be the case. If I create a variable and record the highest high of the close, after entering the range, this is different to the displayed 5min bar highs.
Again using your chart, it would appear that the highest high for the correction was 84110 yet in recording of the highest close, it may only get to 84095.

Thanks,
Neil.
Under IOG, High does reflect high of the current bar so if you plotted/tracked Highest High it would match historical bars in real time and also after redrawing chart, can you possibly use it in your code....just wondering.

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

Re: Creating a trailing entry stop

Postby NW27 » 05 Jan 2012

Hi,
Just out of interest, I manually coded my Trailing entry stop.
Here is an example of it and my stops in action.
The DarkBlue circles are the trailing Entry Stop. When it reaches a certain price zone, they kick in.
The red "*" is the StopLoss. (Initial Stop)
The blue "B" is the break even stopping kicking in.
The DarkGreen triangles are the trailing stops.

Note - All of the text and symbols are embedded with the actual Symbol code.
sample.png
Sample of Trailing Entry and Trailing Exits.
(111.24 KiB) Downloaded 1197 times
Neil.


Return to “MultiCharts”