ATR value at Entry

Questions about MultiCharts and user contributed studies.
User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

ATR value at Entry

Postby larssan » 06 Jul 2011

Hi,

I'm trying to create a code for scaling in to a position.

After the first entry I want to use the ATR value (of the entrybar) for scaling in the next contract.

Something like:

Code: Select all

Value1 = 1250;
if CurrentEntries = 0 then
BuyPrice = Value1 ;
ATR = AvgTrueRange(14);

if CurrentEntries = 0 then begin
Buy 1 Contract next bar at BuyPrice + 1 Point Stop;
Buy 1 Contract next bar at BuyPrice + 1 Point + (ATR*2) Stop;
end
else if CurrentEntries = 1 then
Buy 1 Contract next bar at BuyPrice + 1 Point + (ATR*2) Stop;
If the second Stop is hit in the same bar as the first it's ok, but if the second Stop is hit a few bars later then the Second Stop price is incorrect.
(It is not 1250 + 1 Point + ATR*2)

Even if the second entry is 20 bars later I still want to use the ATR value at the first entrybar.

I don't know if it's because the ATR isn't calculated from the first entrybar or if anything else is wrong.

Hope someone can help.

Thanks, Lars

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

Re: ATR value at Entry

Postby TJ » 06 Jul 2011

keep these in mind:

(except IOG IntrabarOrderGeneration)

1. all strategies are calculated at EOB (end of bar)

2. all orders are in effect for ONE bar only

3. [edited. For updated details, see Stan post below]


Therefore if you want the ATR value of a specific bar,
you can put the assignment inside a condition
so that the value does not get re-assign again.

Code: Select all

// the following statement is being re-assigned every bar
ATR = AvgTrueRange(14);

escamillo
Posts: 203
Joined: 25 Mar 2011
Has thanked: 23 times
Been thanked: 56 times

Re: ATR value at Entry

Postby escamillo » 06 Jul 2011

try something like this - not quite sure if this is what you mean but maybe.

if BarStatus(1) = 2 then
begin
if MarketPosition <> 0 then
begin
Once ATR = AvgTrueRange(14) ;

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 302 times

Re: ATR value at Entry

Postby Stan Bokov » 07 Jul 2011

3. at the end of the bar, any unfilled orders are cancelled,
and the autotrade logic are evaluated again.
If the market meets the logic conditions, new orders are issued.
TJ, thanks for the helpful hints. I just want to comment that on a new bar the script is re-evaluated again and a new 'pack of orders' is generated. If the newly generated order is the same as what's on the broker, it will not be cancelled and resubmitted - it will be left alone. Otherwise you would always be going to the back of the line. It would be left alone if it was exactly the same, in terms of quantity, etc. If something differed it would be cancelled and replaced. This was true for MC6.

In MC7 we changed that - now orders are modified. They are only cancelled and replaced if
1) order type changes and/or
2) direction of the order changes.

In all other cases the existing order is modified, which avoid losing your place in the queue.

User avatar
larssan
Posts: 61
Joined: 26 Feb 2011
Location: Sweden
Has thanked: 8 times
Been thanked: 8 times

Re: ATR value at Entry

Postby larssan » 08 Jul 2011

Thanks for the suggestions...

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 302 times

Re: ATR value at Entry

Postby Stan Bokov » 08 Jul 2011

For scaling out you can use the 'from entry' combination.

Entry
Used in strategy exit statements to tie an exit to the particular entry that was assigned the EntryLabel name.
An exit can only be tied to an entry within the same signal; for more information, see Buy or SellShort.

Usage
From Entry("EntryLabel")

Where: EntryLabel - the name that was assigned to the entry that the exit is to be tied to
From - a skip word and can be omitted

Example
Completely exit from the long position established by the entry labeled "Original Entry", at Market price on open of next bar:

Code: Select all

Sell From Entry("Original Entry")Next Bar At Open;


Return to “MultiCharts”