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

[amibroker] Re: pyramiding - problems with code



PureBytes Links

Trading Reference Links

Ed,

For what it is worth, it was your replies to my very first post that got me over the hump and on my way to solving my problem. It was also the spirit and generousity of those replies that instilled in me a sense of obligation to give back whenever I thought I might have something to offer in the same way that you helped me.

Keep posting! And thanks again.

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@xxx> wrote:
>
> ok great. Sorry for my annoyed reply but sometimes I give detailed responses and never find out if my response is even read which kind off takes away the stimulus :)
> 
> For the code I posted you can add to scale out of additional contracts if needed. I have yet to work on problems where one first scales in and then scales out.
> 
> regards, Ed
> 
> 
> 
>   ----- Original Message ----- 
>   From: gborrageiro 
>   To: amibroker@xxxxxxxxxxxxxxx 
>   Sent: Friday, July 03, 2009 11:23 AM
>   Subject: [amibroker] Re: pyramiding - problems with code
> 
> 
> 
> 
> 
>   hi Edward,
> 
>   I do read replies...for some reason when I searched for my prior post it did'nt come up, so I thought it had'nt been posted.
>   Thanks for your code, it works!
>   I spent three weeks with Amibroker support and could'nt get it resolved. Code issues are not high on the list of their priorities unfortunately. 
> 
>   thanks again.
> 
>   --- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@> wrote:
>   >
>   > do you ever read replies?
>   > 
>   > 
>   > ----- Original Message ----- 
>   > From: gborrageiro 
>   > To: amibroker@xxxxxxxxxxxxxxx 
>   > Sent: Thursday, June 25, 2009 6:36 PM
>   > Subject: [amibroker] pyramiding - problems with code
>   > 
>   > 
>   > 
>   > 
>   > 
>   > hi,
>   > 
>   > I am testing some scaling out strategies and can't get the backtester to go short. There's a prob with my code somewhere but I just can't see where. 
>   > 
>   > Your help would be appreciated! thanks
>   > 
>   > SetTradeDelays( 0, 0, 0, 0 );
>   > BuyPrice = Avg;
>   > ShortPrice = Avg;
>   > SetOption( "FuturesMode", True );
>   > SetOption( "InitialEquity", 100000 );
>   > 
>   > fast = ema(avg,10);
>   > slow = ema(avg,100);
>   > 
>   > Buy = Cross( fast, slow ) ;
>   > Short = Cross( slow, fast ) ;
>   > Sell = 0;
>   > Cover = 0;
>   > 
>   > FirstProfitTarget = 0.02; 
>   > TrailingStop = 0.06; 
>   > StopLoss = 0.02;
>   > 
>   > priceatbuy = 0;
>   > highsincebuy = 0;
>   > priceatshort = 0;
>   > lowsinceshort = 0;
>   > 
>   > exit = 0;
>   > 
>   > for ( i = 0; i < BarCount; i++ )
>   > {
>   > if ( priceatbuy == 0 AND Buy[ i ] )
>   > {
>   > priceatbuy = BuyPrice[ i ];
>   > }
>   > 
>   > if ( priceatshort == 0 AND Short[ i ] )
>   > {
>   > priceatshort = ShortPrice[ 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 ( Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * highsincebuy )
>   > {
>   > // trailing stop hit - exit
>   > exit = 2;
>   > SellPrice[ i ] = Min( Avg[ i ], ( 1 - TrailingStop * 0.01 ) * highsincebuy );
>   > }
>   > 
>   > if ( Low[ i ] <= ( 1 - StopLoss * 0.01 ) * priceatbuy )
>   > {
>   > // Stop Loss hit - exit
>   > exit = 3;
>   > SellPrice[ i ] = Min( Avg[ i ], ( 1 - StopLoss * 0.01 ) * priceatbuy );
>   > }
>   > 
>   > if ( exit >= 2 )
>   > {
>   > Buy[ i ] = 0;
>   > Sell[ i ] = exit + 1; // mark appropriate exit code
>   > exit = 0;
>   > priceatbuy = 0; // reset price
>   > highsincebuy = 0;
>   > }
>   > }
>   > 
>   > if ( priceatshort > 0 )
>   > {
>   > lowsinceshort = Min( Low[ i ], lowsinceshort );
>   > 
>   > if ( exit == 0 AND
>   > Low[ i ] <= ( 1 - FirstProfitTarget * 0.01 ) * priceatshort )
>   > {
>   > // first profit target hit - scale-out
>   > exit = 1;
>   > Short[ i ] = sigScaleOut;
>   > 
>   > }
>   > 
>   > if ( High[ i ] >= ( 1 + TrailingStop * 0.01 ) * lowsinceshort )
>   > {
>   > // trailing stop hit - exit
>   > exit = 2;
>   > CoverPrice[ i ] = Max( Avg[ i ], ( 1 + TrailingStop * 0.01 ) * lowsinceshort );
>   > }
>   > 
>   > if ( High[ i ] >= ( 1 + StopLoss * 0.01 ) * priceatshort )
>   > {
>   > // Stop Loss hit - exit
>   > exit = 3;
>   > CoverPrice[ i ] = Max( Avg[ i ], ( 1 + StopLoss * 0.01 ) * priceatshort );
>   > }
>   > 
>   > if ( exit >= 2 )
>   > {
>   > Short[ i ] = 0;
>   > Cover[ i ] = exit + 1; // mark appropriate exit code
>   > exit = 0;
>   > priceatshort = 0; // reset price
>   > lowsinceshort = 0;
>   > }
>   > }
>   > }
>   > 
>   > SetPositionSize( 2, spsShares );
>   > 
>   > SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) ); // scale out 50% of position
>   > //SetPositionSize( 50, 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/