PureBytes Links
Trading Reference Links
|
Here's the whole code if you care to see it, I still don't get a
single trade...
Short = Cross( MA( C, 10 ), MA( C, 5 ) );
Cover = 0 ;
FirstProfitTarget = .05; // profit
SecondProfitTarget = .1; // in percent
TrailingStop = .1; // also in percent
Icing = .03 ;
priceatshort=0;
Lowsinceshort=0;
exit = 0;
/*--------------------------------Short code-------------------------
---------*/
for( i = 0; i < BarCount; i++ )
{
if( priceatshort == 0 AND Short[ i ] )
{
priceatshort = ShortPrice[ i ];
}
if( priceatshort > 0 )
{
Lowsinceshort= Min( Low[ i ], Lowsinceshort);
//PT1
if( exit == 0 AND Low[ i ] <= ( 1 - FirstProfitTarget * 0.01 )
* priceatshort)
{
exit = 1;
ShortPrice[i] = ( 1 - FirstProfitTarget * 0.01 ) *
priceatshort;
Short[ i ] = sigScaleOut;
}
//PT2
if( exit == 1 AND Low[ i ] <= ( 1 - SecondProfitTarget *
0.01 ) * priceatshort)
{
exit = 2;
ShortPrice[ i ] = ( 1 - SecondProfitTarget * 0.01 ) *
priceatshort ;
Short[ i ] = sigScaleOut;
}
//PT3 Icing
if( exit == 2 AND Close[ i ] >= ( 1 + Icing * 0.01 ) *
Lowsinceshort)
{
exit = 3;
CoverPrice[ i ] = ( 1 + Icing * 0.01 ) * Lowsinceshort ;
}
//Trail Stop Loss
if( High[ i ] >= ( 1 + TrailingStop * 0.01 ) * Lowsinceshort )
{
exit = 4;
CoverPrice[ i ] = ( 1 + TrailingStop * 0.01 ) *
Lowsinceshort ;
}
//Reset for the next loop
if( exit >= 3 )
{
Short[ i ] = 0;
Cover[ i ] = exit + 1; // mark appropriate exit code
exit = 0;
priceatshort= 0; // reset price
Lowsinceshort = 0;
}
}
}
SetPositionSize( 50, spsPercentOfEquity ); /*Initial % of equity to
be traded.*/
SetPositionSize( 50, spsPercentOfPosition * ( Short ==
sigScaleOut ) ); /* percentage to scale out when PT's are hit*/
--- In amibroker@xxxxxxxxxxxxxxx, "Terry" <MagicTH@xxx> wrote:
>
> The first part of the code works. I get shorts.
> The looping part is incomplete (will not compile). You must've not
> copied it all.
>
> --
> Terry
> -----Original Message-----
> From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]
On
> Behalf Of orionsturtle
> Sent: Friday, July 14, 2006 12:08
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Why wont this code allow short trades???
>
> I tried to make this help file code work on the short side, but it
> never even enters into a single trade. I did set the backtest
> positions to short. Could someone please just take a quick look at
> this small piece of code and maybe you can see why it wont trade
> short. I believe it is something simple but I can't seem to find
> it.Thank you.
> ---------------------------
> Short = Cross( MA( C, 10 ), MA( C, 5 ) );
> Cover = 0 ;
> priceatshort=0;
> Lowsinceshort=0;
> exit = 0;
>
> for( i = 0; i < BarCount; i++ )
> {
> if( priceatshort == 0 AND Short[ i ] )
> {
> priceatshort = ShortPrice[ i ];
> }
> if( priceatshort > 0 )
> {
> Lowsinceshort= Min( Low[ i ], Lowsinceshort);
> //PT1
> if( exit == 0 AND Low[ i ] <= ( 1 - FirstProfitTarget *
0.01 )
> * priceatshort)
> {
> exit = 1;
> ShortPrice[i] = ( 1 - FirstProfitTarget * 0.01 ) *
> priceatshort;
> Short[ i ] = sigScaleOut;
> }
>
>
>
>
>
>
>
> Please note that this group is for discussion between users only.
>
> To get support from AmiBroker please send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> For other support material please check also:
> http://www.amibroker.com/support.html
>
>
> Yahoo! Groups Links
>
|