Easy Language Strategies MACD+RSI and a Parabolic SAR reversal

Blackey

Junior member
Messages
12
Likes
0
Hello All - I am currently working full time and trying to teach myself to trade. This is proving hard as there aren't enough hours in the day for studying!! When not in work I am studying for the markets, looking at training/trading videos or listening to audio training. I am getting close to starting to trade but want to develop a few strategies and backtest them. I learned a lot about technical analysis from 2 books, one is Technical Analysis of the Financial Markets by John J. Murphy and the other is Technical Analysis Explained by Martin J. Pring. Both were heavy but good! I have subscribed to TradeStation and gone through the online tutorials and read the reference materials on Easy Language and viewed the online tutorials also.

To get to the point, I would like someone to help me with the code for 2 strategies. The first is to generate a long entry when 3 conditions are met.

1. MACD has had crossover and is heading towards 0 or "north" again.
2. RSI indicates that the item is in oversold territory.
3. There is a Parabolic SAR buy confirmation.

The code I have so far for that one is:

PHP:
inputs:  	FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ; 
inputs:		Price( Close ), Length( 14 ), OverSold( 30 ) ; 
inputs:		AfStep( 0.02 ), AfLimit( 0.2 ) ; 
 
variables:  	MyMACD( 0 ), MACDAvg( 0 ), MACDDiff( 0 ) ; 
variables:		MyRSI( 0 ) ; 
 
variables:		oParCl( 0 ), oParOp( 0 ), oPosition( 0 ), oTransition( 0 ) ; 
 
MyRSI = RSI( Price, Length ) ; 
 
MyMACD = MACD( Close, FastLength, SlowLength ) ; 
MACDAvg = XAverage( MyMACD, MACDLength ) ; 
MACDDiff = MyMACD - MACDAvg ; 
 
 
 
if CurrentBar > 2 and MACDDiff crosses over 0 then { CB > 2 check used to 
 avoid spurious cross confirmation at CB = 2 (at CB = 1, MyMACD and MACDAvg will be 
 the same) } 
	{Buy ( "MacdLE" ) next bar at market ;} 
 
 
if Currentbar > 1 and MyRSI crosses over OverSold then 
  { CB > 1 check used to avoid spurious cross confirmation at CB = 1 } 
	{Buy ( "RsiLE" ) next bar at market ;} 
 
 
{ The IntrabarOrderGeneration attribute is set to false in this strategy because this  
strategy is intended to place an order on a given bar that is valid for the entire 
duration of the next bar.  It is not intended, in this strategy, for any of the order 
parameters to vary be recalculated intra-bar. } 
 
[IntrabarOrderGeneration = false] 
  
 
Value1 = ParabolicSAR( AfStep, AfLimit, oParCl, oParOp, oPosition, oTransition ) ; 
 
if oPosition = -1 then 
	Buy ( "ParLE" ) next bar at oParOp stop ;

Does anyone know how to add an exit condition into that? I have a couple I'd like to test but it's taking me ages to find code examples.

The secound strategy I'd like to create is one based on daily charts with Parabolic SAR. I'd like it to scan back at 21 days and generate a buy signal on the first long entry dot or a sell signal on the first short entry dot, i.e a long or short entry on the Parabolic reversal then a stop or sell signal on the next reversal. This strategy I would run on daily charts. I havent got as far with this one as I am having trouble with certain word entries and else statements. For the Parabolic SAR strategy exit I'd like to generate a sell signal upon the SAR reversal. Does anyone know the code I could use for that?

The code I have so far for that is just the very beginning:
PHP:
{ The IntrabarOrderGeneration attribute is set to false in this strategy because this 
strategy is intended to place an order on a given bar that is valid for the entire
duration of the next bar.  It is not intended, in this strategy, for any of the order
parameters to vary be recalculated intra-bar. }

[IntrabarOrderGeneration = false]
inputs:  AfStep( 0.02 ), AfLimit( 0.2 ) ;
variables:  oParCl( 0 ), oParOp( 0 ), oPosition( 0 ), oTransition( 0 ) ;

Value1 = ParabolicSAR( AfStep, AfLimit, oParCl, oParOp, oPosition, oTransition ) ;

if oPosition = -1 then
	Buy ( "ParLE" ) next bar at oParOp stop ;
	else
 	if oPosition = 1 then
	Sell Short ( "ParSE" ) next bar at oParOp stop ;
	end;

Any help at all would be greatly appreciated!!!!!


Thanks - Gavin.
 
