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

Re: [amibroker] Re: Hedging with PositionScore?



PureBytes Links

Trading Reference Links

hi,
 
I think te code I posted in the beta group does not address your specific problem. I have not used varset so I would not know if there is a problem here. I posted my code here as wel and was not planning to upload in the file section since I am fairly new to the topic myself. I just tried to get some conversation going on the CBI but I think for many people the problem is  getting started with it.  I am finding out it is not too complicated it just needs some good examples.
 
Maybe if you explain what you want to do I can help,
 
rgds, Ed
 
 
 
----- Original Message -----
From: vlanschot
Sent: Tuesday, May 08, 2007 11:35 AM
Subject: [amibroker] Re: Hedging with PositionScore?

Question for Ed (nl) who created the code below in 03/2005, or of
course anybody else who cares to jump in.

Is there any reason why I cannot seem to get, in the GetFirstSignal-
loop, the values from a VarSet which I defined previously in the
GetFirstOpenPos-loop. Your code below shows that the "cntlongopen"
variable, defined in the 1st loop, can be called later in the 2nd
loop.

For all clarity, I need to make a link between stock-specific
variables between these loops. In other words, I use VarSet
("Var1"+openpos.Symbol, var1) in order to retrieve it in the 2nd loop
via VarGet("Var1"+sig.Symbol). So far, this doesn't work.

For context, and as mentioned in some of my previous mails, I'm
trying to code a fairly simple (I thought) rebalancing strategy, this
time without the rotational trading bit. Any help appreciated.

Thx,

PS

--- In amibroker@xxxxxxxxxps.com, "ed nl" <ed2000nl@xx.> wrote:
>
> Herman,
>
> I expanded the code a little. Now you can set maxShort is well. The
nice thing about this is that you will only go full inside the margin
with mixed long and short positions and not just either long or short,
>
> rgds, Ed
>
>
>
> /*
>
> Do not allow more than "maxLong" LONG positions OR "maxShort" SHORT
positions
>
> */
>
> SetCustomBacktestProc("");
>
> maxLong = 8;
> maxShort = 9;
>
> if( Status("action") == actionPortfolio ) {
>
> bo = GetBacktesterObject();
> bo.PreProcess();
>
> for( i = 0; i < BarCount; i++ ) {
>
>
> cntLongOpen = 0;
> cntShortOpen = 0;
>
> // scan through open positions and count the number of long
positions
> for( openpos = bo.GetFirstOpenPos(); openpos; openpos =
bo.GetNextOpenPos() ) {
>
> // check for entry signal and long signal
> if( openpos.IsOpen AND openpos.IsLong ) {
>
> cntLongOpen = cntLongOpen + 1;
>
> } else if ( openpos.IsOpen AND openpos.IsLong == 0) {
>
> cntShortOpen = cntShortOpen + 1;
>
> }
>
> }
>
>
> // look at new signals and exclude Long signals if they
exceed maxLong
> for( sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal
(i) ) {
>
> // check for entry signal and long signal
> if( sig.IsEntry() AND sig.IsLong() ) {
>
> if( cntLongOpen >= maxLong ) {
>
> sig.PosSize = 0;
>
> } else {
>
> cntLongOpen = cntLongOpen + 1;
>
>
> }
>
> // check for entry signal and short signal
> } else if ( sig.IsEntry() AND sig.IsLong() == 0) {
>
> if( cntShortOpen >= maxShort ) {
>
> sig.PosSize = 0;
>
> } else {
>
> cntShortOpen = cntShortOpen + 1;
>
>
> }
>
>
> }
>
>
> }
>
> bo.ProcessTradeSignals( i );
> }
>
> bo.PostProcess();
>
> }
> ----- Original Message -----
> From: Herman van den Bergen
> To: amibroker@xxxxxxxxxps.com
> Sent: Tuesday, March 01, 2005 11:59 AM
> Subject: RE: [amibroker] Hedging with PositionScore?
>
>
> Thank you Ed, will try that!
>
> herman
> -----Original Message-----
> From: ed nl [mailto:ed2000nl@...]
> Sent: Tuesday, March 01, 2005 2:42 AM
> To: amibroker@xxxxxxxxxps.com
> Subject: Re: [amibroker] Hedging with PositionScore?
>
>
> I think I answered my own question in case you are interested.
It seems to work.
>
> rgds, Ed
>
>
> /*
>
> Number of positions: do not allow more than "maxLong" LONG
positions
>
> */
>
> SetCustomBacktestProc("");
>
> maxLong = 7;
>
> if( Status("action") == actionPortfolio ) {
>
> bo = GetBacktesterObject();
> bo.PreProcess();
>
> for( i = 0; i < BarCount; i++ ) {
>
>
> cntLongOpen = 0;
>
> // scan through open positions and count the number of
long positions
> for( openpos = bo.GetFirstOpenPos(); openpos; openpos =
bo.GetNextOpenPos() ) {
>
> // check for entry signal and long signal
> if( openpos.IsOpen AND openpos.IsLong ) {
>
> cntLongOpen = cntLongOpen + 1;
>
> }
>
> }
>
>
> // look at new signals and exclude Long signals if they
exceed maxLong
> for( sig = bo.GetFirstSignal(i); sig; sig =
bo.GetNextSignal(i) ) {
>
> // check for entry signal and long signal
> if( sig.IsEntry() AND sig.IsLong() ) {
>
> if( cntLongOpen > maxLong ) {
>
> sig.PosSize = 0;
>
> } else {
>
> cntLongOpen = cntLongOpen + 1;
>
>
> }
>
>
> }
>
> }
>
> bo.ProcessTradeSignals( i );
> }
>
> bo.PostProcess();
>
> }

__._,_.___

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





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

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

__,_._,___