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

Notification

Icon
Error

Options
Go to last post Go to first unread
rasj  
#1 Posted : Wednesday, February 1, 2012 9:36:01 PM(UTC)
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times
I have a problem re this formula (in The Enhanced System Tester)as it returns 0.00 when I run Simulations: DayAfter:= Ref(EngulfingBull(),+1); DayAfterWhiteDay:= (DayAfter = White()); DayAfterBlackDay:= (DayAfter = Black()); EngulfingBull() and DayAfterWhiteDay I know it is the positive Ref() in DayAfter that's causing the problem. What I want to do is to put a filter on the day after the EngulfingBull()signal (and visa versa for the EngulfingBear() signal), and back-test it. Pls. correct/help me Thanks,
jjstein  
#2 Posted : Friday, February 3, 2012 5:16:49 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)
Robin -- Try this:

WhiteDayFollows:=White() AND Ref(EngulfingBull(),-1);
BlackDayFollows:=Black() AND Ref(EngulfingBull(),-1);
If(WhiteDayFollows,+1,If(BlackDayFollows,-1,0));

rasj  
#3 Posted : Friday, February 3, 2012 1:30:04 PM(UTC)
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times
Sorry, but it didn't work. Still 0.00 Doesn't Ref(EngulfingBull(),-1) refer to the day before the signal? And that should always be a black day hence the bullish engulfing signal. Unfortunately, I need something that refers to the day after a signal - in this case EngulfingBull()- has formed.
mstt  
#4 Posted : Friday, February 3, 2012 2:49:36 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Robin

I'm not goint to attempt to solve your problem but I have a suggestion that I think should serve you well. Regardless of how your particular problem plays out with the EST I suggest that you change your perspective from the present looking into the future ( Ref(x,+1) ) to be in the present and looking into the past. Usually this is a matter of simply delaying all expressions by one bar - references 1 bar into the future become expressions that look at the current bar, and results for the current bar become results from the previous bar.

MetaStock can look into the future for all data bars except the last one. You and I, however, are not able to do that and writing code that does the "impossible" is a sure cause of problems.

Roy
jjstein  
#5 Posted : Friday, February 3, 2012 4:07:33 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)
Robin -- You may need to "adjust" your thinking, so it's in line with how Metastock works. It might help to visualize by assuming you (and Metastock) are traversing a timeline -- like an X-AXIS on a chart -- from left to right, one bar at a time. It's a bit like Excel, so any "formula" you write will process each bar like an Excel "column" -- each bar starting with five "rows" already (OHLCV), plus a row for each formula/indicator you create; something like this:

1. Open
2. High
3. Low
4. Close
5. Volume
6. Formula/Indicator
.
.
.
x. Formula/Indicator


IMPORTANT NOTE: You are ALWAYS better off making a Custom Indicator and dragging it on a Chart, so you can see EXACTLY what formula code is doing. Only after that looks correct, should you try the code it in the System Tester. You can use the FML() and FMLVAR() functions to use EXACTLY the same code in the System Tester as you see on the chart.


Now, I'll try to answer your questions:

1. >>Unfortunately, I need something that refers to the day after a signal - in this case EngulfingBull()- has formed.

Using a "power tool" when all you need is a screwdriver. Don't use a "look ahead"; that's cheating and you will come to a bad end.<g>


2. >>Doesn't Ref(EngulfingBull(),-1 refer to the day before the signal?

Yes. You need to be a bit more precise -- to which signal do you refer, the Engulfing or the White?

Your original post SEEMED to say that you want to "filter" the EngulfingBull(); I would interpret that as follows:

On the day AFTER an EngulfingBull() signal, see if that day is a White() day. If so, use that as a BUY signal.

The code I posted says EXACTLY that:
Code:

WhiteDayFollows:=Ref(EngulfingBull(),-1) { Yesterday }
AND White(); { Today }


Your original code tried to say "If tomorrow is EngulfingBull() and tomorrow is White()," which refer to the same bar.


Hope that helps. Here is a "screen shot" of the code I posted:
UserPostedImage


3. If you still get bad results in System Tester, you need to post ALL the code you are using in the System Tester TABS, plus the settings you've used for the Simulation.
Code:

Here is an example:
**************************
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


4. HOW TO POST CODE: Put your code between these two lines, but take out the space after the first asterisk:

* code*
Put your code here.
* /code*

So it looks like this:

Code:

Put your code here.


5. HOW TO POST A CHART: In Metastock, use the "Save as HTML" option. Find the folder you just saved to, then use your web browser and go to www.IMGUR.com, drag the JPG or PNG file to the browser and UPLOAD it. Then click the BBCODE option, and switch back to the Forum and PASTE the image code.

