{
EasyLanguage Strategy Code
Population member: 27
Max bars back: 96
Created by: Adaptrade Builder version 1.3.0.1
Created: 8/21/2012 2:28:19 AM
Compatible with TradeStation 6 or newer
Price File: C:\Program Files\Adaptrade Software\Adaptrade Builder 1.3\Examples\1tick (2012.04.25-2012.05.04 downtrend).txt
Build Dates: 4/25/2012 to 4/25/2012
Project File: C:\Program Files\Adaptrade Software\Adaptrade Builder 1.3\Examples\1tick 2012.08.20d.gpstrat
}
{ Strategy inputs }
Inputs: FirstEntryTm (830),
LastEntryTm (1458),
NBarEn1 (90),
NATREn (83),
EntFr (2.7944),
TargFr (0.9845),
NATRTrail (96),
ATRFrTrail (4.1464),
TrailPct (44.0000),
NBarEx (17),
TimeEx (1459),
PSParam (50.00),
RoundPS (true),
RoundTo (1),
MinSize (1),
SizeLimit (1);
{ Variables for average true range for entry and exit orders }
Var: ATREn (0),
ATRTrail (0);
{ Variables for entry and exit prices }
Var: EntPrL (0),
TargPrL (0),
LStop (0),
NewLStop (0),
LTrailOn (false);
{ Variables for entry and exit conditions }
Var: EntCondL (false),
TimeOK (false);
{ Variables for position sizing }
Var: NShares (0);
{ Average true range }
ATREn = AvgTrueRange(NATREn);
ATRTrail = AvgTrueRange(NATRTrail);
{ Entry prices }
EntPrL = WAverage(C, NBarEn1) - EntFr * ATREn;
{ Entry and exit conditions }
EntCondL = true;
TimeOK = time >= FirstEntryTm and time < LastEntryTm;
{ Position sizing calculations }
NShares = PSParam;
If RoundPS and RoundTo > 0 then
NShares = IntPortion(NShares/RoundTo) * RoundTo;
NShares = MaxList(NShares, MinSize);
NShares = MinList(NShares, SizeLimit);
{ Entry orders }
If MarketPosition = 0 and EntCondL and TimeOK then begin
Buy("EnLimit-L") NShares shares next bar at EntPrL limit;
end;
{ Exit orders, long trades }
If MarketPosition > 0 then begin
If BarsSinceEntry = 0 then begin
LStop = 0;
LTrailOn = false;
end;
If C - EntryPrice > ATRFrTrail * ATRTrail then
LTrailOn = true;
If LTrailOn then begin
NewLStop = EntryPrice + TrailPct * (C - EntryPrice)/100.;
LStop = MaxList(LStop, NewLStop);
end;
If time >= TimeEx then
Sell("ExTime-L") next bar at market;
If BarsSinceEntry >= NBarEx then
Sell("ExNBars-L") next bar at market;
If LTrailOn then
Sell("ExTrail-L") next bar at LStop stop;
TargPrL = EntryPrice + TargFr * TrueRange;
Sell("ExTarg-L") next bar at TargPrL limit;
end;
On Tue, Aug 21, 2012 at 8:30 PM, mandelmus <gmb...@gmail.com> wrote:
<SNIP>
> I selected the option to "wait for exit before entering a new trade", but that didn't work as I expected it should.
<SNIP>
Then maybe your expectations are wrong?
This code:
If MarketPosition = 0 and EntCondL and TimeOK then
begin
Buy("EnLimit-L") NShares shares next bar at EntPrL limit;
end;
contains the only 'Buy' order in your code and CLEARLY it only enters when MarketPosition = 0;
I do not see how that code can:
<SNIP>
> keep adding positions until
> Tradestation rejects the new positions due to exceeding account equity.
<SNIP>
Again, it's just my opinion but just because Builder builds some code
doesn't mean that we users don't have a responsibility to understand
how the code works. Have you read and understood your code? I've only
glanced at it for 2 minutes but I don't see how it can do what you
suggest.
I then copied the code into a strategy file and applied it to a 1-tick
GOOG chart for the last 2 days. I never holds multiple positions of
adds positions that I can see.
It seems to me that nothing you are saying here is making any sense to
me so I suggest you take a deep breath, figure out what your issue is,
and then state it clearly with code, data, charts or something to
demonstrate it in a repeatable manner or else there's no way the rest
of us can participate. (Or at least I will not participate anymore
until those things clearly happen.) :-)
And BTW...
1) Do you really want to trade GOOG multiple times per minute? 3 days
produced 1075 trades?
2) Just my opinion, but if you were interested in trading this live
you had better look VERY deeply at how these limit orders are being
created and what the chances of getting filled really are.
Running this code on a 1-tick chart boggles my mind, but maybe there's a good
idea back there that I just don't understand.
3) This code buy single contracts. Is that what you really intend?
Question: Will market makers really do that in real life? Odd lot
fills and such?
Good luck!
Cheers,
Mark
Sounds like a setting in TS, but I don’t know off-hand why it would do that. I would check some of the settings in TS under Strategy Properties and maybe consult the associated documentation. You could also try searching the TS forum or even posting to it, but I’d suggest trying a bit longer to track down the issue on your own before posting on the TS forum.
Mike Bryant
Subject: Re: How to limit simultaneous open positions