[amibroker] Re: Different positionsize long/short

 

Hi Hans

You could try something like the following, which keeps a count of the number of entry signals since the last exit and uses that to derive the values.

Buy = //your buy rule
Sell = // your sell rule
Short = //your short rule
Cover = // your cover rule

BuyPos1 = 1;
BuyPos2 = 1;
BuyPos3 = 1;

ShortPos1 = 2;
ShortPos2 = 1;
ShortPos3 = 1;

// insert an extra exit signal at the start of the range to make the next part work correctly
Sell |= Status("FirstBarInRange"); 
Cover |= Status("FirstBarInRange");

// count how many entry signals since the last exit
BuyNum = SumSince(Sell, Buy); 
ShortNum = SumSince(Cover, Short);

// get the parameter value for the entry number
LongPosQty = IIf(BuyNum == 1, BuyPos1, 
IIf(BuyNum == 2, BuyPos2, 
IIf(BuyNum == 3, BuyPos3, 0)));

ShortPosQty = IIf(ShortNum == 1, ShortPos1, 
IIf(ShortNum == 2, ShortPos2, 
IIf(ShortNum == 3, ShortPos3, 0)));

// set the position size
SetPositionSize(IIf(Buy, LongPosQty, IIf(Short, ShortPosQty, spsNoChange)), spsShares);

Filter = Buy OR Short;
AddColumn(Buy, "Buy", 1);
AddColumn(Short, "Short", 1);
AddColumn(BuyNum, "BuyNum", 1);
AddColumn(ShortNum, "ShortNum", 1);
AddColumn(LongPosQty, "LongPosQty", 1);
AddColumn(ShortPosQty, "ShortPosQty", 1);


Cheers
Alan
Helixtrader.com

__._,_.___

Posted by: alan.clement@gmail.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (5)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.

**** 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/


.

__,_._,___


EmoticonEmoticon