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

Re: [amibroker] Re: Help with trading system



PureBytes Links

Trading Reference Links



My Problem with the code below is that it does not do the job , you have to either put bollinger bands on the macd and work around or leave out the macd  , a cross on the macd is not the option as it will only take one period for the cross .

I tried to simplyfy it with a RSI single strategy which does not work so well either it brings back lots of warrants and futures when im looking for stocks . But here it is , Im going to have to find a way around this . maybe you can use this better than me


//RSI

/* Basics */
SetBarsRequired(10000,10000); /* this ensures that the charts include all bars AND NOT just those on screen */
SetFormulaName("RSI System"); /*name it for backtest report identification */
SetTradeDelays( 1, 1, 1, 1 ); /* delay entry/exit by one bar */
SetOption( "initialequity", 100000 ); /* starting capital */
PositionSize = -10; /* trade size will be 10% of available equty */
SetOption( "MaxOpenPositions", 6 ); /* I don't want to comit more than 60% of Equity at any one time */
SetOption( "PriceBoundChecking", 1 ); /* trade only within the chart bar's price range */
SetOption( "CommissionMode", 2 ); /* set commissions AND costs as $ per trade */
SetOption( "CommissionAmount", 32.95 ); /* commissions AND cost */
SetOption( "UsePrevBarEquityForPosSizing", 1 ); /*set the use of last bars equity for trade size*/
PositionScore = 100/C; /*Set the order for which stock trades when get mulitple signals in one bar in backtesting */

/* End */



periodsRSI = Param( "Periods", 15, 1, 200, 1 );
BuyRSI = 40;
SellRSI = 60;

Buy = IsTrue(RSI(periodsRSI) < BuyRsi) ;
Sell = IsTrue(RSI(periodsRSI) > SellRSI) ;


/* Now for exploration results.
   Will restrict results of exploration to when the Buy AND Sell signals occur
   You can use Filter=1; to display every bar result */

Filter = Buy OR Sell;
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
//AddColumn( LastHigh, "HHV", 1.3 );
//AddColumn( LongMA, "Long MA", 1,3 );
//AddColumn( ShortMA, "Short MA", 1,3 );

/* End */








On Mon, Aug 3, 2009 at 7:17 PM, malcolm Crouch <malcolm.croucher@xxxxxxxxx> wrote:
This code is something i have put together . it is not a masterpiece but it works for testing 4 factors , I am still to add volume which is the fifth   . I am still new at this so please be aware

The top section allows for easy editing of the parameters although i have found you can also try parameters in the report section.

have a look and let me know what you think .... This is based on a technical analysis course i did a few weeks ago . I am not 100% certain about the Stochastics part. I have tested it on the South African JSE , some of it works , some doesnt . but it might be different for your exchanges ...   


_SECTION_BEGIN("5 Factors");
//MACD


