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

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
asf08005  
#1 Posted : Thursday, January 12, 2012 12:43:04 PM(UTC)
asf08005

Rank: Member

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

John, I decided to email you seperately after the forum crashed. This is in response to your code you provided for my strategy. I included a copy at the bottom. Also, I guess I can't include the pictures of my charts. I could email you them separate. You’ve made my life so much easier with your code! I really can’t thank you enough for your help. You saved me many many hours of frustration. You are a Metastock master. Hopefully, one day I’ll be able to pay you back when your code earns mucho dinero!! For the most part, the system works great. However, I did find a few times where it missed a sell signal. In the expert advisor, I plugged in a buy signal( the up arrow) when FmlVar("Fiber-One","SIGNAL")=1, and a sell signal ( down arrow) when FmlVar("Fiber-One","SIGNAL")=-1. I’ve been trying to understand your wonderful code. It helps if I break down the different coding into separate indicators, and then put them on my chart so I can see what is going on. I included a few pics I found of when a sell should be triggered. Perhaps I’m telling metastock the wrong function of when to sell. From what I can tell, you accurately coded my desired stops. I’ll try to describe the situation with the included charts. I made “entrylow1“ an indicator to help me visually understand the code. This looks like my desired stop of having the low after the day of my buy be a stop. However, on my chart it looks like the signal was missed. I should have been out of the trade on the 3rd day when the low was broken. Not sure why it wasn’t triggered. I would have received a separate buy signal that same day, as volume and price were higher than the previous day. Perhaps the system has trouble with having a sell signal and then a buy on the same day? I included another time this occured. Again, my sell signal occurred on the same day a buy was triggered. I think the system might have trouble with separate buy and sell signals on the same day. Heres a time where the low of the buy day is broken. I should be out of the trade. The more I look over the trades, it seems like this is the problem. It doesn’t just occur with the 2nd day low stop, it seems to ignore all 3 stop conditions on days where a buy signal and sell signal occur. I ran it through the EST, and the same thing happens. Not sure if you saw my response on the forum before everything got deleted. But, I can’t figure out the function to put in for my stop orders to fill as soon as price breaks one of my 3 stops. I can see how I can choose to get out of the trade at the open,high,low,close. Just can’t get the function right. I hope I’m not being too much of a pain in the ass. Again, you went well beyond my expectations of any help I thought I’d receive. I’m excited to test my strategy with Metastock. You have gotten me closer to testing than I’d ever get. -Andrew {_Test - Holds value of highest closing price when trade is active} Buy:=C>Ref(C,-1) AND V>Ref(V,-1); EntryLow0:=ValueWhen(1,Buy,L); x:=ValueWhen(1,Buy,Cum(1))+1; EntryLow1:=ValueWhen(1,Cum(1)=x,L); EntryClose:=ValueWhen(1,Buy,C); Pct:=(EntryClose-EntryLow0)/EntryClose; Sell:=Lor Lor L Tr:=If(PREV=0,If(Buy,C,0),If(Sell OR L {Filter repeat signal, 1=Buy -1=Sell, No signal on 1st bar!} init:=Cum(IsDefined(Buy+Sell))=1; Season:=ValueWhen(1,Buy-Sell0 OR init,Buy)*2-1; Signal:=If(SeasonRef(Season,-1),Season,0); {Plot} Tr; {**} To use with a System Test, use the following: BUY: FmlVar("_Test","Signal")=1; SELL: FmlVar("_Test","Signal")=-1; Here are my images. Its from my created expert advisor. All I did was put under trends tab: Bullish: FmlVar("_Test","Signal")=1; Bearish: FmlVar("_Test","Signal")=-1; Then, I made a symbol for each respective function. Bullish being the up arrow, bearish the down arrow. I pulled up a Viacom chart. I drew a circle around the bar that violated the stop but had no exit signal. The indicator is the "EntyLow1" condition from your code. I made a seperate indicator for it. -Broke low of 2nd day but stayed in trade.(Chart Below) UserPostedImage -Broke low of entry day, should have triggered exit. UserPostedImage -Here, system works as should!! UserPostedImage -Low of 2nd day broken, but no exit signal. UserPostedImage I also ran an EST. This is the same trade as the 2nd linked chart. UserPostedImage The more I look over all the trades, it does seem that its an issue of the system not wanting to take a buy and sell signal the same day.
jjstein  
#2 Posted : Friday, January 13, 2012 1:47:22 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)
Asf -- There still seem to be forum problems; emails aren't going out. I just happened to check the forum directly, and see you replied 12 hours ago!

Anyway: You're welcome! It looked like a big job for a newbie, so I jumped in.

