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

Notification

Icon
Error

Options
Go to last post Go to first unread
supremeinfo  
#1 Posted : Monday, August 20, 2012 8:34:28 AM(UTC)
supremeinfo

Rank: Member

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

Code:


Condition:=Cross(Mov(C,2,E),Mov(C,36,S));
CloseAtCrossover:=ValueWhen(1,Condition,C);
Value:=(C-CloseAtCrossover)/CloseAtCrossover;
Buy:=Value>0.03;
Buy

with refrence to the above code which is enough to test my strategy (buy when price rises by 3 % from crossover value of 2 ema & 36 sma) the only problem is it gives a buy signal before the next crossover or immediately after the exit of the previous trade. For the above given code for buy order my sell will be
Code:

cross(mov(c,36,s),c) 

sell short order will be
Code:


Condition:=Cross(Mov(C,36,s),Mov(C,2,e));
CloseAtCrossover:=ValueWhen(1,Condition,C);
Value:=(CloseAtCrossover-c) / C;


sell:=Value>0.03;

sell

buy to cover order

cross(c,mov(c,36,s) 

plz assist me in writing the correct code... warm regards supreme
wabbit  
#2 Posted : Monday, August 20, 2012 7:17:39 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)
I'd be using a counter and reset:

Code:

MA1:=Mov(C,2,E);
MA2:=Mov(C,36,S);

condition:=Cross(MA1,MA2);

count:=Cum(C>(1.03*ValueWhen(1,condition,C)));
reset:=condition;

counter:=count - ValueWhen(1,reset,count);
buy:=counter=1 AND Alert(counter<>1,2);

{plot}
buy;



wabbit [:D]

supremeinfo  
#3 Posted : Tuesday, August 21, 2012 8:51:33 AM(UTC)
supremeinfo

Rank: Member

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

Hi Wabbit ! Thx for your valuable time & effort to help me formulate the correct code.....i can successfully backtest my strategy... moreever came to know the the exact syntax for using "valuewhen" .....however still bit confused about "cum" function & reset latch Warm regards supreme
wabbit  
#4 Posted : Tuesday, August 21, 2012 8:34:10 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)
Cum() just counts the condition for every bar on the chart, "reset" combined with ValueWhen() just resets the counter to zero.


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.