PureBytes Links
Trading Reference Links
|
It should be
BuyPrice[i] = ( 1 + FirstProfitTarget * 0.01 ) * PriceAtBuy;
--
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriting.com
2008/4/23 aryah55 <rrussell@xxxxxxxxxxxxx>:
>
> I have never got sigscaleout example 4 (or example 3 for that matter)
> from manual to work - until now (I think).
> As pointed out by Graham in previous messages, there is a critical
> line missing from the manual code and yours - see line under the Buy /
> sigScaleout line. This is in fact what you are looking for I think -
> the sigscaleout buy price code is
> BuyPrice[i] = FirstProfitTarget + PriceAtBuy;
> I dont know why this line works - it just does!! [I would have thought
> that the BuyPrice for the second parcel should be original buy price
> (Price at Buy) plus 10% thereof not plus 10 but???]
> I had other problems with the published code particularly with the
> Trail stop and have solved them with the revised code below. By
> placing the revised trail as an ELSE condition in both the initial and
> second stages, it exits at the appropriate stop ie its 10% below the
> initial buyprice and, after the scale out,it becomes 10% below the
> sigscaleout buyprice. Hope this helps.
>
> // 23April 2008.
> //========================== SIGSCALEOUT
> =============================================================
> // BASED ON A COPY OF EXAMPLE 4 FROM MANUAL RE SCALE IN AND OUT
> // EXAMPLE INCLUDES SIMPLE SCALE OUT OF POSITION ON PROFIT TARGETS ONLY
> // EXAMPLE (AND EXAMPLE3) DIN'T WORK FOR ME - OTHERS AS WELL AS NOTED
> ON MANY MESSAGES ON FORUM
> // MY PROBLEMS INCLUDED - SCALEOUT SCALED 90-95% OF POSITION ON FIRST
> PROFIT TARGET EVEN WHEN SET TO 50%
> // EXAMPLE DID WORK FOR SOME INCLUDING GRAHAM
> // TRACED FIRST PROBLEM AFTER TOO MANY HOURS TO THE INTERACTION
> BETWEEN SETTRADEDELAYS AND SIGSCALEOUT
> // MY FIX CREATED A SECOND PROBLEM - TRAIL WAS BEING EXECUTED ON SAME
> DAY THAT 2ND PROFIT TARGET MET - UNDERSTATING PROFIT.
> // NOT BEING ANY SORT OF PROGRAMMER, MY SOLUTIONS MAY BE
> ROUGH/INEFFICIENT BUT FOR WHAT ITS WORTH -
> // SOLUTION TO PROBLEM 1 - SetTradeDelays to (0,0,0,0) (MY default for
> EOD trading is (1,0,1,0))
> // Defer Buy Signal to today from yesterday -
> // Add BUYPRICE code below Buy SigScaleOut line as per Graham's
> message (Thanks)
> // Raw Signals now wrong but built in backtest ok
> // SOLUTION TO PROBLEM 2 - Change Trail and make an ELSE statement on
> both of the initial entry and the scale out IF statements
> // =================================== EXAMPLE 4 SOLVED (FOR ME)
> ======================================
> //======================================================================================================
> Buy = Cross( EMA( C, 8 ), EMA( C, 13 ) );
> Sell = 0; // Must be 0 as cannot use Sell if using scaleInOut?
> // My Long Default In Settings - Enter at the open tomorrow, exit
> at the close today!
>
> // TO AVOID SETTRADEDELAY Problem One -
> ================================================================
> SetTradeDelays(0,0,0,0); // ADDED THIS CODE - MUST SET THIS TO
> ZERO else SCALE OUT NO WORK!!!
> HoldBuy = 0;
> for( i = 0; i < BarCount-1; i++ )
> {
> if( Buy[i])
> {
> HoldBuy[i] = 0;
> HoldBuy[i+1] = 1;
> }
> }
> Buy = HoldBuy; // BUY signal now delayed to today from yesterday
> //
> //==================================================================================================
>
>
> // 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
> // nb - "Sell will exit the total trade AND cannot be used as pyramid
> exit. Only Buy can be used to scale in AND out"
>
>
> 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;
> BuyPrice[i] = FirstProfitTarget + PriceAtBuy; // ADDED per Group
> message from Graham - MUST HAVE
> }
> else // Added ELSE here for Initial entry trail stop
> {
> if( exit == 0 AND 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 == 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 );
> }
> else // Added ELSE here for trail stop on scale out parcel
> {
> if(exit == 1 AND Low[ i ] <= ( 1 - TrailingStop * 0.01 ) *
> highsincebuy )
> {
>
> exit = 3;
> SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 0.01 ) *
> highsincebuy );
> }
> }
> // REMOVE ORIGINAL TRAIL STOP FROM HERE
> if( exit >= 2 )
> {
> //Buy[i] = 0; // REM this as not necessary?
>
> Sell[ i ] = exit+1; // mark appropriate exit
> code(3profit,4Trail) AND define SELL (else no sells ever)
>
> exit = 0;
> priceatbuy = 0; // reset price
> highsincebuy = 0;
> }
> }
> }
> SetPositionSize( 2, spsPercentOfEquity); // 2% of equity
>
> SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) );
> // scale out 50% of position
>
>
> //==============================================================
>
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "gmorlosky" <gmorlosky@xxx> wrote:
> >
> > I would like to have an OR for the trailing stop of either
> > the "original Buy price OR the last sigscaleout price". Can't figure
> > how to reference the last sigscaleout price. Help please.
> >
> > 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
> >
------------------------------------
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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
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/
|