QUESTION: What is the SYMBOL and YEAR for the charts you posted?

There may be both issues with the System Tester, and a few "logic" areas you need to be aware of and decide how to handle. I'll put that in a separate message, after you try the new code below, and see if you still have the same problems.

NOTE: Your initial and trailing stops are built-in to the indicator, in the "Sell" variable assignment. The comments may help. Also, this indicator is a "latch"; get Roy Larsen's Tutorial if you don't already have it; it will help you wrap your head around the "latch" concept, logic, etc.

The latch part of the indicator is calculated by the "Tr" variable, and gives the indicator its value. If you plot the indicator, it will show the Highest Close while a trade is active, and "0" otherwise. Other variables within the indicator can be referenced from outside using FMLVAR(). There is no actual reason to plot the indicator itself.


{_Test} {Latch holds value of highest close during trade}
{Trade entry}
Buy:=C>Ref(C,-1) AND V>Ref(V,-1) AND PREV=0;

{Remember entry conditions for initial stop}
EntryClose:=ValueWhen(1,Buy,C);
EntryLow0:=ValueWhen(1,Buy,L);
x:=ValueWhen(1,Buy,Cum(1))+1;
EntryLow1:=ValueWhen(1,Cum(1)=x,L);

{Calc trailing-stop percentage}
Pct:=(EntryClose-EntryLow0)/EntryClose;

{Trade exit -- Initial & trailing Stops, no actual system exit}
Sell:=L<EntryLow0
OR L<EntryLow1
OR L<PREV*(1-Pct);

{Filter repeat signal, 1=Buy -1=Sell, No signal on 1st bar!}
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);

{Set Latch to highest Close from filtered signal, 0=No Trade}
Tr:=If(PREV=0,If(Signal=1,C,0),If(Signal=-1,0,Max(C,PREV)));

{Plot - Display & sets indicator value for PREV logic}
Tr;
{**}


Offhand, I can't come up with an easy way to display both your "initial stop" and "trailing stop", but if you want to display just the "trailing stop", use a separate indicator, in a separate sub-window. Suggest you set the "Style" to "Dots", thicken them and plot in a separate window. To see the values, hover the mouse or right-click and click Copy, then Paste into a spreadsheet.

{_Test Stop}
{Only trailing stop}
Fml("_Test")*(1-FmlVar("_Test","Pct"));
{**}


In an Expert, use the following to show when the trade is active:

TREND or HIGHLIGHTS:
Buy: FmlVar("_Test","Season")=1;
Sell: FmlVar("_Test","Season")=-1;


Display the signals in a separate window with this:

{_Test Signal}
FmlVar("_Test","Signal");


You could also use the above for Expert SYMBOLS, but that could interfere with displaying System Tester results. I suggest you not use them for the moment.

jjstein  
#3 Posted : Friday, January 13, 2012 3:24:03 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)
Whoops! Please change the "Sell:=" line to:

Sell:=Buy=0 AND
(L<EntryLow0
OR L<EntryLow1
OR L<PREV*(1-Pct));


asf08005  
#4 Posted : Friday, January 13, 2012 7:36:27 AM(UTC)
asf08005

Rank: Member

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

Hey John, Looks like you fixed it!! I compared charts and signals are better. I tried both EST and Expert. Just wanted to make sure, I'm using the right formulas. For all my buys, (EST-buy order, Expert-bullish trends) I'm using FmlVar("Super System 2","SEASON") =1 For (EST-Sell order, Expert- Bearish Trends) i'm using FmlVar("Super System 2","SEASON") =-1. So, are the Season and Signal indicators interchangable? I see what you mean, the symbols do conflict. Could I use a Cross indicator for the stop function in EST? I guess I don't fully understand the logic behind the Metastock language. Basically, I've been guessing and checking to find the stop function, ha! I'm trying to work it through, " set a stop market order where the price breaks through the defined stops". Can't seem to get it though. Usually I never get my stop hit and the EST only has 1 trade. Thanks again John, truly been a life saver!
jjstein  
#5 Posted : Friday, January 13, 2012 10:16:48 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 -- The short answers are: "Signal" shows up when "Season" changes, and that "Stops" are already inside the Indicator.

"Signal" is one bar, either +1 or -1, when the Buy or Sell conditions have been met; all other times it is "0". Duplicates are ignored ("filtered" out); ie: After a Buy, the trade is active, but there may be another Buy before a Sell; the code "filters" those extra signals.

"Season" shows when the trade is in effect. After the first trade starts, it will ALWAYS be either +1 or -1.

FWIW, that 3-line section of code is generic and re-usable.