PeriodFastMACD = Param( "Fast EMA", 5.26, 2, 200, 1 );
PeriodSlowMACD = Param( "Slow EMA", 12.26, 200, 1 );
PeriodSignalMACD = Param( "Signal EMA",10, 2, 200, 1 );
//STOCH
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
periodsStoch = Param( "Periods", 12, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
//RSI
periodsRSI = Param( "Periods", 15, 1, 200, 1 );
BuyRSI = 50;
SellRSI = 45;

//Momentum
PeriodsMom = Param("Period", 25, 1, 100 );
SellMom = 0;
BuyMom = 10;

/* Basics */
SetBarsRequired(10000,10000); /* this ensures that the charts include all bars AND NOT just those on screen */
SetFormulaName("Sample System"); /*name it for backtest report identification */
SetTradeDelays( 1, 1, 1, 1 ); /* delay entry/exit by one bar */
SetOption( "initialequity", 100000 ); /* starting capital */
PositionSize = -10; /* trade size will be 10% of available equty */
SetOption( "MaxOpenPositions", 6 ); /* I don't want to comit more than 60% of Equity at any one time */
SetOption( "PriceBoundChecking", 1 ); /* trade only within the chart bar's price range */
SetOption( "CommissionMode", 2 ); /* set commissions AND costs as $ per trade */
SetOption( "CommissionAmount", 32.95 ); /* commissions AND cost */
SetOption( "UsePrevBarEquityForPosSizing", 1 ); /*set the use of last bars equity for trade size*/
PositionScore = 100/C; /*Set the order for which stock trades when get mulitple signals in one bar in backtesting */

/* End */




/* Factor one MACD */


MACDInd = MACD(PeriodFastMacd, PeriodSlowMacd );
SigInd = Signal(PeriodFastMacd, PeriodSlowMacd , PeriodSignalMacd );
HistInd = MACDInd - SigInd ;



// Get displayed min and max value of MACD and MACD-H, to rescale it for better visibility
scMACDMax = LastValue(HHV(Max(MACDInd, sigInd),
                  BarsSince( Status("barvisible") AND NOT
Ref(Status("barvisible"),-1) )));
scMACDMin = LastValue(LLV(Min(MACDInd, sigInd),
                  BarsSince( Status("barvisible") AND NOT
Ref(Status("barvisible"),-1) )));
scaleMACD = Max( abs(scMACDMax), abs(scMACDMin) );

scHistMax = LastValue(HHV(HistInd,
            BarsSince( Status("barvisible") AND NOT
Ref(Status("barvisible"),-1) )));
scHistMin = LastValue(LLV(HistInd,
            BarsSince( Status("barvisible") AND NOT
Ref(Status("barvisible"),-1) )));
scaleHist = Max( abs(scHistMax), abs(scHistMin) );


Plot( HistInd, "", colorLightBlue, styleHistogram  | styleOwnScale | styleThick
,
      -scaleHist * 1.2, scaleHist * 1.2);
Plot( MACDInd, "", colorGreen);
Plot( SigInd , "", colorRed);

Plot( scaleMACD * 1.2,"",colorRed,styleNoDraw);
Plot( -scaleMACD* 1.2 ,"",colorRed,styleNoDraw);
GraphXSpace = 0;

/* Factor TWO RSI */



//IIf RSI( periods)




 

/* Factor Three  Stochastic */
 StochK( periodsStoch , Ksmooth);

 StochD( periodsStoch , Ksmooth, DSmooth );




/* Factor Four  Momentum */

function Momentum( array, period )
{
  return array - Ref( array, -period );
}
Field = ParamField( "Field" );

Momentum( Field ,PeriodsMom  );


/* Factor Five  Volume  */

/*Put it all togethe */


Buy = IsTrue(
                            Cross( MACDInd, SigIND )
                        AND  MACD( PeriodFastMacd, PeriodSlowMacd ) < -1200
                        AND  RSI(periodsRSI) < BuyRsi
                       
                    //    AND  Cross( StochK( periodsStoch , Ksmooth), StochD( periodsStoch , Ksmooth, DSmooth ) )
                    //    AND StochK ( periodsStoch , Ksmooth)<50
                    //    AND  Momentum( Field ,PeriodsMom  ) < BuyMom
                            );



Sell = IsTrue(
                            Cross( MACDInd, SigIND )
                        AND  MACD( PeriodFastMacd, PeriodSlowMAcd ) >1200
                        AND  RSI(periodsRsi) > SellRsi
                       
                    //    AND  Cross( StochK( periodsStoch , Ksmooth), StochD( periods , Ksmooth, DSmooth ) )
                    //    AND StochK ( periodsStoch , Ksmooth)<30
                    //    AND  Momentum( Field ,PeriodsMom  ) < SellMom
                            );




/* Now for exploration results.
   Will restrict results of exploration to when the Buy AND Sell signals occur
   You can use Filter=1; to display every bar result */

Filter = Buy OR Sell;
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
//AddColumn( LastHigh, "HHV", 1.3 );
//AddColumn( LongMA, "Long MA", 1,3 );
//AddColumn( ShortMA, "Short MA", 1,3 );

/* End */




_SECTION_END();





On Mon, Aug 3, 2009 at 5:15 PM, pstaffieri <pstaffieri@xxxxxxxxx> wrote:
 

Thanks Malcolm look forward to what you have.

--- In amibroker@xxxxxxxxxxxxxxx, malcolm Crouch <malcolm.croucher@xxx> wrote:
>
> From what I can see its pretty straightforward to code ....
>
> Stoch() > 75
> MACD() >0
>
> Gapping : not to sure how to do
>
> Sell = istrue( Volume >= x )
> (is it buy or sell volume )
>
> i will write the code for this later tonight and see if it work ... but i
> have a funny feeling its not going to wrok that well ....
>
> ive just tested a whole lot of strategies and none worked out as well as I
> hoped they would ..
>
> you possibly looking at 15% at the most
>
>
> Regards
>
>
> Malcolm
>
>
> On Mon, Aug 3, 2009 at 11:21 AM, Paolo Cavatore <pcavatore@xxx> wrote:
>
> >
> >
> > anything to drink?
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx <amibroker%40yahoogroups.com>,

> > "pstaffieri" <pstaffieri@> wrote:
> > >
> > > Require a system that is user friendly where I can load on a nightly
> > basis the following:
> > >
> > > 1. New stocks
> > > 2. Volume trigger for stocks
> > > 3. Remove stocks from list
> > >
> > > Also,
> > >
> > > 1. Buys if volume reaches a certain level by 11:30 am, Stochastics
> > (14,1,3) is 75 or over, MACD (5,13,6) is positive, stock has not gapped
> > up/down by over 5 percent.
> > >
> > > 2. Also, after a successful buy it will place a trainling stop of 2% and
> > sell at the end of the day if a certain specific volume is reached for that
> > stock.
> > >
> > > Must be also compatible with the paper trading account at IB.
> > >
> > > Thanks
> > >
> >
> >
> >
>
>
>
> --
> Malcolm A.B Croucher
>




--
Malcolm A.B Croucher



--
Malcolm A.B Croucher


__._,_.___


**** 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/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___