logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages<12
Options
Go to last post Go to first unread
jjstein  
#21 Posted : Saturday, January 14, 2012 6:48:52 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Don't recall that ASF specified what to do if his Buy AND Sell occur on the same day.

Maybe he should weigh in...

asf08005  
#22 Posted : Saturday, January 14, 2012 8:06:54 PM(UTC)
asf08005

Rank: Member

Groups: Registered, Registered Users
Joined: 1/12/2012(UTC)
Posts: 13

Hey guys, I want to get out as soon as my stop is hit. I could still reenter EOD if stock reverses and ends up closing higher on the day with increased volume.
jjstein  
#23 Posted : Saturday, January 14, 2012 8:43:54 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
>>I want to get out as soon as my stop is hit.
In that case, the trailing stop would have to calculate from the previous close, since that is not known until AFTER the trading for the day is done.


>>I could still reenter EOD if stock reverses and ends up closing higher on the day with increased volume.

You would have to trade at the next day's open. That's an issue of timing for backtesting: You can't trade on the day of the close, since you would be using hindsight, a big NO-NO. Although it actually can be done using the System Tester (usually accidentally), you would get false, misleading results -- something you could never trade in the real world. The Strategic Delay would need to be set to 1 bar, so your actual trade would be at the next day's open.

asf08005  
#24 Posted : Saturday, January 14, 2012 9:50:21 PM(UTC)
asf08005

Rank: Member

Groups: Registered, Registered Users
Joined: 1/12/2012(UTC)
Posts: 13

ahh, I see what you mean. Right, in real-time I could check 10 minutes before the close and know if id want to buy again. But the tester wouldn't know if the stock was going to close higher with volume. So, with my stop exit-- Is this part of how metastock works? I guess my trading would involve intraday moves, but Metastock doesn't see intraday moves? It just calculates from the close? Though you would think that Metastock would be able to see if price broke my stop during the day by knowing the low of the day. And then just place a sell order for me to exit the trade at my stop price. Metastock knows what my stop price is. So, after the close of a day, if metastock sees that the low of the day was below my stop, I would exit the trade at my stop price.
wabbit  
#25 Posted : Saturday, January 14, 2012 10:11:51 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
In hindsight, MetaStock and every trader can see everything (do a search for things like LastValue(), Peak(), Trough(), Zig() etc and see what can be done with 20/20 hindsight).

ASF: you need to define the system to take into account what is possible in REAL LIFE trading.



wabbit [:D]

asf08005  
#26 Posted : Sunday, January 15, 2012 12:14:58 AM(UTC)
asf08005

Rank: Member

Groups: Registered, Registered Users
Joined: 1/12/2012(UTC)
Posts: 13

Wabbit, I think my designed system as John has coded it would be realistic. Although I know that it wouldn't be possible getting the exact closing price for my buys, I can't really determine what my exact buys would be. I can't say that I'd be able to get the exact open price either if I used that as my buy. If I were actually trading my strategy, I would be entering at the eod, so using the close would be ok. I must do more research on how to get out at my exact stop price. This too could be done. I know I wouldn't get my orders filled at exactly my stop. I would use stop market orders at mystop price. I know I would get some crappy fills on both ends, but it shouldn't make that much differed.t in my results. Ill get a good idea of the effectiveness of my system. The conditions I specified I do think are realistic. I just want to make sure the system runs through metastock correctly, identifying entries and exits the way I would in real time. If metastock cant buy and sell on the same day, that's fine. As John said, I could delay the buy by 1 day. I'm going to do some more research in the morning on different indicators. Thanks for helping me through this guys!
jjstein  
#27 Posted : Sunday, January 15, 2012 5:46:33 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Andrew -- Hang on for a bit...

On closer inspection, it turns out the Trailing Stop isn't working at all, and the Initial Stop not the way it should. I've just learned that PREV isn't working the way I expected. I thought it stored a value for the whole indicator variable, but it's just for a single variable in any given current expression/assignment.

Have to rethink things...

jjstein  
#28 Posted : Tuesday, January 17, 2012 3:54:06 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Andrew -- No full solution yet; here is something to play with, meanwhile.

It uses your criteria for a BUY and for the Initial Stop (low price 1st two days). After that, it uses the next higher low as a trailing stop.

It does NOT implement the percent off the close & low of the entry day, or buy after a sell on the same day.

Code:

{_Test}
Buy:=C>Ref(C,-1) AND V>Ref(V,-1);

Trade:=if(PREV=0, { no trade }
if(Buy,Low,PREV), { Set initial stop to low of buy bar }
if(L<PREV,0, { Stop hit, SELL }
Low) { otherwise raise (trail) stop to higher low }
);

Season:=if(Trade>0,1,-1);
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ Plot }
Trade;


These System Test settings should get you close to what you want:
*************
SYSTEM EDITOR
*************
GENERAL: Limit number of simultaneous positions to: 1

