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

Notification

Icon
Error

Options
Go to last post Go to first unread
beggou  
#1 Posted : Saturday, August 25, 2012 4:00:26 PM(UTC)
beggou

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/25/2012(UTC)
Posts: 8

Hy I 'm new on the forum and need same help from experts. This is the code in Prorealtime Platform for Mogalef Bands code, I tried to convert it into Metastock but failed with how to use 'If + 2 expressions' and prev :-) . Thanks for sharing
CP=(open+high+low+2*close)/5 F=LinearRegression[3](CP) E=std[7](F) if barindex 'not >' 8 then Mediane = undefined BandeHaute = undefined BandeBasse = undefined Else BandeHaute = F+(E*2) BandeBasse = F-(E*2) if F<BandeHaute[1] and F>BandeBasse[1] then BandeHaute=BandeHaute[1] BandeBasse=BandeBasse[1] endif Mediane =(BandeHaute+BandeBasse)/2 Endif Return BandeHaute , Mediane , BandeBasse
Thanks a lot again
henry1224  
#2 Posted : Sunday, August 26, 2012 5:39:07 PM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
Code:


LRPds:=Input("LinRegperiods",3,100,10);
STPds:=Input("STDperiods",3,100,30);
AP:=(H+L+O+2*C)/5;
LR:=LinearReg(AP,LRPds);
LRstd:=Stdev(LR,STPds);
UBand:=LR+(2*Lrstd);
LBand:=LR-(2*Lrstd);
MBand:=(Uband+LBand)/2;
UBand;MBand;LBand;


beggou  
#3 Posted : Monday, August 27, 2012 9:42:25 AM(UTC)
beggou

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/25/2012(UTC)
Posts: 8

Thanks for your replay but what i need is something different like this. the bands stay static and parallel (kind of horizontal channel) and change only if the linear regression is outside the bands. http://www.mogalef.com/i...p=1_10_The-Mogalef-Bands I've tried to convert the prorealtime code into metastock and did that; but i know it is not the exact conversion; problems with prev :-)
cp:=(O+H+L+(2*C))/5; F:=LinearReg(cp,3); Et:=Stdev(F,7); bh:=F+(2*Et); bb:=F-(2*Et); t1:=If(Cum(1)<8,bh,If(f<prev,If(f<ref(bb,-1),bh,PREV),bh)); t2:=If(Cum(1)<16,bb,If(t1Ref(t1,-1),t1-2*(t1-f),If(f>PREV,PREV,bb))); t1:=If(t2Ref(t2,-1),t2+2*(f-t2),If(f>PREV,bh,PREV)); t2:=If(Cum(1)<16,bb,If(t1Ref(t1,-1),t1-2*(t1-f),If(f>PREV,PREV,bb))); t2;t1; (t1+t2)/2;
please need your help tx
wabbit  
#4 Posted : Monday, August 27, 2012 6:01:19 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)
The simplest solution is to code this outside the limited MS formula language i.e. use the MDK to write an external function, as you want two lines to change their values based on whether a trigger occurs at either of those two lines, which if it can be done, will require a bucket-load of slow PREV functions or simply cannot be done because there will be some sort of circular reference.

MS formulas are fully evaluated line by line, do a search of the forum to find precisely what that means, if you're interested.


wabbit [:D]

jjstein  
#5 Posted : Monday, August 27, 2012 7:57: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)
It's not clear -- from either your partial code OR the graph -- just what you are trying to do.

Perhaps you could try to explain it FULLY in words, first.

Also, you MUST use the CODE tags if you want to post any code, otherwise you never know when the forum software has garbled something.

beggou  
#6 Posted : Tuesday, August 28, 2012 6:58:43 PM(UTC)
beggou

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/25/2012(UTC)
Posts: 8

hi, what i'm looking for is how to draw two horizontal and parallel lines centred on the weighted regression line of (O+H+L+2*C)/5 and separated from it by 2*standard deviation to catch the volatility. The bands will redraw each time the regression line of is out of the bands following the trend and stay the same if the regline is inside the bands. i have tried to program that with the code bellow but it's not perfect. As said by wabbit, it can be done by MDK writing an external function, but i don't know how to do it :-( . tx again for helping me
Code:


F:=LinearReg((O+H+L+2*C)/5,3);
Et:=Stdev(F,7);

bh:=F+(2*Et);
bb:=F-(2*Et);

t1:=If(Cum(1) less than 8,bh,If(fless than PREV,If(f less than Ref(bb,-1),bh,PREV),bh));

