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

Notification

Icon
Error

Options
Go to last post Go to first unread
Michael  
#1 Posted : Friday, March 23, 2007 8:17:59 AM(UTC)
Michael

Rank: Newbie

Groups: Registered, Registered Users
Joined: 3/23/2007(UTC)
Posts: 2
Location: Nizhny Novgorod, Russia

Hello everyone,

I’m trying to figure out how to make an indicator that keeps its own first nonzero value. Let’s view this indicator (as an example)

Mod(CLOSE*1000,3)

During a bar period it can return 0, 1 or 2. Let it takes on values 0, 0, 1, 2, 0 (in order). I want to get 1 since it is first nonzero value in series for a given bar. How I can do it?

*PP  
#2 Posted : Friday, March 23, 2007 11:38:14 AM(UTC)
*PP

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/1/2006(UTC)
Posts: 135
Location: Romania

i am not sure that i understod what u want but if i understod corectly then here it is:

a:=Mod(C*1000,3);
If(Ref(If( BarsSince(a=1)<BarsSince( a=0),1,0),-1)=0 AND If( BarsSince(a=1)<BarsSince( a=0),1,0)=1,1,0)

*PP  
#3 Posted : Friday, March 23, 2007 11:44:02 AM(UTC)
*PP

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/1/2006(UTC)
Posts: 135
Location: Romania

i forgot to mention that the formula above will plot only the first 1 after a zero period. 0,0,1,2,1,0,2,1,1 will return 0,0,1,0,0,0,0,1,0
Michael  
#4 Posted : Friday, March 23, 2007 12:57:41 PM(UTC)
Michael

Rank: Newbie

Groups: Registered, Registered Users
Joined: 3/23/2007(UTC)
Posts: 2
Location: Nizhny Novgorod, Russia

Actually I’ve asked about another thing. I receive real time data, and every time when the price is updated the indicator is updated too. Let periodicity of chart is 5 minute and now 10:00 AM. New bar is started to draw. In 10:01 new piece of data comes and indicator is re-counting again. Its first value for a new bar becomes 0. In a minute its value updated again and become 1 and so on. Thus we have the following changes of indicator (for example):

***period starts 10:01***

10:01 value 0

10:02 value 1

10:03 value 2

10:04 value 1

10:05 value 0

***period ends

At the end of 5 minute period we have a 0 value, but I want to get 1 as it is first nonzero value within period. Is it possible to implement?

crash59  
#5 Posted : Friday, March 23, 2007 1:34:09 PM(UTC)
crash59

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/19/2006(UTC)
Posts: 3

The PREV function cannot be used as it requires 2 bars minimum.

This is one approach to your problem.


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

a0:=Mod(C*1000,3) ;
a1:=ValueWhen(1,Cum(1)=1,a0);
a2:=ValueWhen(1,Cum(1)=2,a0);
a3:=ValueWhen(1,Cum(1)=3,a0);
a4:=ValueWhen(1,Cum(1)=4,a0);
a5:=ValueWhen(1,Cum(1)=5,a0);
a6:=ValueWhen(1,Cum(1)=6,a0);
a7:=ValueWhen(1,Cum(1)=7,a0);
a8:=ValueWhen(1,Cum(1)=8,a0);
a9:=ValueWhen(1,Cum(1)=9,a0);
a10:=
If(a1>0,a1,
If(a2>0,a2,
If(a3>0,a3,
If(a4>0,a4,
If(a5>0,a5,
If(a6>0,a6,
If(a7>0,a7,
If(a8>0,a8,
If(a9>0,a9,0)))))))));
a0;a10;

---------------------------------------------------------------------
*PP  
#6 Posted : Saturday, March 24, 2007 1:14:19 AM(UTC)
*PP

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/1/2006(UTC)
Posts: 135
Location: Romania

Michael,

if u don`t say exactly what u want i can`t help - i don`t even have real time data because i use only EOD. If there is something linked with the minute in wich is happening u should try to combine the minute() function. For example if(frac(minute()/5)=0,1,mod(minute(),5)) the result will be 1 when the minute is 5 or any multiple of 5 and 1,2,3,4 the rest of time.

uasish  
#7 Posted : Saturday, March 24, 2007 11:21:38 AM(UTC)
uasish

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/13/2005(UTC)
Posts: 170

Thanks: 7 times

*pp,

Thks,now the 2nd/3rd retracement of price/indicator can be coded ,i tried a crude repeated valuewhen method.

Asish

wabbit  
#8 Posted : Monday, March 26, 2007 10:25:02 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)
Michael,

Try this as a solution to your problem. I haven't tested it because it's late and I am tired but cannot sleep, so let me know if it works, and if it doesn't work, let me know what happens!

Code:

data:={whatever indicator};

start:=mod(minute(),5)=0;
start:=start and alert(start=0,2);

count:=data<>0;
count:=cum(count);

tr:=(count-valuewhen(1,start,count))=1;
tr:=tr and alert(tr=0,2);

i:=cum(isdefined(tr+start))=1;
myValue:=(barssince(tr or i)<barssince(start or i))*valuewhen(1,tr,data);

{plot}
myValue;


Astute Forum members will recognize the similarities in code between this thread and another recent thread, showing the usefulness of this coding technique.


Hope this helps.

wabbit [:D]




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.