Search the web
Sign In
New User? Sign Up
amibroker · AmiBroker User's List
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
pyramiding - problems with code   Message List  
Reply | Forward Message #139951 of 143811 |
Re: pyramiding - problems with code

Thanks Ed! I am sure I will learn a lot after studying your code. Thanks for
sharing.
Best regards
Larry

--- In amibroker@yahoogroups.com, "Edward Pottasch" <empottasch@...> wrote:
>
> hi,
>
> attached again. Changed little thing with chart.
>
> should be able to see it at www.yahoo.com groups
>
> rgds, Ed
>
>
>
> ----- Original Message -----
> From: onelkm
> To: amibroker@yahoogroups.com
> Sent: Saturday, July 04, 2009 4:19 PM
> Subject: [amibroker] Re: pyramiding - problems with code
>
>
>
>
>
> Ed
> Thanks but the attachments do not show up. Could you try again?
> Larry
>
> --- In amibroker@yahoogroups.com, "Edward Pottasch" <empottasch@> wrote:
> >
> > attached some code on scaling out. Test code for ES futures. What it does
it takes an initial position of 3 contracts when there is a long or short
signal. Then there are 3 targets. It will scale out of these 3 positions when
the targets are hit. However, if the trailing stop is hit it will sell all
positions that are left. Also when the endtime is hit all open positions are
closed. So situations may occur that it opens 3 long contracts and only the
first target is hit and it scales out of 1 position. 2 positions left and then
the endtime is hit and it will sell the remaining 2 contracts.
> >
> > see example chart (5 minute timeframe): here you see a full long scale out
followed by a full short scale out.
> >
> >
> >
> >
> >
> > ----- Original Message -----
> > From: onelkm
> > To: amibroker@yahoogroups.com
> > Sent: Friday, July 03, 2009 6:37 PM
> > Subject: [amibroker] Re: pyramiding - problems with code
> >
> >
> >
> >
> >
> >
> > Could you please post the code that now runs? I am also interested in
pyramiding on the short side and would like to see how you programmed it.
> > Thanks
> > Larry
> > --- In amibroker@yahoogroups.com, "Edward Pottasch" <empottasch@> wrote:
> > >
> > > the code is just an example and I believe I used your setup system:
> > >
> > > Buy = ( Cross( MA( C, 10 ), MA( C, 50 ) ) ) * timearray;
> > > Buy = Ref(Buy,-1); BuyPrice = O;
> > >
> > > in this case you use the Close price in the Buy statement. In real time
systems the Close price is equal to the Last price. So within the timeframe you
use (e.g. 1 minute bars) a signal may appear and disappear within the bar. You
are only interested in the true close price of that bar. This is known only at
the end of the bar. That's why when adding Buy = Ref(Buy,-1); you shift the Buy
array 1 element forward and use the signal of the previous bar and you enter at
the open. This way you avoid entering a trade of which the signal disappears
later in the bar.
> > >
> > > Another reason is that I myself use it for my real time system is that
trading a cross is often not realistic in the practice unless you enter a trade
using Market (MKT) orders. For instance if you let the High cross a certain
level you avoid getting multiple signals and also the signal will not disappear
but often this is exacly the time that the price is running away from you and
often you will not be able to enter the trade at the cross price. So I stopped
fooling myself with these 20000% per year results and wait for the bar to finish
and enter at the open of the next bar.
> > >
> > > regards, Ed
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: gborrageiro
> > > To: amibroker@yahoogroups.com
> > > Sent: Friday, July 03, 2009 12:31 PM
> > > Subject: [amibroker] Re: pyramiding - problems with code
> > >
> > >
> > >
> > >
> > >
> > > hi Edward,
> > >
> > > Why do you utilize the buy and short price from the previous bar?
> > > Buy = Ref( Buy, -1 );
> > > Short = Ref( Short, -1 );
> > >
> > > thx
> > >
> > > --- In amibroker@yahoogroups.com, "Edward Pottasch" <empottasch@> wrote:
> > > >
> > > > do you ever read replies?
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: gborrageiro
> > > > To: amibroker@yahoogroups.com
> > > > 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 );
> > > >
> > >
> >
>





Sat Jul 4, 2009 3:10 pm

onelkm
Offline Offline
Send Email Send Email

Forward
Message #139951 of 143811 |
Expand Messages Author Sort by Date

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...
gborrageiro
Offline Send Email
Jun 25, 2009
4:37 pm

do you ever read replies? ... From: gborrageiro To: amibroker@yahoogroups.com Sent: Thursday, June 25, 2009 6:36 PM Subject: [amibroker] pyramiding - problems...
Edward Pottasch
ed2000nl
Offline Send Email
Jun 25, 2009
8:52 pm

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,...
gborrageiro
Offline Send Email
Jul 3, 2009
9:24 am

hi Edward, Why do you utilize the buy and short price from the previous bar? Buy = Ref( Buy, -1 ); Short = Ref( Short, -1 ); thx...
gborrageiro
Offline Send Email
Jul 3, 2009
10:32 am

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...
Edward Pottasch
ed2000nl
Offline Send Email
Jul 3, 2009
10:11 am

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...
Mike
sfclimbers
Offline Send Email
Jul 3, 2009
4:33 pm

the code is just an example and I believe I used your setup system: Buy = ( Cross( MA( C, 10 ), MA( C, 50 ) ) ) * timearray; Buy = Ref(Buy,-1); BuyPrice = O; ...
Edward Pottasch
ed2000nl
Offline Send Email
Jul 3, 2009
11:03 am

Could you please post the code that now runs? I am also interested in pyramiding on the short side and would like to see how you programmed it. Thanks Larry...
onelkm
Offline Send Email
Jul 3, 2009
4:38 pm

ok thanks Mike, regards, Ed ... From: Mike To: amibroker@yahoogroups.com Sent: Friday, July 03, 2009 6:32 PM Subject: [amibroker] Re: pyramiding - problems...
Edward Pottasch
ed2000nl
Offline Send Email
Jul 3, 2009
10:01 pm

hi, the code is attached in reply to the first question about pyramiding by gborrageiro. I will post some code what I have on this tomorrow that enters 3...
Edward Pottasch
ed2000nl
Offline Send Email
Jul 3, 2009
10:05 pm

hi, I attach some code that might be interesting to some and illustrates what I was saying about problems when using signals based on a cross. It is based on...
Edward Pottasch
ed2000nl
Offline Send Email
Jul 3, 2009
10:59 pm

attached some code on scaling out. Test code for ES futures. What it does it takes an initial position of 3 contracts when there is a long or short signal....
Edward Pottasch
ed2000nl
Offline Send Email
Jul 4, 2009
7:57 am

Ed Thanks but the attachments do not show up. Could you try again? Larry...
onelkm
Offline Send Email
Jul 4, 2009
2:20 pm

hi, attached again. Changed little thing with chart. should be able to see it at www.yahoo.com groups rgds, Ed ... From: onelkm To: amibroker@yahoogroups.com ...
Edward Pottasch
ed2000nl
Offline Send Email
Jul 4, 2009
2:31 pm

Thanks Ed! I am sure I will learn a lot after studying your code. Thanks for sharing. Best regards Larry...
onelkm
Offline Send Email
Jul 4, 2009
3:11 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help