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

Notification

Icon
Error

Options
Go to last post Go to first unread
Flexi  
#1 Posted : Wednesday, February 2, 2011 10:56:45 AM(UTC)
Flexi

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2006(UTC)
Posts: 135

Below is the profit curve code from jose

Try implementing a specific of bars exit on the code but the the plot didn't exit on the specific number of bars exit. Anyone know whats wrong with the code?
The one in bold are altered code

{* Entry Long formula/reference *}
{ SMA crossover entry - do not trade! }
entry:=Cross(Mov(C,5,S),Mov(C,10,S));

{* Exit Long formula/reference *}
{ Reverse SMA crossover exit }
exit:=(Cross(C,Mov(C,10,S) AND Alert(entry,1)=0) Or (Barssince(entry)=16 and Alert(entry,1)=0);

{ User inputs }
plot:=Input("[1]%Profit curve, [2]MaxDD%, [3]Trade signals",1,3,1);
cost:=Input("Total Transaction costs (Brokerage + Slippage) %:",0,100,.2)/200;

{ Trade Binary & clean Entry/Exit signals }
init:=Cum(IsDefined(entry+exit))=1;
flag:=ValueWhen(1,entry-exit<>0 OR init,entry);
entry:=flag*(Alert(flag=0,2)
OR entry*Cum(entry)=1);
exit:=(flag=0)*(Alert(flag,2)
OR exit*Cum(exit)=1);

{ Profit Long % curve }
EntryVal:=ValueWhen(1,entry,C*(1+cost));
Profit:=C*(1-cost)/EntryVal-1;
ProfitPer:=(flag*Profit+Cum(exit*Profit))*100;

{ Profit Long % max drawdown }
MaxDD:=
Highest(Max(Highest(ProfitPer),0)-ProfitPer);

{ Plot in own window below chart }
If(plot=1,ProfitPer,If(plot=2,MaxDD,entry-exit))
mstt  
#2 Posted : Wednesday, February 2, 2011 12:56:09 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Flexi The major problem lies with your application of the Alert() function. A 1-period Alert is the same as no alert at all. The last bar that the original signal (entry in this case) plots TRUE is regarded as the first bar of an Alert. To extend the original signal for additional bars you must use a minimum of 2 for the Alert() Periods parameter. It's not clear to me what purpose either Alert() has in this context. For example, BarsSince(entry)=16 can only be TRUE for 1 bar so there's no need to truncate it to achieve that effect. When I use "AND Alert(signal=0,2)" as part of an entry or exit signal it's usually to limit the entry signal to being TRUE for just one bar instead of a series of bars. "AND Alert(signal=0,2)" is essentially the same as "AND Ref(Signal,-1)=FALSE". My reason for using Alert() rather an Ref() for truncating signals is that Alert() does not introduce an additional N/A bar to the final result of a formula. The successive use of several Ref() functions introduces at least a corresponding number of additional N/A bars. To most MS users this is of no consequence but it can affect the accuracy or completeness of what you're trying to calculate or display. Roy
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.