[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Buyprice changes while long



PureBytes Links

Trading Reference Links

ok good. This is also what I used but I found in some cases there are 2 buys in a row without a sell in between, even when running exrem. I thought that this was your problem.
 
Anyways, I guess it is solved now.
 
The code I have sent earlier was not complete. The stoploss needed to be trailing. I add the adjusted code + a chart,
 
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 ] = stopLoss[ j ];
         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
;
                  
         }
      }
   }
}

}

SetOption("MaxOpenPositions", 100
);
SetOption("PriceBoundChecking", True
);
PositionSize = -100
;
SetTradeDelays(0,0,0,0
);

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,shapeUpTriangle,shapeNone),colorGreen,0,L,-15
);
PlotShapes(IIf(Buy,shapeHollowUpTriangle,shapeNone),colorWhite,0,L,-15
);
PlotShapes(IIf(Buy,shapeHollowCircle,shapeNone),colorWhite,0,BuyPrice,0
);
PlotShapes(IIf(Sell,shapeDownTriangle,shapeNone),colorRed,0,H,-15
);
PlotShapes(IIf(Sell,shapeHollowDownTriangle,shapeNone),colorWhite,0,H,-15
);
PlotShapes(IIf(Sell,shapeHollowCircle,shapeNone),colorWhite,0,SellPrice,0);
 
 
 
 
 
 
 
 
 
 
----- Original Message -----
From: cagigas00
Sent: Friday, July 11, 2008 5:10 PM
Subject: [amibroker] Re: Buyprice changes while long

Hi Ed,

Thanks for answering. Yes, I have to rethink the exit since I am simulating a trail stop but I need it more complicated than the one I can implement with Applystop().

Regarding the problem with Buystop I have found a way to fix it. I need to place the Buyprice sentence:

BuyPrice=ValueWhen(Buy,Max(O,Ref(Entrypt,-1)));

below the Exrem() sentence, thus I remove the other ocurrences of Buy that move the Buyprice. Try it and you will see that the Buyprice is now a constant while long (the blue line). I guess this is a typical error when coding since we always want Buyprice below Buy signal. Buyprice needs to be static.

regards,

Oscar

 

 


--- In amibroker@xxxxxxxxxps.com, "Edward Pottasch" <empottasch@x..> wrote:
>
> hi,
>
> below I adjusted your code for the simplified sell algorithm. Like the buyPrice you can now also display the sellprice. Best to go from there. Expand your sell algorithm and look if you can display it, that will help you to see what your code is doing, rgds, Ed
>
> SetBarsRequired(10000,10000);
>
> Entrypt=HHV(H,3);
>
> Buy= Cross(H,Ref(Entrypt,-1));
> BuyPrice=ValueWhen(Buy,Max(O,Ref(Entrypt,-1)));
>
> //MaxTRADECLOSE=Ref(HighestSince(Buy,C),-1);
>
> Sell= L < Ref(LLV(L,5),-1);// OR (Maxtradeclose-BuyPrice) > 2*ATR(10);
> SellPrice=ValueWhen(Sell,Min(O, Ref(LLV(L,5),-1)));
>
> Buy = ExRem(Buy,Sell);
> Sell = ExRem(Sell,Buy);
>
> Plot(BuyPrice,"buyprice",colorBlue,styleLine);
> Plot(SellPrice,"maxtradeclose",colorLightBlue,styleLine);
>
> 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);
>

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___