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

Notification

Icon
Error

Options
Go to last post Go to first unread
a26174980  
#1 Posted : Friday, November 2, 2012 8:30:57 AM(UTC)
a26174980

Rank: Member

Groups: Registered, Registered Users
Joined: 11/2/2012(UTC)
Posts: 15

how to set a variable time in HHV? fo example HHV(c,time1) where time1 is a variable, but HHV doesnt allow variable
a26174980  
#2 Posted : Friday, November 2, 2012 8:44:15 AM(UTC)
a26174980

Rank: Member

Groups: Registered, Registered Users
Joined: 11/2/2012(UTC)
Posts: 15

i have one more problem... how to write a program satisfying the below: Condition 1: the price crosses Simple moving average of period 20 condition 2:the price crosses Simple moving average of period 50 the SELL command will only trigger (when condition 1 happens first ,and then condition 2 happens later) i dont know how to write a program that can confirm the conditions happen sequentially. thank you so much if u guys can help me!! this problem has bothered me for a long time!!
haddison  
#3 Posted : Saturday, November 3, 2012 8:32:06 AM(UTC)
haddison

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/6/2010(UTC)
Posts: 113
Location: London

Use the Forum dll for this (I think it's called Forum.HHV).
jjstein  
#4 Posted : Saturday, November 3, 2012 10:51:17 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)
You are more likely to get some help, if you completely define your BUY & SELL conditions, along with any code you've already written.
a26174980  
#5 Posted : Saturday, November 3, 2012 9:30:39 PM(UTC)
a26174980

Rank: Member

Groups: Registered, Registered Users
Joined: 11/2/2012(UTC)
Posts: 15

the buy signal: cross( MACD(), Mov(MACD(),9,E) the sell signal: After the BUY signal starts, if the price ever (1) rises(or is already ) above bollinger's top band, stop loss is triggered when the (2)price crosses the bollinger's middle band. if the price has not reached bollinger's top band ( (1) not satisfied), but the price rises(or is already ) above bollinger's middle band. stop loss is triggered when the price crosses the bollinger's bottom band. in conclusion, A)price ever reach above top band, stop loss at mid band if (A) not satisfied, price ever reach above mid band, stop loss at bottom band. thank you so much for your attention!!!
jjstein  
#6 Posted : Saturday, November 3, 2012 10:21:16 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)
You need to be more specific. 1. What does "price" mean, and when? It can be any of OHLC. 2. Is the "cross" above or below? Which price? 3. You seem to use "stop loss" interchangeably with "sell signal"...usually, a "stop loss" is a "trailing stop", a set value which can rise, but never lower. Is that what you mean? 4. If so, what is the initial value of the stop at the time of the buy signal? 5. What should trigger the stop -- Low or Close?
jjstein  
#7 Posted : Saturday, November 3, 2012 11:10: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)
After making a few assumptions, here is some code:
Code:
{_Test}{ INPUT }Periods:=input("Periods: ",5,50,20);
{ CALC }Bmid:=mov(C,Periods,S);Btop:=Bmid+(2*stdev(C,Periods));Bbot:=Bmid-(2*stdev(C,Periods));
{ BUY }Entry:=cross(MACD(),Mov(MACD(),9,E)); { MACD }
TrailingStop:=if(HIGH>Btop,Bmid,Bbot);
{ LATCH - Store value of stop }Latch:=If(PREV=0, { no trade }If(Entry,Bbot,0), { Initial Stop }If(LOW<PREV,0, { stop hit }Max(PREV,TrailingStop) { raise stop }));
{ REMOVE REDUNDANCY }Entry:=Alert(Latch=0,2)*(Latch>0) or cum(Latch>0)=1;Exit:=Alert(Latch,2)*(Latch=0);Signal:=Entry-Exit;Season:=If(Latch>0,1,-1);
{ PLOT - Advance visually. Style-DOT Weight-3}ValueWhen(1,Ref(Latch,-1)>0,Ref(Latch,-1));
A simple visual:UserPostedImage Some test results:UserPostedImage
a26174980  
#8 Posted : Saturday, November 3, 2012 11:14:19 PM(UTC)
a26174980

Rank: Member

Groups: Registered, Registered Users
Joined: 11/2/2012(UTC)
Posts: 15

oh,sorry. 1. the price is closed price 2. closed price cross the bands from above to below 3. it is a trailing stop using bollinger bands as the trailing value 4. the initial value of the stop depends on the closed price when the buy signal starts. if the closed price is above bollinger top,the initial value of the stop is bollinger middle. if the closed price is below bollinger top but above bollinger middle,the initial value of the stop is bollinger bottom. 5. the closed should trigger the stop
jjstein  
#9 Posted : Saturday, November 3, 2012 11:35:51 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)
a26174980 wrote:
if the closed price is above bollinger top,the initial value of the stop is bollinger middle. if the closed price is below bollinger top but above bollinger middle,the initial value of the stop is bollinger bottom.
And if the CLOSE is at or less than the bollinger middle?
a26174980  
#10 Posted : Saturday, November 3, 2012 11:53:20 PM(UTC)
a26174980

Rank: Member

Groups: Registered, Registered Users
Joined: 11/2/2012(UTC)
Posts: 15

the stop loss is still bollinger bottom
jjstein  
#11 Posted : Sunday, November 4, 2012 1:54: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)
This should do it, then:
Code:
{_Test}{ INPUT }Periods:=input("Periods: ",5,50,20);
{ CALC }Bmid:=mov(C,Periods,S);Btop:=Bmid+(2*stdev(C,Periods));Bbot:=Bmid-(2*stdev(C,Periods));
{ BUY }Entry:=cross(MACD(),Mov(MACD(),9,E)); { MACD }
TrailingStop:=if(CLOSE>Btop,Bmid,Bbot);
{ LATCH - Store value of stop }Latch:=If(PREV=0, { no trade }If(Entry,TrailingStop,0), { Initial Stop = Trailing Stop }If(CLOSE<PREV,0, { stop hit }Max(PREV,TrailingStop) { raise stop }));
{ REMOVE REDUNDANCY }Entry:=Alert(Latch=0,2)*(Latch>0) or cum(Latch>0)=1;Exit:=Alert(Latch,2)*(Latch=0);Signal:=Entry-Exit;Season:=If(Latch>0,1,-1);
{ PLOT - Advance visually. Style-DOT Weight-3}ValueWhen(1,Ref(Latch,-1)>0,Ref(Latch,-1));
Basic visual:UserPostedImage Results:UserPostedImage
a26174980  
#12 Posted : Sunday, November 4, 2012 2:49:51 AM(UTC)
a26174980

Rank: Member

Groups: Registered, Registered Users
Joined: 11/2/2012(UTC)
Posts: 15

THANK YOU SO MUCH!! I cant search the function of CLOSEMAX on the internet. what is CLOSEMAX ? sorry , i am a beginner to metastock
jjstein  
#13 Posted : Sunday, November 4, 2012 11:29:32 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)
It appears there is an error in the Forum Software again <sigh>. Send me your email in a PM (Private Message) and I will email the code.
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.