In an Expert, use "Season" for TREND and/or HIGHLIGHTS (to show the trade is open/closed, Long/Short, etc.), while "Signal" is used for a Buy or Sell signal in Expert SYMBOLS or a System Test.


>>Could I use a Cross indicator for the stop function in EST?

You're "overthinking"...Maybe you need to re-read the previous message? The indicator both signals trades AND has the stops built-in! (You did not specify an "exit", just initial and trailing stops.)

Use these for the System Test ORDER tabs:

BUY Order: FmlVar("_Test","Signal")=1;
SELL Order: FmlVar("_Test","Signal")=-1;

Before you play any more with the System Tester, check that the indicator signals are correct and that you (mostly) understand what is going on inside the indicator.

That is a SEPARATE issue from using it with the System Tester -- the indicator must first be right.

The System Tester has some settings and issues you MUST be aware of, such as Margin Use and Execution Delay, otherwise you can unintentionally "cheat" -- trade with hindsight/foreknowledge, like buy at the Open AFTER the Close. Tends to give impossible results, but the System Tester will NOT tell you that! You'll just see fastantic results never achievable in real-world trading.

I'll follow-up in a separate message.

asf08005  
#6 Posted : Friday, January 13, 2012 12:50:18 PM(UTC)
asf08005

Rank: Member

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

ah ha, that helped. I'm slowly learning more and your code has definitely helped. I'm totally new to coding and never considered myself that computer savvy. But, this stuff is pretty cool! My mind seems to grasp the code better when it is visually represented by an indicator on a chart. Working on Metastock has really opened my eyes to how computers can perform all different types of functions. It's all programmed into code. I guess thats the whole point of designing a mechanical system to trade based off of. It tries to turn your trading decisions into a robotic, computerized code, limiting the dangerous ingredient of human emotion! Your code is sooo close to perfection. I found a time where a stop should have been triggered. OK, I pulled up a Viacom chart. I used the expert. The trailing stop should have taken the trade out. I included the data needed. The highest close was 2 days day before the circled bar. Using the Pct trailing stop, my stop should have been $37.12. The circled bar is 6/13. Viacom-6/7/06 Close=36.29 Low=35.89 (Close-Low)/Close = .011 6/9/06 Close= 37.53 37.53-(37.53*.011)=37.12 6/13/06 Low=36.73 UserPostedImage I wish I could figure this out. Trailing stop pct is right.
jjstein  
#7 Posted : Friday, January 13, 2012 3:36:58 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)
Can you confirm a BUY on 12 Apr 06? It looks like there should have been a SELL on 13 Jun 06, or certainly on 21 Apr 06.

asf08005  
#8 Posted : Friday, January 13, 2012 4:00:32 PM(UTC)
asf08005

Rank: Member

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

Yes, I got a buy on april 12, 2006. Then a sell the next day, and a buy on the 21st. UserPostedImage
wabbit  
#9 Posted : Friday, January 13, 2012 6:40:18 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)
I know some of the posts from earlier went missing in the forum "hiccup" so there might have been a discussion already, but I am a little concerned about the entry condition; it looks like the system is entering on the close of the signal bar? Can ASF enter a trade after the market closes, or should the trade be taken at the open of the next bar? In which case, you need to do more code to eliminate the trade on 13th where the open price (the price at which the trade "should" have entered) is below the SL.


$0.02


wabbit [:D]

jjstein  
#10 Posted : Friday, January 13, 2012 6:41:34 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)
What are the conditions for the color scheme you're using -- Green & Red bars vs. White arrows? It's getting a little confusing...

jjstein  
#11 Posted : Friday, January 13, 2012 7:38:57 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)
Hi Wabbit! Back from your travels, I presume?

Am trying to get the signal correct, as described -- will add "Strategic Delay" in System Tester.

Something's off on the Trailing Stop, and am trying to figure it out...the symbol is VIAB (Norgate) or VIA.B (Equis), the BUY date is 9 Jun 06 and on 13 Jun 06 the STOP is 37.12, which should trigger a SELL with a 36.73 LOW price on the that date.

But it's not...

CODE
{_Test} {Latch holds value of highest close during trade}
{Trade entry}
Buy:=C>Ref(C,-1) AND V>Ref(V,-1) AND PREV=0;

{Remember entry conditions for initial stop}
EntryClose:=ValueWhen(1,Buy,C);
EntryLow0:=ValueWhen(1,Buy,L);
BuyBar:=ValueWhen(1,Buy,Cum(1));
x:=BuyBar+1;
EntryLow1:=if(Cum(1)>BuyBar,ValueWhen(1,Cum(1)=x,L),0);

