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

Notification

Icon
Error

Options
Go to last post Go to first unread
Thom  
#1 Posted : Thursday, January 5, 2006 4:23:28 AM(UTC)
Thom

Rank: Member

Groups: Registered, Registered Users
Joined: 1/5/2006(UTC)
Posts: 14

Hey guys (& gals) New to MetaStock (9.0) and to the forum. Getting up to speed on formula language but not quite there yet... I'm looking to run a system test using sell/cover criteria that includes a basic ATR-based stop upon initial entry ONLY; I,m not looking for a trailing stop. My exit would be based on other criteria (assuming that my stop wasn't hit) that I can program without issues, but I can't seem to wrap my head around a way to program an inital ATR-based stop point that references my entry price and doesn't move. The standard stop options in the system tester don't quite get it done: I'm looking for something similar to the Maximum Loss stop but ATR-based rather than dollars or percentage of equity. This seems like it should be a very common and simple stop but I can't find it anywhere (already searched the formula database—surprised it isn't there) and can't seem to figure it out myself. Can anyone help me out with this one? Thom
wabbit  
#2 Posted : Thursday, January 5, 2006 4:54:52 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)
Have a look on the forum for Roy Larsens instructions on creating latches, or you can download a free .dll add-in from Richard Dale that does both initial stops AND trailing stops. If you dont want the trailing component you dont have to use it! Hope this helps. wabbit :D
Jose  
#3 Posted : Thursday, January 5, 2006 5:39:10 AM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
Any stop that requires a reference to the entry, is basically a self-referencing formula. A simple alternative to using Richard Dale's excellent Advanced Trailing Stop plug-in, would be a (slow) PREV-based latch such as used in this indicator: [code:1:b584ca1244] { EntryPrice/ATR reference, stoploss code example for use in EntryPrice-related exit. ©Copyright 2004~2006 Jose Silva For personal use only. http://www.metastocktools.com } { User inputs } multi:=Input("ATR stop multiplier",0,10,2); plot:=Input("[1]ATR Stop, [2]System signals",1,2,1); { Sample system Entry & Exit signals } entry:=Cross(C,Mov(C,21,E)); exit:=Cross(Mov(C,10,E),C); { ATR } ATRstop:=ATR(10)*multi; { Reference ATR at system entry, and apply to exit as a stoploss } trade:=If(PREV=0,If(entry,C,0), If(exit OR C<PREV-ATRstop,0,PREV)); { New entry signal } NuEntry:=trade>0 AND Alert(trade=0,2); { New exit signal } NuExit:=trade=0 AND Alert(trade>0,2); { True entry ATR stop } EntryATR:=ValueWhen(1,NuEntry,C-ATRstop); { Plot on price chart } If(plot=1,EntryATR,NuEntry-NuExit) [/code:1:b584ca1244] jose '-)
Thom  
#4 Posted : Saturday, January 7, 2006 5:11:12 PM(UTC)
Thom

Rank: Member

Groups: Registered, Registered Users
Joined: 1/5/2006(UTC)
Posts: 14

Thanks guys. Wow, I thought I was getting up to speed on the formula language; apparently, not so. I guess I'm used to working more with actual formulas and functions then I am with actually writing programming language. Everyone on this forum seems to be light years ahead of me (which perhaps is a good thing). Thank you both for your input and patience with the new guy. So as not to become a royal pain in the rear, could you guys point me in the right direction for actually learning the programming language myself rather than leaching off others knowledge? I've read the MetaStock primer, but obviously need more. Any aftermarket programming books available that cover whatever programming language is used (what language is used, by the way)? I'm up for the challenge! Wabbit, I had the Richard Dale plug-ins before coming online. As a function in a system test, they refer only to a formula; I found the formulas in the Indicator Builder. So far, so good. Here's where I'm lost: the formulas appear (to me) to require the input of KNOWN information (e.g. date I entered the trade, etc.). But, that's the point of the system test (amongst other things): to determine an entry date. It seems therefore, that the plug-in formulas can't be used in a system test as they require the input of otherwise unknown variables, thus leaving the formulas with no reference points with which to function (and I'm not sure how to modify them). Am I missing something here? Jose, I copied your example and pasted it into the Indicator builder so I could see how it presented itself, and try to work through the programming language. In you example you show: { ATR } ATRstop:=ATR(10)*multi; Then, later: { Reference ATR at system entry, and apply to exit as a stoploss } trade:=If(PREV=0,If(entry,C,0), If(exit OR C<PREV-ATRstop,0,PREV)); If I'm understanding things properly, in the portion of the formula that reads: If(exit OR C<PREV-ATRstop,0,PREV)); you have previously defined "ATRstop" as "ATR(10)*multi", and previously defined "multi" as "Input("ATR stop multiplier",0,10,2)" (the multipliers are 0,10,2). Is this correct? Am I on the right track? Thanks again, guys, for taking the time; I really appreciate it. Cheers, Thom
wabbit  
#5 Posted : Sunday, January 8, 2006 3:07:05 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)
Thom, I am not quite sure of your issue, so I hope that by providing an example it might helps solve your issue... {simple MA entry system} ma1:=Mov(C,7,S); ma2:=Mov(C,21,S); x:=ma1>ma2; entry:=x AND Alert(x=0,2); ExtFml( "AdvancedStop.StopLong", entry,C-2*ATR(10),0,0,0,0,0,0); An entry is triggered at the MA crossover. A stop loss is fixed at C-2*ATR(10). Now as there is no exit programmed here, this value will remain even though new 'entries' occur after the initial entry. If you program your entries AND exits (you might want to try the Latch function from the Forum.dll file) then the initial stop loss will be set et every entry. Any more questions, please ask Hope this helps, a little. wabbit :D
Thom  
#6 Posted : Tuesday, January 10, 2006 2:42:49 AM(UTC)
Thom

Rank: Member

Groups: Registered, Registered Users
Joined: 1/5/2006(UTC)
Posts: 14

Thanks Wabbit...the fog is beginning to lift. Appreciate the help. Working through the two examples has definitely helped. Thom
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.