[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Metastockusers] Re: expression must contain only constant data



PureBytes Links

Trading Reference Links

Try this code as an example:

=====================
Divergences - Class A
=====================
---8<---------------------------

{ Class A price/indicator divergence v3 }
{ +1 signal = bullish trough divergences }
{ -1 signal = bearish peak divergences }
{ ©Copyright 2003 Jose Silva }
{ http://users.bigpond.com/prominex/pegasus.htm }

ind:=Input("MACD=1,  RSI=2,  DMI=3,  Mom=4",
 1,4,1);
pds:=Input("indicator periods",2,2520,10);
f:=Input("price field: Close=1, High/Low=2",
 1,2,1);
Ch:=Input("peak/trough depth minimum (0-100%)",
 0,100,0)/100;
shift:=Input("shift signals back to match divergences=1",0,1,0);

{y:=insert any indicator or Fml("formula name")}
y:=If(ind=1,MACD(),If(ind=2,RSI(C,pds),
 If(ind=3,DMI(C),Mo(C,pds))));

xu:=If(f=1,C,H);
xd:=If(f=1,C,L);
Pkx:=xu<Ref(xu,-1) AND Ref(xu,-1)>Ref(xu,-2)
 AND Ref(xu,-1)>=(xu+Ref(xu,-2))/2*(1+Ch);
Pkx1:=ValueWhen(1,Pkx,Ref(xu,-1));
Pkx2:=ValueWhen(2,Pkx,Ref(xu,-1));
Trx:=xd>Ref(xd,-1) AND Ref(xd,-1)<Ref(xd,-2)
 AND Ref(xd,-1)<=(xd+Ref(xd,-2))/2*(1-Ch);
Trx1:=ValueWhen(1,Trx,Ref(xd,-1));
Trx2:=ValueWhen(2,Trx,Ref(xd,-1));

Pky:=y<Ref(y,-1) AND Ref(y,-1)>Ref(y,-2)
 AND Ref(y,-1)>=(y+Ref(y,-2))/2*(1+Ch);
Pky1:=ValueWhen(1,Pky,Ref(y,-1));
Pky2:=ValueWhen(2,Pky,Ref(y,-1));
Try:=y>Ref(y,-1) AND Ref(y,-1)<Ref(y,-2)
 AND Ref(y,-1)<=(y+Ref(y,-2))/2*(1-Ch);
Try1:=ValueWhen(1,Try,Ref(y,-1));
Try2:=ValueWhen(2,Try,Ref(y,-1));

0;
Ref(Trx AND Try AND Trx1<Trx2
 AND Try1>Try2,shift)
+Ref((Pkx AND Pky AND Pkx1>Pkx2
 AND Pky1<Pky2)*-1,shift)

---8<---------------------------

jose '-)



--- In Metastockusers@xxxxxxxxxxxxxxx, chrismontgomery1966@xxxx wrote:
> "This variable or expression must contain only constant data."
> =============
> peak1:= Peak(1,Fml("MACD Histogram"),5);
> peak2 := Peak(2,Fml("MACD Histogram"),5);
> peakbars1:=PeakBars(1,Fml("MACD Histogram"), 5);
> peakbars2:=PeakBars(2,Fml("MACD Histogram"), 5);
> 
> Ref(H,- peakbars1 ) > Ref(H,-peakbars2) 
> AND peak2 > peak1
> ===============
> I am trying to determine if there is a bearish divergence
> between Price and an indicator. 
> 
> Interpretes as follows: There are two peaks in the Histogram
> the latest one is lower that the second ( prior ) one. While the
> highest high price is higher than the prior one.
> 
> This is where the error occurs.
> Ref(H,- peakbars1 ) wants a constant.
> 
> Any way around this limitation?
> 
> Also is it incorrect to try to use Peak and Trough functions as they 
> rely on the zigzag function?
> 
> Many thanks,
> Chris
> 7.2EOD and 9EOD
> 
> {MACD Histogram}
> EMA12 := Mov( C,12,E ) ;
> EMA26 := Mov( C,26,E ) ;
> FastMACD := ( EMA12 - EMA26 ) ;
> SlowMACD := Mov( FastMACD , 9,E );
> FastMACD - SlowMACD ;



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com.  Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/zMEolB/TM
---------------------------------------------------------------------~->

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/Metastockusers/

<*> To unsubscribe from this group, send an email to:
     Metastockusers-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/