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

[amibroker] setpositonsize question



PureBytes Links

Trading Reference Links

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/