Ed,
Nice piece of work.
Please, how do you post your
formula to keep tabs ?
Every time I send a formula with Yahoo, the
lines are right indented.
Regards
--- In amibroker@xxxxxxxxxps.com,
"Edward Pottasch" <empottasch@...>
wrote:
>
>
hi,
>
> another Email .... the original problem you have has to
do with the
fact that at some bars there is a buy and a sell signal at the
same
bar. For some reason using exrem it is not treated properly it
seems
.. did not figure out what exactly is the problem.
>
>
I find it pretty hard to put all your rules inside 1 sell
statement.
Therefore I show you how to solve your problem using a
additional
procedure. Basicly once you are in a trade you have
> - a
stoploss (sort of a trailing stop) defined by Ref(LLV(L,5),-1)
and
you have
> - a profit stop defined by Ref(2*ATR(10),-1).
>
> Below I show how you could code your idea, rgds, Ed
>
>
>
>
> procedure
sell_proc(Buy,BuyPrice,stopLoss,profitTarget) {
>
> global Sell;
> global SellPrice;
>
> global
BuyAdjusted;
> global BuyPriceAdjusted;
>
> Sell = 0;
> SellPrice = 0;
>
> BuyAdjusted = 0;
>
BuyPriceAdjusted = 0;
>
> global stopLossLine;
> global
profitTargetLine;
>
> stopLossLine = Null;
>
profitTargetLine = Null;
>
> for( i = 0; i < BarCount; i++ )
> {
>
> if ( Buy[ i ] )
> {
>
>
BuyAdjusted[ i ] = 1;
> BuyPriceAdjusted[ i ] = BuyPrice[ i ];
>
> stopLossLine[ i ] = stopLoss[ i ];
> profitTargetLine[ i ] =
BuyPrice[ i ] + profitTarget[ i ];
>
> for (j = i + 1; j <
BarCount; j++)
> {
> stopLossLine[ j ] = stopLossLine[ i ];
> profitTargetLine[ j ] = profitTargetLine[ i ];
>
> if(
L[ j ] <= stopLossLine[ j ] )
> {
>
> Sell[ j ] = 1;
> SellPrice[ j ] = Min(O[ j ],stopLossLine[ j ]);
>
> i =
j;
> break;
>
> }
> else if( H[ j ] >
profitTargetLine[ j ] )
> {
>
> Sell[ j ] = 1;
>
SellPrice[ j ] = Max(O[ j ],profitTargetLine[ j ]);
>
> i = j;
> break;
>
> }
> else if (j == BarCount - 1)
> {
>
> i = BarCount;
>
> }
> }
> }
> }
>
> }
>
>
>
SetBarsRequired(10000,10000);
>
>
Entrypt=HHV(H,3);
>
> Buy=
Cross(H,Ref(Entrypt,-1));
>
BuyPrice=Max(O,Ref(Entrypt,-1));
>
>
sell_proc(Buy,BuyPrice,Ref(LLV(L,5),-1),Ref(2*ATR(10),-1)
);
>
> Buy = BuyAdjusted;
> BuyPrice = BuyPriceAdjusted;
>
>
Plot(stopLossLine,"stopLossLine",colorBlue,styleThick);
>
Plot(profitTargetLine,"profitTargetLine",colorLightBlue,styleThick);
>
Plot(Ref(Entrypt,-1),"EntryLevel",colorYellow,styleDashed);
>
> SetChartOptions(0, chartShowDates);
>
Plot(C,"Last=",colorBlack,64);
>
>
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-15);
>
PlotShapes(IIf(Buy,shapeHollowCircle,shapeNone),colorGreen,0,BuyPrice,0);
>
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
>
PlotShapes(IIf(Sell,shapeHollowCircle,shapeNone),colorRed,0,SellPrice,0);
>
>
>
>
>
>
>
> -----
Original Message -----
> From: cagigas00
> To: amibroker@xxxxxxxxxps.com
> Sent: Friday, July 11, 2008 11:08 AM
> Subject: [amibroker]
Buyprice changes while long
>
>
>
> The following
code replicates the problem I am having with a
system. The buyprice is
suppossed to be constant while the system is
long, however it keeps
changing. How can I make the Buyprice a constant?
>
>
Thanks
>
> Oscar
>
> //COND//
>
>
Entrypt=HHV(H,3);
>
> //ENTRY SIGNAL//
>
> Buy=
H > Ref(Entrypt,-1);
>
>
BuyPrice=ValueWhen(Buy,Ref(Entrypt,-1));
>
> //EXIT
SIGNAL//
>
>
MaxTRADECLOSE=Ref(HighestSince(Buy,C),-1);
>
>
Sell= L < Ref(LLV(L,5),-1) OR (Maxtradeclose-BuyPrice) >
2*ATR(10);
>
> //REMOVE EXCESIVE SIGNALS//
>
>
Buy=ExRem(Buy,Sell);
>
> Sell=ExRem(Sell,Buy);
>
> //PLOT BUY AND SELL POINTS//
>
>
Plot(C,"Last=",colorBlack,styleBar|styleThick);
>
>
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-15);
>
>
PlotShapes(IIf(Buy,shapeHollowCircle,shapeNone),colorGreen,0,BuyPrice,0);
>
>
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
>
>
PlotShapes(IIf(Sell,shapeHollowCircle,shapeNone),colorRed,0,SellPrice,0);
>
> //AUX//
>
>
Plot(Buy,"buy",colorRed,styleLine|styleOwnScale);
>
>
Plot(BuyPrice,"buyprice",colorBlue,styleLine);
>
>
Plot(Maxtradeclose,"maxtradeclose",colorGreen,styleLine);
>