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

[amibroker] Re: setpositonsize question



PureBytes Links

Trading Reference Links

Hi,

I haven't tested any of the following, so you'll need to do your own due diligence. But I suspect the following...

1. SetPositionSize just popluates the resereved array named PositionSize.

2. You should not be calling SetPositionSize repeatedly from within a loop. This method sets all bars of the PositionSize array, replacing whatever was there before (i.e. you are clobbering the array every call).

3. If you want to change a single bar of the PositionSize array, just reference it using standard array dereference operator [].

So, try moving your call to SetPositionSize(10, spsPercentOfEquity ) to before the loop such that every bar is initialized to that value. 

Then, within your loop, just change the i-th bar of the PositionSize array. Note that the documentation of SetPositionSize indicates that percentage of position values will be in the range -1000 to -2000. Thus, to set 200 spsPercentageOfPosition do PositionSize[i] = -1200.

See if that works for you.

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "ronspieker" <tip001@xxx> wrote:
>
> Newbie question:
> 
> Can you reset the SetPositionSize function at various points in the code? (For variable size postions) For example, for the first buy signal 
> 
>    SetPositionSize(10, spsPercentOfEquity ); 
> 
> Then for the second buy trigger, triple the position
> 
>   SetPositionSize(200, spsPercentOfPosition);
> 
> 	
> An example code (which only triggers the first position size statement) would be
> 
> 
> SetTradeDelays( 0, 0, 0, 0 ); 
> SetOption("MaxOpenPositions", 4); 
> 
> 
> _TRACE("!CLEAR!"); 
> 
> 
> //Buy and Sell Conditions
> 
> Cond1 = Close > MA (C , 200);
> Cond2 = RSI(2) <25;
> Cond4 = RSI(2) >70;
> 
> // Initialize 
> 
> 	BuyPriceA=BuyPriceB=BuypriceC=BuypriceD=0;
> 	intrade=0;
> 	Tradedate=DateTime();
> 	TradedateA=TradedateB=TradedateC=Null;
> 
> // Loop through all the bars
> 
> 	for(i = 1; i < BarCount; i++)
> 	{
> 	
> 			if(intrade==0)
> 			{
> 				if((Cond1[i]==1) AND (Cond2[i]==1) ) //Enter Position 1 
> 				{
> 			
> 					Intrade=1;
> 					Buy[i] = 1;
> 					BuyPriceA = BuyPrice[i];
> 					TradedateA=Tradedate[i];
> 
> 				}
> 			else
> 				{
> 	
> 				}					
> 			}
> 	
> 
> 			if((intrade==1) AND tradedateA != Tradedate[i])
> 			{
> 	
> 				if (C[i]<BuyPriceA) //Enter position 2
> 				{
> 					SetPositionSize(200, spsPercentOfPosition);
> 					Intrade=2;
> 					Buy[i]=1;
> 					BuyPriceB=BuyPrice[i];
> 					TradedateB=Tradedate[i];
> 				}
> 
> 				else
> 				{
> 					
> 				} 
> 			}
> 
> 			
> 			if((intrade==1 OR intrade==2 ) AND (Cond4[i]==1))		
> 				{
> 						Sell[i]=Cond4[i];
> 						intrade=0;
> 						BuyPriceA=0;
> 						BuyPriceB=0;
> 		
> 				}
> 		
> 
> 						
> 	}
> 	
> SetPositionSize(10, spsPercentOfEquity );
>




------------------------------------

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

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/