BUY ORDER: FmlVar("_Test","Signal")=1;
Order Type: Stop
Limit or Stop Price: CLOSE
Strategic Delay (Bars): Day: 0

SELL ORDER: FmlVar("_Test","Signal")=-1;
Order Type: Stop
Limit or Stop Price: ref(L,-1)
Strategic Delay (Bars): Day: 0


**************************
PERFORM TRADING SIMULATION
**************************
Select Securities
-----------------
Dates: 3024 periods (12 years)


System Testing Options
----------------------
Default Size: % of Available Equity: 100
Portfolio: "Check" Close all positions on the last bar.

*** Click the MORE button ***

System Testing Options
----------------------
BROKER Tab
Interest Rates: Set all to "0".

Margin Requirements (avoid use of margin):
Long Initial: 100%
Long Maintenance: 0%
Short Initial: 200%
Short Maintenance: 101%

Commissions:
Type: Percent of Transaction
Entry: 0.1%
Exit: 0.1%

TRADE EXECUTION Tab
-------------------
"Uncheck" Realistic Market Prices
Slippage: Set all to "0"


Uh, there are "issues" with the System Tester; see this file. Once the test is done, view the report and use "Plot on Chart" to check trades. On the report, click on the ORDERS tab and hit END; make sure that not too many orders got cancelled (if so, one of the settings above is not right). There is a same-day entry & exit on 3 Jan 06, but there shouldn't be -- I don't know why.

Results don't look good for VIAB; lousy Equity Curve.

asf08005  
#29 Posted : Tuesday, January 17, 2012 8:38:00 PM(UTC)
asf08005

Rank: Member

Groups: Registered, Registered Users
Joined: 1/12/2012(UTC)
Posts: 13

Interesting John. Not so sure about my strategy. Although its not exactly my strategy, its pretty close. I've been fooling around with different markets, trying to get some historical data in Metastock. I thought I could just use yahoo and wikiposit. Kinda a pain. Got a free trial from tradingdata. Only gives me about a year of data for most futures/stocks but still helps a lot. A few clicks and I have all the data downloaded. It would take weeks for me to get the data into metastock myself. I'm thinking its worth the $. Got any recs as to a good data source? I had been testing my strategy using papertrade since about August for stocks. I manually went through the nasdaq minis from about 2003. I was pretty excited with my results, the system looked very profitable. However, testing it now across many more markets, ive got a mixed bag. Some down, some barely above buy/hold, others outperform. Maybe I'll try to introduce my short strategy, this might help get a better curve. My short is pretty much the opposite of my long. Enter short when v> previous day and ends lower. Stops= must hold highs of first two days, then i use a trailing stop % (entryhigh-entryclose)/entryhigh). Then use lowest close + %. Its the same as the long strategy just switched around so, I'm guessing I can make a few modifications. --By the way, what would you be looking for in an equity curve? A nice steady rise with limited drawdowns? Thanks John.
jjstein  
#30 Posted : Wednesday, January 25, 2012 9:31:20 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Andrew -- OK, got something for you. Only part I could not work in is that 2nd day low (yet).

In brief:

1. Trailing Low
2. Entry Day Low plus % Entry Day Close (your original request)
3. Entry Day Low plus Trailing ATR

They all use a break by the LOW, and the Trailing ATR hangs off the CLOSE; these elements are easily adjusted.


--Johnathan

Code:

{_Test}
{*******************************}
{ Use trailing low only }
{*******************************}
Buy:=C>Ref(C,-1) AND V>Ref(V,-1);

Trade:=if(PREV=0, { no trade }
if(Buy,Low,PREV), { Set initial stop to low of buy bar or 0 if no buy signal }
if(L<PREV,0, { Stop hit, SELL, reset latch }
Max(Low,PREV) { otherwise raise (trail) stop to next higher low }
));

Season:=if(Trade>0,1,-1);
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ Plot }
Trade;

Code:

{_Test}
{*******************************}
{ Use low of entry bar, then % of Entry-day Close & Low off current close }
{*******************************}
Buy:=C>Ref(C,-1) AND V>Ref(V,-1);

{ Stores value of stop }
Trade:=if(PREV<=0, { no trade }
if(Buy,Low,PREV), { Enter trade, set initial stop to low of buy bar }
{ Stop hit if below % or entry day Low }
{ otherwise raise (trail) stop to next higher low }
{ If entry % based stop hit, SELL, reset latch }
if(L<Max(C*(1-(ValueWhen(1,PREV=0,C)-ValueWhen(1,PREV=0,L))/ValueWhen(1,PREV=0,C)),PREV),0,PREV)
);

Season:=if(Trade>0,1,-1);
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ Plot }
Trade;

Code:


{_Test}
{*******************************}
{ Use low of entry bar, then trailing ATR off highest close }
{*******************************}
A:=Input("ATR",1,10,3); { multiplier }
X:=Input("Periods",1,20,3); { periods }