t2:=If(Cum(1)less than 16,bb,If(t1 different than Ref(t1,-1),t1-2*(t1-f),If(f greather than PREV,PREV,bb)));
t1:=If(t2 different than Ref(t2,-1),t2+2*(f-t2),If(f greather than PREV,bh,PREV));
t2:=If(Cum(1) less than 16,bb,If(t1 different than Ref(t1,-1),t1-2*(t1-f),If(f greather than PREV,PREV,bb)));

t2;t1;(t1+t2)/2;

The initial and real code from Prorealtime for Mogalef Bands is the following:
Code:

CP=(open+high+low+2*close)/5
F=LinearRegression[3](CP)
E=std[7](F)
if barindex less than 8 then
 Mediane = undefined
 BandeHaute = undefined
 BandeBasse = undefined
Else
 BandeHaute = F+(E*2)
 BandeBasse = F-(E*2)
 if F less than BandeHaute[1] and F greather than BandeBasse[1] then
	BandeHaute=BandeHaute[1]
	BandeBasse=BandeBasse[1]
 endif
 Mediane =(BandeHaute+BandeBasse)/2
Endif
Return BandeHaute , Mediane , BandeBasse 

problems with greather and less than signs !!!
jjstein  
#7 Posted : Tuesday, August 28, 2012 11:38: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)
I think this will do it -- but I don't quite understand how you will get BUY & SELL signals out of it.
Code:

_Mogalef
{ VARS }
Pd1:=Input("LinRegperiods",3,100,3);
Pd2:=Input("STDperiods",3,100,7);

{ CALC }
AP:=(H+L+O+2*C)/5;
LR:=LinearReg(AP,Pd1);
SD:=Stdev(LR,Pd2);

{ LATCH }
x:=if(PREV=0, { initial or reset }
LR, { store }
if(LR>(PREV+2*ValueWhen(1,PREV=0,Stdev(LR,Pd2))) { over }
or LR<(PREV-2*ValueWhen(1,PREV=0,Stdev(LR,Pd2))), { under }
0, { reset }
PREV)); { keep }

{ BANDS }
Middle:=ValueWhen(1,ref(x,-1)=0,x); { LR }
SD:=ValueWhen(1,ref(x,-1)=0,Stdev(LR,Pd2)); { Stdev }
Top:=Middle+2*SD; { Top }
Bottom:=Middle-2*SD; { Bottom }

{ PLOT }
Top; { Green }
Bottom; { Red }
Middle; { Blue }
LR; { White }


UserPostedImage

jjstein  
#8 Posted : Wednesday, August 29, 2012 10:46:12 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)
UPDATE: Cleaned up the code & added some comments; graph uses the DOTTED style instead of LINE.
Code:

{ USER }
Pd1:=Input("Regression Periods",3,100,3);
Pd2:=Input("Standard Deviation Periods",3,100,7);
Pd3:=Input("Standard Deviations",1,5,2);

{ DEFINE }
AP:=(H+L+O+2*C)/5; { Price }
LR:=LinearReg(AP,Pd1); { Moving Regression line }
SD:=Stdev(LR,Pd2); { Standard Deviation }

{ LATCH }
x:=If(PREV=0, { initial or reset }
LR, { store }
If(LR>PREV+Pd3*ValueWhen(1,PREV=0,SD) { over }
OR LR<PREV-Pd3*ValueWhen(1,PREV=0,SD), { under }
0, { reset }
PREV)); { keep }

{ BANDS }
Middle:=ValueWhen(1,Ref(x,-1)=0,x); { Get LR value from point in time }
SD:=ValueWhen(1,Ref(x,-1)=0,SD); { Get SD value from point in time }

{ PLOT }
Middle+Pd3*SD; { Top - Green }
Middle-Pd3*SD; { Bottom - Red }
Middle; { Blue }
LR; { White }

UserPostedImage

beggou  
#9 Posted : Wednesday, August 29, 2012 12:13:25 PM(UTC)
beggou

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/25/2012(UTC)
Posts: 8

Thank you very much jjstein; you are a boss +++ About how to trade the Mogalef band, look at that http://www.whselfinvest....ies_26_Mogalef_Bands.php tx again
jjstein  
#10 Posted : Wednesday, August 29, 2012 2:39:42 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 looked, and something seems to be missing -- the "trend filter":

Quote:
The 30-minute chart supplies the trend filter. The trend filter is center line in the 30-minute chart calculated 80 periods back.

Quote:
The trend filter blocks short sell signals in a bullish market and buy signals in a bearish market.


Any idea how this is calculated?

beggou  
#11 Posted : Friday, August 31, 2012 11:46:04 AM(UTC)
beggou

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/25/2012(UTC)
Posts: 8