{Calc trailing-stop percentage}
Pct:=(EntryClose-EntryLow0)/EntryClose;

{Trade exit -- Initial & trailing Stops, no actual system exit}
Sell:=Buy=0 AND
(
L<EntryLow0 OR
L<EntryLow1 OR
L<PREV*(1-Pct)
);

{Filter repeat signal, 1=Buy -1=Sell, No signal on 1st bar!}
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);

{Set Latch to highest Close from filtered signal, 0=No Trade}
Tr:=If(PREV=0,If(Signal=1,C,0),If(Signal=-1,0,Max(C,PREV)));

{Plot - Display & sets indicator value for PREV logic}
Tr;
{**}


{_Test Stop}
{Only trailing stop}
Fml("_Test")*(1-FmlVar("_Test","Pct"));
{**}


{_Test Signal}
FmlVar("_Test","Signal");


{_Test BUY}
FmlVar("_Test","Buy");


{_Test SELL}
If(FmlVar("_Test","Sell"),-1,0);

UserPostedImage

asf08005  
#12 Posted : Friday, January 13, 2012 7:46:34 PM(UTC)
asf08005

Rank: Member

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

John, Green for up days, Red for down days, I'm using the white arrows as symbols for buys and sells in my expert. The charts shown have the Expert attached. Symbols Tab: Up arrow(Buy)= FmlVar("Super System 2","SIGNAL")=1 Down arrow(sell)= FmlVar("Super System 2","SIGNAL")=-1 My concern was that the system didn't exit a trade when the trailing stop should have been hit. I'll try to provide a rundown of the trade. On, 6/7/06, I had a buy signal. The range % calculated from the entry day(6/7/06) =(Close-Low)/Close = (36.29-35.89)/36.29 = .011. The highest close was 6/9/06.($37.53). Therefore, the programmed stop should have been = close - (close*%) = $37.53 - (37.53*.011) = $37.12. the next day(6/12/06) the low of the day held my stop of $37.12. I'm still in the trade, and since the stock hasn't closed higher than 6/9/06, the stop stays the same. 6/13/06- low of the day was $36.73, my stop of $37.12 would have been broken. I should be out of the trade. Wabbit, i'm still trying to work on my entries and exits. John has been a wonderful help, and I'm sure the information he has provided should tell me what my entry and exit functions should be. But, I have a lack of ability. From what I have learned about Metastock so far, the EST and Expert show similar indicators just looking at a chart. The expert allows me to plug in my buy and sell functions, and then I can plot them on a chart using symbols. It doesn't show me the exact price of entry and exit, just the days I should make a trade in or out. I'm aware that the EST has some serious problems that need to be considered when using it. Results cannot be taken to the bank. One of the problems I have has been writing the order type functions under the buy and sell order tabs. For buys, I want to enter at the eod. If I was making the trades in real-time, I'd log onto my broker around 3:50, and place a buy market order. I know that in reality I wouldn't get the exact closing price on all trades. However, when calculating stops and committing to the rest of my system, I wouldn't be using the price my market order was filled at anyway. I'd use the close of the day in calculations. I'll consider this a slippage cost and try to work this into my system. Hope that made a little sense, haha. So, as I run my system now, I don't have an actual buy order function or sell order function. They are both checked as market orders. My orders are getting filled according to the specifications under the Trade Sim - system testing options tab. Under the Trade Execution tab, I see I can choose O,H,L,C for Buy and Sell Price. This is OK for my entry, because I want to enter at the closing price anyway, However, it doesn't work for my sell order. I want to exit exactly when my stop price is broke. Currently, the EST sees the day when my stop is hit, and then listens to the Trade execution to determine the price I exit at. I have to figure out how what my sell order type function is so I get out exactly at my stop price. Although not realistic, once I get everything in place, the EST should give me a rough idea of the effectiveness of my strategy, no? Please let me know if I should be aware of something else. I got tired of manually running through my strategy in Excel, looking at charts of different markets. That is why I have turned to Metastock. To have a more accurate, consistent backtest of my system across all markets. I've been pleasantly surprised about the wealth of information available to Metastock users. This forum has been a great resource!!
wabbit  
#13 Posted : Friday, January 13, 2012 8:06:57 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)
jjstein wrote:
Hi Wabbit! Back from your travels, I presume?


Unfortunately, yes. We had an awesome year in Europe, so it is a little sad that it is over (until our next adventure!)


wabbit [:D]

wabbit  
#14 Posted : Friday, January 13, 2012 9:04:31 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)
Can someone please explain how the stops are supposed to work?


wabbit [:D]

