MetaStock™ Zone Forum & FAQ Artykuły Linki Elliott Waves EasyLanguage™ Zone

 A B C D E F G H I J K L M N O P R S T U V W Y Z #

Up/Down Bar Count by Jose Silva

Need a bit of yoooou guys expertise in coding. Are there any simple ways of saying three
consecutive higher closes instead of C>Ref(C,-1) AND Ref(C,-1)> Ref(C,-2) AND Ref(C,-2) > Ref(C,-3)

Thanking you kindly

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Try this:

---8<-----------------------------
consecPds:=3;
Sum(C>Ref(C,-1),consecPds)=consecPds
---8<-----------------------------

jose '-)
http://www.metastocktools.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Oops, I means LLV for higher closes. Use HHV(C - ref(C,-1), 2) < 0 for lower closes.

Dave

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Dave is thinking outside the box with his solution:

---8<-----------------
pds:=3;
LLV(C-Ref(C,-1),pds)>0
---8<-----------------

This may be easier to follow for those of us still inside the box:

---8<-----------------
pds:=3;
Sum(C>Ref(C,-1),pds)=pds
---8<-----------------

jose '-)
http://www.metastocktools.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Hi Jose,

can't really take credit for the idea, just something I picked up.

Following on, how would I calculate the number of consecutive Up days (& conversely down downs) as an indicator. I have tried using some latch logic but just not getting it right.

Regards, David

---------------------

David, try something like this indicator:

========================
Consecutive Up/Down Days
========================
---8<----------------------------

{ Consecutive Up/Down Closes - v1.0

For personal use only.
http://www.metastocktools.com

Note: simultaneous Up/Down signals cancel
each other.}

{ Indicator/User inputs }
pds1:=Input("Consecutive Up bars",1,21,3);
pds2:=Input("Consecutive Down bars",1,21,2);
reverse:=Input("Reverse signals? [1]Yes, [0]No",0,1,0);
plot:=Input("Signals: [1]Clean, [2]All, [3]Trade binary",1,3,1);
delay:=Input("Entry and Exit delay",0,5,0);

{ Consecutive Up/Down signals }
entry1:=LLV(C-Ref(C,-1),pds1)>0;
exit1:=HHV(C-Ref(C,-1),pds2)<0;

{ Reverse signals? }
entry:=If(reverse,exit1,entry1);
exit:=If(reverse,entry1,exit1);

{ Clean signals }
init:=Cum(IsDefined(entry+exit))=1;
bin:=ValueWhen(1,entry-exit<>0 OR init,entry);
OR entry*Cum(entry)=1);
OR exit*Cum(exit)=1);
signals:=long-short;

{ Plot in own window }
0;
Ref(If(plot=2,entry,0),-delay);
Ref(If(plot=1,signals,
If(plot=2,-exit,bin)),-delay)

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

jose '-)
http://www.metastocktools.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Thanks Jose, I got that to work & is good for triggers. I think what I was after though was an indicator actually giving the count of consecutive days up. ie the indicator actually reports the number of days going up , then resets to zero when the consecutive days stop. I was thinking then of using it as part of the system logic ie 'daysup > 3'

Regards, David

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

David, try this indicator:

Up/Down Bar Count

{ Up/Down bar count - v1.0
http://www.metastocktools.com }

{ User input }
plot:=Input("plot: [1]up/down Signals, [2]up/down Bar Count",1,2,2);

{ Up/Down signals }
up:=C>Ref(C,-1);
down:=C<Ref(C,-1);

{ Up/Down bar count }

{ Plot in own window }
0;If(plot=1,up-down,upCount-downCount)

jose '-)
http://www.metastocktools.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Jose, thanks, that hit the spot. I split them into 2 separate indicators to do what I wanted (attached below). Your examples are really helpful thanks to understand different ways to code.

Cheers, Dave

-------------------------------
Bars Down Forumula
-------------------------------
{ Down signal }
Dwn := C < Ref(C,-1);
firstDwn:= Dwn AND Alert(Dwn < 1, 2);

{ Down bar count }
DwnCount;
-------------------------------

-------------------------------
Bars Up Forumula
-------------------------------
{ Up signal }
up:=C>Ref(C,-1);

{ Up bar count }
upCount;
-------------------------------

Source / From: TOP
equismetastock[at]yahoogroups[dot]com

Equis and MetaStock® and MetaStock Professional® are registered trademarks of Equis International. Achelis Binary Wave®, The DownLoader®,
Expert Advisor®, OptionScope®, Quotecenter® and Smart Charts® are trademarks of Equis International, a Thomson Reuters company.

TradeStation® Pro, TradeStation® 2000i, OptionStation®, SuperCharts®, PowerEditor® and EasyLanguage®
are registered trademarks of TradeStation Technologies, Inc. Other names and marks referred to are the property of their respective owners.

All information provided on this website is for educational purposes only. Trading involves risk, including possible loss of principal and other losses.

Ten i inne materiały na tej stronie zostały zamieszczone zostały jedynie w celach edukacyjnych, nie ponoszę żadnej odpowiedzialno¶ci za ich stosowanie.

Gra na giełdzie i rynkach walutowych (FOREX) niesie ze sob± ryzyko poważnych strat finansowych!