Lets make efficient auto trading setup

#1
Dear Friends,

Lets we try to make auto trading setup with features below:-

1. Position Size should be of Rs. 200000/- only
2. It should be of 4 Lots Strategy.
3. 50% (2 Lots) profit booking at 1st Target and Remaining 50% (1 Lot) profit booking at 2nd Target and Rest as per reverse signal.
4. Position must close end of the day.
5. Trailing SL will be 0.5% to 1% as per symbol.
6. This setup must suit with any buy, sell, short, cover signals means we will just copy / paste this afl below our any buy / sell logic.
7. This afl should be usable for auto / mechanical trading.

this afl must work with any strategy as simple as below:-

buy = ema(c,5)>ema(c,15) and ema(c,5) > ema(c,25);
sell = ema(c,5)<ema(c,15);
short=ema(c,5)<ema(c,15) and ema(c,5)<ema(c,25);
cover=ema(c,5)>ema(c,25);

or any other setup.

Thanks in Advance.
 
#2
SYNTAX SetPositionSize( size, method )
RETURNS ARRAY
FUNCTION This function allows to control trade (position) size in four different ways, depending on 'method' parameter.

Parameters:

size (ARRAY) defines desired trade size

method (ARRAY) defines how 'size' is interpreted

spsValue (=1) - dollar value of size (as in previous versions)
spsPercentOfEquity (=2) - size expressed as percent of portfolio-level equity (size must be from ..100 (for regular accounts) or .1000 for margin accounts)
spsShares (=4) - size expressed in shares/contracts (size must be > 0 )
spsPercentOfPosition (=3) - size expressed as percent of currently open position (for SCALING IN and SCALING OUT ONLY)
spsNoChange (=0) - don't change previously set size for given bar

New SetPositionSize function automatically encodes new methods of expressing position size into old "positionsize" variable as follows:

values below -2000 encode share count,
values between -2000 and -1000 encode % of current position
values between -1000 and 0 encode % of portfolio equity
values above 0 encode dollar value

Although it is possible to assign these values directly to old-style PositionSize variable, new code should use SetPositionSize function for clarity.
EXAMPLE For example to liquidate 50% of position simply use

SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) );

Special value spsNoChange (=0) means don't change previously set size for given bar (allows to write constructs like that):

SetPositionSize( 100, spsShares ); // 100 shares by default
SetPositionSize( 50, IIf( Buy == sigScaleOut, spsPercentOfPosition, spsNoChange ) ); // for scale-out use 50% of current position size

Example of code that exits 50% on first profit target, 50% on next profit target and everything at trailing stop:

Buy = Cross( MA( C, 10 ), MA( C, 50 ) );
Sell = 0;

// the system will exit
// 50% of position if FIRST PROFIT TARGET stop is hit
// 50% of position is SECOND PROFIT TARGET stop is hit
// 100% of position if TRAILING STOP is hit

FirstProfitTarget = 10; // profit
SecondProfitTarget = 20; // in percent
TrailingStop = 10; // also in percent

priceatbuy=0;
highsincebuy = 0;

exit = 0;

for( i = 0; i < BarCount; i++ )
{
if( priceatbuy == 0 AND Buy[ i ] )
{
priceatbuy = BuyPrice[ i ];
}

if( priceatbuy > 0 )
{
highsincebuy = Max( High[ i ], highsincebuy );

if( exit == 0 AND
High[ i ] >= ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy )
{
// first profit target hit - scale-out
exit = 1;
Buy[ i ] = sigScaleOut;
}

if( exit == 1 AND
High[ i ] >= ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy )
{
// second profit target hit - exit
exit = 2;
SellPrice[ i ] = Max( Open[ i ], ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy );
}

if( Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * highsincebuy )
{
// trailing stop hit - exit
exit = 3;
SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 0.01 ) * highsincebuy );
}

if( exit >= 2 )
{
Buy[ i ] = 0;
Sell[ i ] = exit + 1; // mark appropriate exit code
exit = 0;
priceatbuy = 0; // reset price
highsincebuy = 0;
}
}
}

SetPositionSize( 50, spsPercentOfEquity );
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) ); // scale out 50% of position
SEE ALSO
References:

The SetPositionSize function is used in the following formulas in AFL on-line library:

Connors TPS
Customised Avg. Profit %, Avg. Loss % etc
Ed Seykota's TSP: EMA Crossover System
Scale Out: Futures
testing multiple system simulataneously
Trend Following System

Unreviewed user comments:
MikeB
-------
2006-04-09 08:32:33 Note that the price used to sell partial (first profit target) is NOT the SellPrice but the BuyPrice. So, the code should read as follows...

if( exit == 0 AND
High[ i ] >= ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy )
{
// first profit target hit - scale-out
exit = 1;
Buy[ i ] = sigScaleOut;
BuyPrice[ i ] = ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy; // Set SellPrice via BuyPrice
}
}
 
#3
This is my strategy for autobot trading for my market
I will try for nifty and see the result
I still want to reduce the DD to low as 5-6% need to consider something more
anyone can suggest to imrpove the strategy tell me
 

Similar threads