Buy:=C>Ref(C,-1) AND V>Ref(V,-1);

{ Stores value of stop }
Trade:=if(PREV<=0, { no trade }
if(Buy,Low,PREV), { Enter trade, set initial stop to low of buy bar }
 { Entry % based stop hit, SELL, reset latch }
 { otherwise raise (trail) stop to next ATR }
if(L<Max(HighestSince(1,PREV=0,C)-A*ATR(X),PREV),0,PREV)
);

Season:=if(Trade>0,1,-1);
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ Plot }
Trade;


jjstein  
#31 Posted : Wednesday, February 1, 2012 1:54:02 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Andrew -- OK, have had a fresh look at all three, so will post here for discussion. Maybe someone else will chime in with a comment or improvement. I did make some changes, due to quirks in the System Tester, so it would use full equity.

First, here are the criteria:

Code:
################################################################
CRITERIA FOR ALL SYSTEMS
################################################################


**************************
PERFORM TRADING SIMULATION
**************************
Dates: 3024 periods (12 years)
Default Size: % of Available Equity: 100
Portfolio: "Check" Close all positions on the last bar.

----------
BROKER Tab
----------
Interest Rates: Set all to "0".

Margin Requirements (avoid use of margin):
Long Initial: 100%
Long Maintenance: 0%
Short Initial: 200%
Short Maintenance: 101%

Commissions:
{ Using $1.00 will match the trade count }
 Type: Points per Transaction
Entry: 1
 Exit: 1

-------------------
TRADE EXECUTION Tab
-------------------
"Uncheck" Realistic Market Prices
Prices: Set all to OPEN
Slippage: Set all to "0"
Delay order opening: 0



jjstein  
#32 Posted : Wednesday, February 1, 2012 2:06:55 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Here's the indicator; there's a "_Test Plot" to see the indicator as a trailing stop.

Code:
**************************************
{ System I:
 Initial Stop: Entry bar low
 Trailing Stop: Highest low during trade }
**************************************



################################################################
INDICATORS
################################################################

{_Test}
Buy:=C>Ref(C,-1) AND V>Ref(V,-1);

{ Store value of stop }
Trade:=if(PREV=0, { no trade }
if(Buy,Low,PREV), { Trade on, set initial stop, else 0 (no trade) }
if(L<PREV,0, { stop hit, set to 0 }
Max(Low,PREV) { otherwise raise (trail) stop to next higher low }
));

Season:=if(Trade>0,1,-1);
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ Plot }
Trade;



{*******************************}
{ Drag to main window.
 Style: DOTTED
 Weight: THICKEST
 Color: BLUE }
{*******************************}
{_Test Plot}

Max(Fml("_Test"),C*.8); { 80% gets plot out of the way, for visibility }



{*******************************}
OPTIONAL
{*******************************}
{ EXPERT - Highlights }
FmlVar("_Test","Season")=1; { GREEN=Trade On }
FmlVar("_Test","Season")=-1; { RED=Trade off }
1; { YELLOW=no signal }


{ Indicator to plot just Buy/Sell points }
FmlVar("_Test","Signal");


Here's a screen-shot:
UserPostedImage


Code:
################################################################
SYSTEM TEST: Settings & Code
################################################################
GENERAL: Limit number of simultaneous positions to: 1


BUY Order:
{Code}
dummy:=OPT1;
signal:=FmlVar("_Test","Signal")=1;
ref(signal,+1);

Order: STOP
Price: ref(C,+1)
Delay: Day: 1



SELL Order:
{Code}
signal:=FmlVar("_Test","Signal")=-1;
ref(signal,+1);

Order: STOP
Price: {"f" code box}

LastBar:=LastValue(Cum(1))=Cum(1);
ExitPrice:=Min(FmlVar("_Test","Trade"),ref(H,+1));
if(LastBar,typ(),ExitPrice);

Delay: Day: 1


OPTIMIZATION:

Set MIN, MAX and STEP for OPT1 to "1".



Finally, in case you've picked up the trial or Standard TradeSim:
Code:
################################################################
TRADESIM
################################################################
ExtFml("TradeSim.Initialize");
ExtFml("TradeSim.EnableProtectiveStop",0);
ExtFml("TradeSim.EnablePriceFilter");

LastBar:=LastValue(Cum(1))=Cum(1);
ExitPrice:=if(LastBar,Typ(),Min(ref(FmlVar("_Test","Trade"),-1),H));
EntryTrig:=FmlVar("_Test","Signal")=1;
ExitTrig:=FmlVar("_Test","Signal")=-1
OR LastBar; {Exit all}

ExtFml("TradeSim.RecordTrades",
"_Test",
LONG,
EntryTrig,
CLOSE,
LOW-0.01,
ExitTrig,
ExitPrice,
START);


Users browsing this topic
Guest (Hidden)
2 Pages<12
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.