Hope that helps,


rasj  
#6 Posted : Saturday, February 4, 2012 9:43:25 AM(UTC)
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times
Johnathan, All I want to to is back-test a theory I have re Engulfing Bull/Bear signals. I don't have a problem with the explorer as I already use the exact same solution you suggested. I only want to back-test this. So Does my Bullish (or Bearish) Engulfing System get better results if I add a 3rd day filter such as White() or Black() to it? Am I better off waiting an extra day to see how it ended before I react to an bullish/bearish engulfing signal? Unfortunately, I can't use the above solution when I am back-testing because I am testing various periods depending to see if my theory works better in a bear period or a bull period. I might for example look at the period of 584 Daily Bars 1/7/2009 Through 5/2/2011 (845 Days), and not last week or yesterday. So basically I don't know when a signal may have formed. I hope this can help you (and others) a little bit more.
jjstein  
#7 Posted : Saturday, February 4, 2012 1:36:00 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)
rasj wrote:
Am I better off waiting an extra day to see how it ended before I react to an bullish/bearish engulfing signal?

The only way to find out is to test each.

rasj wrote:
Unfortunately, I can't use the above solution when I am back-testing because I am testing various periods depending to see if my theory works better in a bear period or a bull period.

So...test both methods in each of your chosen periods.

rasj wrote:
I might for example look at the period of 584 Daily Bars 1/7/2009 Through 5/2/2011 (845 Days), and not last week or yesterday.

That shouldn't matter with the System Tester, but would with the Explorer -- which are you using for your study?

rasj wrote:
So basically I don't know when a signal may have formed.

Uh, either an Indicator on a Chart will show that, or the System Tester will plot results.

jjstein  
#8 Posted : Saturday, February 4, 2012 2:11:46 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)
Robin -- Thought maybe an example would help, so I ran both your ideas through the System Tester.

Here's the code:
Code:
{_Test1}
WhiteDayFollows:=Ref(EngulfingBull(),-1) { Yesterday }
AND White(); { Today }

BlackDayFollows:=Ref(EngulfingBear(),-1) { Yesterday }
AND Black(); { Today }

Buy:=WhiteDayFollows;
Sell:=BlackDayFollows;

{ SIGNAL - Filter repeats }
init:=Cum(IsDefined(Buy+Sell))=1;
Season:=ValueWhen(1,Buy-Sell<>0 OR init,Buy)*2-1;
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ PLOT }
Signal; { 1=Buy -1=Sell, No signal on 1st bar! }

UserPostedImage


Here's your "triple" test:
Code:
{_Test2}
WhiteDayFollowsTwice:=Ref(EngulfingBull(),-2) { Two days ago }
AND ref(White(),-1) { Yesterday }
AND White(); { Today }

BlackDayFollowsTwice:=Ref(EngulfingBear(),-2) { Two days ago }
AND ref(Black(),-1) { Yesterday }
AND Black(); { Today }

Buy:=WhiteDayFollowsTwice;
Sell:=BlackDayFollowsTwice;

{ SIGNAL - Filter repeats }
init:=Cum(IsDefined(Buy+Sell))=1;
Season:=ValueWhen(1,Buy-Sell<>0 OR init,Buy)*2-1;
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ PLOT }
Signal; { 1=Buy -1=Sell, No signal on 1st bar! }

UserPostedImage



I just used your opposite criteria for signals; there are no stops:
Code:
################################################################
SYSTEM TEST: Settings & Code
################################################################
GENERAL: Limit number of simultaneous positions to: 1


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

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



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

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



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

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



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

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



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

rasj  
#9 Posted : Monday, February 6, 2012 2:51:45 PM(UTC)
rasj

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/17/2008(UTC)
Posts: 21
Location: Houston, TX

Thanks: 2 times
Thx for the example, Jonanthan. Much better even-though my theory seems to be not such a good idea... There is one thing though, and because I normally use System Tester in a more simple way, that made me think. Technically in this instance EngulfingBear() is not a Sell signal but rather a Sell Short signal. Might that have an influence re the above coding (aka _Test1 & _Test2)?
jjstein  
#10 Posted : Monday, February 6, 2012 8:22:33 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)
Robin,

>>Technically in this instance EngulfingBear() is not a Sell signal but rather a Sell Short signal.

Then you need to come up with your own SELL signal.

Note that from your original post, I just took what you gave, made a best guess as to what you use as a SELL signal and tried to put together an example. The end result was meant to show you why the REF(x,+1) wasn't needed and to help you see how Metastock works the data.

Hopefully, the posted code is simple enough for you to modify and try other conditions.

Users browsing this topic
Guest (Hidden)
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.