sorry, I don't know how they get the trend. I don't use the filter trend in my trading; instead i use de ret90, MME150 lines for the trend, and the STPMT for timing & repulse indicators for divergences to buy/sell. It 's a "Eric Lefort" methode.
Code:

-REPULSE1
lo :=LLV(LOW,1);
hi:=HHV(HIGH,1);
a:=(3*CLOSE-2*lo-Ref(OPEN,0))/CLOSE*100;
b:=(Ref(OPEN,0)+2*hi-3*CLOSE)/CLOSE*100;
Mov(a-b,5,E);

Code:

_REPULSE5
lo :=LLV(LOW,5);
hi:=HHV(HIGH,5);

a:=(3*CLOSE-2*lo-Ref(OPEN,-4))/CLOSE*100;
b:=(Ref(OPEN,-4)+2*hi-3*CLOSE)/CLOSE*100;
Mov(a-b,25,E);
Code:

_REPULSE10
lo :=LLV(LOW,10);
hi:=HHV(HIGH,10);
a:=(3*CLOSE-2*lo-Ref(OPEN,-9))/CLOSE*100;
b:=(Ref(OPEN,-9)+2*hi-3*CLOSE)/CLOSE*100;
Mov(a-b,10*5,E)
Code:

_STPMT
st1 := Stoch( 5,3);
st2 := Stoch(14,3);
st3 := Stoch(45,15);
st4 := Stoch(75,20);

stpmt := ( 4.1*st1 + 2.5*st2 + st3 + 4*st4 ) /11.6;
MM9STPM := Mov(stpmt , 9, S);

stpmt;MM9STPM;st1;st2;st3;st4
Code:

_RET90
Ret:= (LLV(LOW, 90) +HHV(HIGH, 90))/2;
Ret
beggou  
#12 Posted : Sunday, September 2, 2012 11:18:07 AM(UTC)
beggou

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/25/2012(UTC)
Posts: 8

@jjstein hello! Sorry to come back to you again, but i have noticed that the bands move with one bar chart late when the moving regression line is up or down the Mogalef bands. So the plot show the standard deviation (n-1) and the bands move one bart chart late. If you can help to correct that, it will be great. I've tried to do it, but :-(, it's too complicated for me :-). Thanks again for your help.
jjstein  
#13 Posted : Thursday, September 13, 2012 1:36:13 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)
Um, that may be an "illusion", due to the LINE Style of the LR plot. Have a look at it using DOTTED Style: UserPostedImage P.S. Sorry to be so late getting back to you -- had some odd problems with the desktop, had to replace all of main memory!
beggou  
#14 Posted : Thursday, September 13, 2012 1:30:55 PM(UTC)
beggou

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/25/2012(UTC)
Posts: 8

Hello boss :-) It is not an illusion. I don't wear glasses, nor drunk :-) . The bands move indeed one bar later. Your help will be nice tx
jjstein  
#15 Posted : Thursday, September 20, 2012 11:19:31 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)
Try the following:
Code:
{ NOTE: This will not catch a "violation" until after the 2nd data point }{ USER }Pd1:=Input("Regression Periods",3,100,3);Pd2:=Input("Standard Deviation Periods",3,100,7);Pd3:=Input("Standard Deviations",1,5,2);
{ DEFINE }AP:=(H+L+O+2*C)/5; { Price }LR:=LinearReg(AP,Pd1); { Moving Regression line }SD:=Stdev(LR,Pd2); { Standard Deviation }
{ LATCH }x:=If(PREV=0, { initial or reset }ref(LR,-1), { store }If(LR>PREV+Pd3*ValueWhen(1,PREV=0,ref(SD,-1)) { over }OR LR<PREV-Pd3*ValueWhen(1,PREV=0,ref(SD,-1)), { under }0, { reset }PREV)); { keep }
{ BANDS }PiT:=Ref(x,0)=0; { Point in Time }Middle:=ValueWhen(1,PiT,LR); { Get LR value @ PiT }SD:=ValueWhen(1,PiT,SD); { Get SD value @ PiT }
{ PLOT }Middle+Pd3*SD; { Top - Green }Middle-Pd3*SD; { Bottom - Red }Middle; { Blue }LR; { White }
beggou  
#16 Posted : Sunday, September 23, 2012 8:08:14 AM(UTC)
beggou

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/25/2012(UTC)
Posts: 8

it's perfect now :-) Thank you very much for your help.
jjstein  
#17 Posted : Sunday, September 23, 2012 8:52:37 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)
Just noticed that the forum software doesn't display the code under LATCH correctly. It's right when I EDIT the post, but the forum display isn't right. If you didn't have replies emailed to you, send a private msg with your email, and I'll send it along.
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.