have a look at code below Anthony. I guess it could
be programmed using arrays only, not sure,
regards, Ed
function
cccc(Buy,Sell) {
CumCst = Null;
for (i = 1; i < BarCount; i++) {
if(Buy[i]) {
CumCst[i]=0.10;
for (j = i +
1; j < BarCount; j++) {
if (Sell[ j ] )
{
i =
j - 1;
break;
}
else if(C[j] > C[j-1])
{
CumCst[j]
= Min(CumCst[j-1]
+ 0.003,0.13);
}
else if(C[j] <=
C[j-1]) {
CumCst[j]
= CumCst[j-1];
}
else if (j == BarCount -
1)
{
i =
BarCount;
break;
}
}
}
else if(Sell[i]) {
CumCst[i]=0.10;
for (j = i +
1; j < BarCount; j++) {
if (Sell[ j ] )
{
i =
j - 1;
break;
}
else if(C[j] < C[j-1])
{
CumCst[j]
= Min(CumCst[j-1]
+ 0.003,0.13);
}
else if(C[j] >=
C[j-1]) {
CumCst[j]
= CumCst[j-1];
}
else if (j == BarCount -
1)
{
i =
BarCount;
break;
}
}
}
}
return CumCst;
}
Buy=Cross(C,EMA(C,19));
Sell=Cross(EMA(C,19),C) ;
CumCst = cccc(Buy,Sell);
per=19; Smth = 2/(per+1)+CumCst;
MovAvg = AMA(C,Smth);
Plot(movavg,"",colorBlue,1); Plot(C,"",1,64);
PlotShapes(Buy*shapeUpArrow,colorGreen,0,L,-20); PlotShapes(Sell* shapeDownArrow,colorRed,0,H,-20);
Title="cumulative value = "+WriteVal(Cumcst,1.3);
----- Original Message -----
Sent: Saturday, January 23, 2010 1:47
PM
Subject: Re: [amibroker] Help with
formula
Keith,
Have you tried the formula ? I made the
adjustments as you stated still does not work...although
I had them the way you suggested earlier...I have
been trying but something is not working properly.
Description:
When there is a new buy or sell signal the cumCst
will reset to 0.10 and increment by 0.003
until it gets to a maximum of 0.13, this is not
happening with the formula below....I can not
see the error, can anyone ?
Here is the complete formula
Buy=Cross(C,EMA(C,19));
Sell=Cross(EMA(C,19),C)
;
CumCst=0.00;
poslong=0;
posshort=0;
for (i=1; i
< BarCount; i++)
{
if(Buy[i])
{
poslong=1;
posshort=0;
CumCst[i]=0.10;
}
if(Sell[i])
{
poslong=0;
posshort=1;
CumCst[i]=0.10;
}
if(posshort)
{
if(C[i] < C[i-1])
CumCst[i] = CumCst[i-1] + 0.003;
else
CumCst[i] = CumCst[i-1];
}
if(poslong)
{
if(C[i] > C[i-1])
CumCst[i] = CumCst[i-1] + 0.003;
else
CumCst[i] = CumCst[i-1];
}
if(CumCst[i] > 0.13)
CumCst[i] = 0.13;
}
per=19;
Smth=2/(per+1)+CumCst;
MovAvg=AMA(C,Smth);
Plot(movavg,"",colorBlue,1);
Plot(C,"",1,64);
PlotShapes(Buy*shapeUpArrow,colorGreen,0,L,-20);
PlotShapes(Sell*
shapeDownArrow,colorRed,0,H,-20);
Title="cumulative value = "+WriteVal(Cumcst,1.3);
----- Original Message -----
Sent: Saturday, January 23, 2010 1:37
AM
Subject: Re: [amibroker] Help with
formula
Anthony --
I have
added comments to your code below: //
Anthony.afl
Buy=Cross(C,EMA(C,19)); Sell=Cross(EMA(C,19),C)
; CumCst=0.00; poslong=0; posshort=0; for (i=1; i < BarCount;
i++) { if(Buy[i])
{ poslong==1; // == doesn't set
poslong to 1, it stays 0 posshort==0;
// use = to set value
CumCst[i]=0.10; }
if(Sell[i]) {
poslong==0;
posshort==1; // == doesn't set posshort to 1, it stays
0 CumCst[i]=0.10;
// use = to set
value
}
if(posshort) // posshort is 0 and code below is
never executed {
if(C[i] < C[i-1])
CumCst[i] = CumCst[i-1] +
0.003; else
CumCst[i] =
CumCst[i-1]; }
if(poslong)
// poslong is 0 and code below is never executed
{ if(C[i] >
C[i-1])
CumCst[i] = CumCst[i-1] + 0.003;
else CumCst[i] =
CumCst[i-1]; }
Keith,
Thanks...but that does not seem to be the
problem..when there is a signal
buy or sell...cumCST starts at 0.10 and
increments by 0.003 as per the
formula...that is not happening....it
must be something else
Anthony
-----
Original Message -----
Sent:
Friday, January 22, 2010 10:35 PM
Subject:
Re: [amibroker] Help with formula
In four places you used
== where you should have used > Anthony Faragasso
wrote:
Hello,
Could someone look at this please...I can not see the
error...
The cumCST should increment up to .13 but it is not
happening..
Thank you
Anthony
Buy=Cross(C,EMA(C,19));
Sell=Cross(EMA(C,19),C) ;
CumCst=0.00;
poslong=0;
posshort=0;
for (i=1; i
< BarCount;
i++)
{
if(Buy[i])
{
poslong==1;
posshort==0;
CumCst[i]=0.10;
}
if(Sell[i])
{
poslong==0;
posshort==1;
CumCst[i]=0.10;
}
if(posshort)
{
if(C[i]
< C[i-1])
CumCst[i]
= CumCst[i-1] + 0.003;
else
CumCst[i]
= CumCst[i-1];
}
if(poslong)
{
if(C[i]
> C[i-1])
CumCst[i]
= CumCst[i-1] + 0.003;
else
CumCst[i]
= CumCst[i-1];
}
if(CumCst[i]
>= 0.13)
CumCst[i] =
0.13;
}
per=19;
Smth=2/(per+1)+CumCst;
MovAvg=AMA(C,Smth);
Plot(movavg,"",colorBlue,1);
Plot(C,"",1,64);
PlotShapes(Buy*shapeUpArrow,colorGreen,0,L,-20);
PlotShapes(Sell*
shapeDownArrow,colorRed,0,H,-20);
Title="cumulative
value = "+WriteVal(Cumcst,1.3);
__._,_.___
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
__,_._,___
|