I am no expert on EL but I am able to write most of the strategies that I need. However, I use TS2Ki which I don't think you are using looking at your code. What I would say is that I think you are complicating things with too many variables in your "If" statements.

I have found the best way to get around this is to have Condition statements so you may have something like:

Condition1 = Currentbar > 1 and MyRSI = OS;

You keep adding conditional statements that will make up your strategy and then when making your "If" statement it just becomes:

If Condition1 and Condition2 and Condition6 then ........etc

I have found this helps enormously with working out the logic and making sure that I have each small part correctly coded.

I hope this helps a bit


Paul



 
Hi Trader333 - Many thanks for your reply. That makes sense allright. I got my hands on a copy of "Building Trading Systems with TradeStation by Jack Schwager" so I'm going to get tucked into that and hopefully gain the ability to write proper code.

Again, thanks for the reply and enjoy the rest of your weekend.


Gavin.
 
Hi Paul - I read the first few chapters of that book and it basically said exactly what you told me to concentrate on, which was to have a structure and code in modules.

So I've got a little further with code for stop loss and trailing stops but my entries and exits aren't tight enough. I'll keep at it!! Would appreciate your views on it though?

PHP:
{Test code to generate a long entry based on 1st Para SAR signal on daily chart or short entry entry
based on 1st Para SAR signal for opposite movement. Will attempt money mgt and trailing stop also!}


inputs: AccFactorStep( 0.02 ), AccFactorLimit( 0.2 ),protStop$(500),
trailStopThresh$(500),trailStopPrcnt(25);

variables:  oParCl( 0 ), oParOp( 0 ), oPosition( 0 ), oTransition( 0 ) ;

Value1 = ParabolicSAR( AccFactorStep, AccFactorLimit, oParCl, oParOp, oPosition, oTransition ) ;


if oPosition = -1 
	then
	begin
	Buy ( "ParLE" ) next bar at oParOp stop ;
	end;

if oPosition = 1 
	then
	begin
	Sell Short ( "ParSE" ) next bar at oParOp stop ;


	SetStopLoss(protStop$);
SetPercentTrailing(trailStopThresh$,trailStopPrcnt);


end;


I'd like to tighten up the code to generate quicker entry and exit signals based on the first signal from the Parabolic SAR on a daily chart.

If you have any ideas I'd appreciate it!


Thanks - Gavin.
 
Gavin,

I will certainly help where I am able to but like I said I am not that expert in EL. Which platform are you writing for as it looks different to what is available to me in TS2Ki


Paul
 
Hi Paul - I read the first few chapters of that book and it basically said exactly what you told me to concentrate on, which was to have a structure and code in modules.

So I've got a little further with code for stop loss and trailing stops but my entries and exits aren't tight enough. I'll keep at it!! Would appreciate your views on it though?

PHP:
{Test code to generate a long entry based on 1st Para SAR signal on daily chart or short entry entry
based on 1st Para SAR signal for opposite movement. Will attempt money mgt and trailing stop also!}


inputs: AccFactorStep( 0.02 ), AccFactorLimit( 0.2 ),protStop$(500),
trailStopThresh$(500),trailStopPrcnt(25);

variables:  oParCl( 0 ), oParOp( 0 ), oPosition( 0 ), oTransition( 0 ) ;

Value1 = ParabolicSAR( AccFactorStep, AccFactorLimit, oParCl, oParOp, oPosition, oTransition ) ;


if oPosition = -1 
	then
	begin
	Buy ( "ParLE" ) next bar at oParOp stop ;
	end;

if oPosition = 1 
	then
	begin
	Sell Short ( "ParSE" ) next bar at oParOp stop ;


	SetStopLoss(protStop$);
SetPercentTrailing(trailStopThresh$,trailStopPrcnt);


end;


I'd like to tighten up the code to generate quicker entry and exit signals based on the first signal from the Parabolic SAR on a daily chart.

If you have any ideas I'd appreciate it!


Thanks - Gavin.

www.kreslik.com is a tradestation friendly trading community that might be useful for you.
 
Gavin,

I will certainly help where I am able to but like I said I am not that expert in EL. Which platform are you writing for as it looks different to what is available to me in TS2Ki


Paul
Hiya Paul - I'm running TS 8.3. It's cool if you're not too up on it, I still have the rest of the book to get through!! I'll get there in a while, just takes time when you have a full time job as well! Work gets in the way of a lot of things unfortunately.


Thanks - Gavin.
 
Top