jjstein  
#15 Posted : Friday, January 13, 2012 9:47:11 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)
The original message was lost, but it was an Initial Stop of the LOW for the first two days of the trade, with a Trailing Stop set from a percent of the entry-day close over the entry-day low.

Here's a re-write which might be a little more clear. It appears that the TrailingStop is set to zero, but I can't figure out why.


{_Test} {Latch holds value of highest close during trade}
{Trade entry}
Buy:=C>Ref(C,-1) AND V>Ref(V,-1) AND PREV=0;

{Remember entry conditions for initial stop}
EntryClose:=ValueWhen(1,Buy,C);
EntryLow0:=ValueWhen(1,Buy,L);
BuyBar:=ValueWhen(1,Buy,Cum(1));
EntryLow1:=If(Cum(1)>BuyBar,ValueWhen(1,Cum(1)=BuyBar+1,L),EntryLow0);

{Calc trailing-stop percentage}
Pct:=(EntryClose-EntryLow0)/EntryClose;

InitialStop:=Max(EntryLow0,EntryLow1);
TrailingStop:=PREV*(1-Pct);
ComboStop:=Max(InitialStop,TrailingStop);

{Trade exit -- Initial & trailing Stops, no actual system exit}
Sell:=Buy=0 AND L<ComboStop;

{Filter repeat signal, 1=Buy -1=Sell, No signal on 1st bar!}
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);

{Set Latch to highest Close from filtered signal, 0=No Trade}
Tr:=If(PREV=0,If(Signal=1,C,0),If(Signal=-1,0,Max(C,PREV)));

{Plot - Display & sets indicator value for PREV logic}
Tr;

jjstein  
#16 Posted : Friday, January 13, 2012 9:48:06 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)
The Trailing stop percent is calculated from the highest close of the current trade.

wabbit  
#17 Posted : Saturday, January 14, 2012 12:01:06 AM(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 this code from a few posts ago :

Code:

{Trade exit -- Initial & trailing Stops, no actual system exit}
Sell:=Buy=0 AND
(
L<EntryLow0 OR 
L<EntryLow1 OR 
L<PREV*(1-Pct)
);


the Sell function is a Boolean value, of which you are taking the PREV then multiplying it by a pct??

I think something like this might suit better:

Code:

SL:=
if(Buy,L,
if(ref(Buy,-1),HHV(L,2),
HighestSince(1,Buy,(1-Pct)*L)));


or am I missing something?



wabbit [:D]

jjstein  
#18 Posted : Saturday, January 14, 2012 9:33:23 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)
PREV just stores the highest close since the start of the trade; L<PREV*(1-Pct) checks if the trailing stop has been hit.


{Trade exit -- Initial & trailing Stops, no actual system exit}
Sell:=Buy=0 { this bar is not a buy signal, so check for stop being hit }
AND
(
L<EntryLow0 OR { Initial Stop #1 }
L<EntryLow1 OR { Initial Stop #2 }
L<PREV*(1-Pct) { Trailing Stop }
);


Wabbit -- How do you do the "Code" indent in the message?

jjstein  
#19 Posted : Saturday, January 14, 2012 1:28:13 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)
OK, I've simplified things, to try and narrow down the problem:

{_Test}
{Buy on higher close and higher volume.
Use 5% trailing stop, calculated off highest close during trade.
Latch holds value of highest close during trade.}
Buy:=C>Ref(C,-1) AND V>Ref(V,-1);
TrailingStop:=PREV*(0.95);
Sell:=L<TrailingStop;
Tr:=If(PREV=0,
If(Buy,C,0),
If(Sell,0,Max(C,PREV)));
Tr;


The SELL never triggered, so I looked at TrailingStop:

{_Test TrailingStop}
FmlVar("_Test","TrailingStop");

...which is never changes from "0".

Why?

wabbit  
#20 Posted : Saturday, January 14, 2012 4:25:22 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)
Your use of the PREV function is flawed.

Ask yourself these questions:
Q. On the first bar, what is the value of the TrailingStop variable?
A. Zero.

Q. On the second bar, what is 0.95 * PREV?
A. Zero.

Q. On any bar after, what is 0.95 * PREV?
A. Zero.


Compare this code to yours by looking at the very left hand side of the chart.

Code:

TrailingStop:=If(Cum(1)=1,C,PREV*(0.95)); {exponential decay of price}

TrailingStop;


then ask yourself the same questions as above.

Armed with this knowledge, we can write a "simple" Larsen-latch but it is going to contain at least four PREV calls (which is going to be slow) and will not allow a trade to exit and enter on the same bar as required by ASF (as an indicator, but it MIGHT in the EST).


Hope this helps.

wabbit [:D]

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