I am working on daytrade systems on ES
futures. I have a simple setup I want to test first:
Long Only:
1) enter 2 contracts at the open, 1 bar
after a buy signal
2) scale out 1 contract if profit target 1 is
hit
3) exit second contract if profit target 2 is
hit
4) exit position (partial or whole) if
trailing stop is hit
First question: how does one use setPositionSize?
I tried this:
SetPositionSize( 2, spsShares );
SetPositionSize( 1, spsShares * ( Buy == sigScaleOut ) );
Second question: the exit code I use is based no
the example code in the manual (see below). But in my specific setup I want to
define a exit price once the first target is hit. How does one do
this?
thanks, Ed
procedure
sellCoverChandelier3_proc(Buy,BuyPrice) {
global Sell;
global SellPrice;
global TrailStopArray;
global HighSinceBuyArray;
global BuyAdjusted;
Sell = 0;
SellPrice = 0;
BuyAdjusted =
0;
TrailStopArray = Null;
HighSinceBuyArray = Null;
FirstProfitTarget = 0.5; // in
points
SecondProfitTarget = 1;
TrailingStop = 4;
priceatbuy=0;
for( i = 0; i < BarCount; i++ )
{
exitType =
0;
if ( Buy[ i ] )
{
priceatbuy = BuyPrice[ i ];
highsincebuy = 0;
BuyAdjusted[ i ] =
1;
for (j = i; j < BarCount; j++)
{
highsincebuy =
Max( High[ j ], highsincebuy );
HighSinceBuyArray[ i ]
= highsincebuy;
TrailStopArray[ j ] =
highsincebuy - TrailingStop;
if( exitType == 0 AND High[ j ] >= (priceatbuy + FirstProfitTarget) )
{
// first profit target hit - scale-out
exitType
= 1;
Buy[ j ] = sigScaleOut;
}
if( exitType == 1 AND High[ j ] >= (priceatbuy + SecondProfitTarget) )
{
// second profit target hit - exit
exitType
= 2;
Sell[ j ] = 1;
SellPrice[ j ] = Max( Open[ j ], (priceatbuy + SecondProfitTarget) );
i =
j;
break;
}
if( Low[ j ] <= (highsincebuy - TrailingStop) )
{
// trailing stop hit - exit
Sell[ j ] = 1;
SellPrice[ j ] = Min( Open[ j ], (highsincebuy - TrailingStop) );
i =
j;
break;
}
}
}
}
}