Category Archives: Complete EasyLanguage Systems

Original Camarilla EasyLanguage Code [Correction]

Camarilla – A group of confidential, often scheming advisers; a cabal.

An attentive reader of this blog, Walter Baker,  found some typos in my code.  I have corrected them in the code section – if you have used this code make sure you copy and paste the code in its entirety into your EasyLanguage editor and replace your prior version.

I wanted to elaborate on the original version of Camarilla.  The one that users have been downloading from this website is pure reversion version.  The Camarilla Equation was by created by Nick Scott, a bond day trader, in 1989.  The equation uses just yesterday’s price action to project eight support/resistance price levels onto today’s trading action.  These levels, or advisers, as the name of the equation suggests provides the necessary overlay to help predict turning points as well as break outs.  Going through many charts with the Camarilla indicator overlay it is surprising how many times the market does in fact turn at one of these eight price levels.  The equations that generate the support/resistance levels are mathematically simple:


Resistance #4 = Close + Range * 1.1 / 2;

Resistance #3 = Close + Range * 1.1/4;

Resistance #2 = Close + Range * 1.1/6;

Resistance #1 = Close + Range * 1.1/12;


Support #1 = Close – Range * 1.1/12;

Support #2 = Close – Range * 1.1/6;

Support #3 = Close – Range * 1.1/4;

Support #4 = Close – Range * 1.1/2;


The core theory behind the equation and levels is that prices have a tendency to revert to the mean.  Day trading the stock indices would be easy if price broke out and continued in that direction throughout the rest of the day.  We all know that “trend days” occur very infrequently on a day trade basis; most of the time the indices just chop around without any general direction.  This is where the Camarilla can be effective.  Take a look at the following chart [ ES 5-minute day session] where the indicator is overlaid. and how the strategy was able to take advantage of the market’s indecisiveness.  This particular example shows the counter-trend nature of the Camarilla.  The original Camarilla looked at where the market opened to make a trading decision.  The chart below is an adapted version of the one I send out when one registers on for the download.   I thought it would be a good idea to show the original that incorporates a break out along with the counter trend mechanism.  I will go over the code in the next post.  You can copy the code below and paste directly into you EasyLanguage editor.

Camarilla at its Best!
Carmarilla in Reversion Mode

Original Camarilla rules:

  • If market opens between R3 and R4 go with the break out of R4.  This is the long break out part of the strategy.
  • If market opens between R3 and S3 then counter trend trade at the R3 level.  In other words, sell short at R3.  If the market moves down, then buy S3.  As you can see this is the mean reversion portion of the strategy.
  • If market open between S3 and S4 go with the break out of S4 – the short break out method.
  • Stops are placed in the following manner:
    • If long from a R4 break-out, then place stop at R3.
    • If short from a S4 break-out, then place stop at S3.
    • If long from a R3 countertrend, then place stop at R4.
    • If short from a S3 countertrend, then place stop at S4.
  • Profit objectives can be placed at opposite resistance/support levels:
    • If short from a R3 countertrend, then take profits at S1, S2, or S3.
    • If long from a S3 countertrend, then take profits at R1, R2, or R3.

Profit objectives for all trades can be a dollar, percent of price of ATR multiple.

Example of Camarilla Break Out Trade from S4
Camarilla Break Out
inputs: endTradetime(1530);
vars:	R1(0),R2(0),R3(0),R4(0),S1(0),S2(0),S3(0),S4(0),pivotPoint(0),myAvg(0);
vars: buyTrig(0),sellTrig(0),waitBar(0),s3Pen(0),r3Pen(0),s4Pen(0),r4Pen(0),s2Pen(0),r2Pen(0);
vars: buysToday(0),sellsToday(0);
vars: s3_s4(0),s2_s3(0),s1_s2(0),s4_s5(0);
vars: r1_r2(0),r2_r3(0),r3_r4(0),r4_r5(0);
vars: r1_s1(0),r3_s3(0),r4_s4(0),r5_s5(0);

if date <> date[1] then
	buyTrig = 0;
	sellTrig = 0;
	waitBar = 0;
	s3Pen = 0;
	r3Pen = 0;
	s4Pen = 0;
	r4Pen = 0;
	s2Pen = 0;
	r2Pen = 0;
	buysToday = 0;
	sellsToday = 0;
	r4_r5 = 0;
	r3_r4 = 0;
	r2_r3 = 0;
	r1_r2 = 0;
	r1_s1 = 0;
	r3_s3 = 0;
	r4_s4 = 0;
	r5_s5 = 0;
	s1_s2 = 0;
	s2_s3 = 0;
	s3_s4 = 0;
	s4_s5 = 0;


waitBar = waitBar + 1;

R4 = CloseD(1)+(HighD(1)-LowD(1)) * 1.1 / 2;
R3 = CloseD(1)+(HighD(1)-LowD(1)) * 1.1/4;
R2 = CloseD(1)+(HighD(1)-LowD(1)) * 1.1/6;
R1 = CloseD(1)+(HighD(1)-LowD(1)) * 1.1/12;
S1 = CloseD(1)-(HighD(1)-LowD(1)) * 1.1/12;
S2 = CloseD(1)-(HighD(1)-LowD(1)) * 1.1/6;
S3 = CloseD(1)-(HighD(1)-LowD(1)) * 1.1/4;
S4 = CloseD(1)-(HighD(1)-LowD(1)) * 1.1/2;

if openD(0)<= s4 then s4_s5 = 1;

If openD(0)> s4 and openD(0) <= s3 then s3_s4 = 1;
If openD(0)> s3 and openD(0) <= s2 then s2_s3 = 1;
If openD(0)> s2 and openD(0) <= s1 then s1_s2 = 1;

If openD(0)> s1 and openD(0) <= r1 then r1_s1 = 1;

If openD(0)> r1 and openD(0) <= r2 then r1_r2 = 1;
If openD(0)> r2 and openD(0) <= r3 then r2_r3 = 1;
If openD(0)> r3 and openD(0) <= r4 then r3_r4 = 1;

If openD(0)> r4 then r4_r5 = 1;

if openD(0) < r3 and openD(0) > s3 then r3_s3 = 1;
If openD(0) < r4 and openD(0) > s4 then r4_s4 = 1;

if time < endTradeTime and time > 930 then
	if r3_r4 = 1 and entriesToday(date) < 3 and  c < r4 then buy("R4-BrkOut") next bar at r4 stop;
	if s3_s4 = 1 and entriesToday(date) < 3 and  c > s4 then sellShort("S4-BrkOut") next bar at s4 stop;
	if c > r2 then r2Pen = 1;
	if c > r3 then r3Pen = 1;
	if c > r4 then r4Pen = 1;
	if r3_s3 = 1 and r3Pen = 1 and c > r3 and entriesToday(date) < 3 
		 then sellShort("R3Sell") next bar at r3 stop;
	if r4Pen = 1 and c < r4 then r4Pen = 0;	
	if r3Pen = 1 and c < r3 then r3Pen = 0;	
	if r2Pen = 1 and c < r2 then r2Pen = 0;

	if c < r1 then 
		r2Pen = 0;
		r3Pen = 0;
		r4Pen = 0;
	if c > s1 then
		s2Pen = 0;
		s3Pen = 0;
		s4Pen = 0;

	if c < s2 then s2Pen = 1;
	if c < s3 then s3Pen = 1;
	if c < s4 then s4Pen = 1;

	if r3_s3 = 1 and s3Pen = 1 and c < s3 and entriesToday(date) < 3 then 
		buy("S3Buy") next bar at s3 stop;
	if s4Pen = 1 and c > s4 then s4Pen = 0;	
	if s3Pen = 1 and c > s3 then s3Pen = 0;
	if s2Pen = 1 and c > s2 then s2Pen = 0;
	if marketPosition = 1 then
		sell from entry("S3Buy") next bar at s4 stop;
		sell from entry("R4-BrkOut") next bar at r3 stop;
	if marketPosition = -1 then
		buyToCover from entry("R3Sell") next bar at r4 stop;
		buyToCover from entry("S4-BrkOut") next bar at s3 stop;

Camarilla Strategy EasyLanguage Source
Please follow and like us:

Day Of Week Analysis using a Method In EasyLanguage

One metric that seems to be missing from TradeStation is a Day Of Week analysis.  It would be nice, but I don’t know how helpful, to know the $P/L breakdown on a weekday basis; does your system make all of its money on Mondays and Fridays?  I created the code that will print out to the print log using an EasyLanguage method.  A method is a subroutine that can be included in the main code (strategy, indicator, etc.,.)  The global parameters to the main program can be seen inside the method.  You can localize variable scope to the method by declaring the variable within the method’s body.  A method is a great way to modularize your programming, but it is not the best way to reuse software; the method is accessible only to the main program.  This EasyLanguage also utilizes an array and shows a neat piece of code to access the array elements and align them with the day of the week.  The dayOfWeek() function returns [1..5] depending on what day of the week the trading day falls on.  Monday = 1 and Friday = 5.  The array has five elements and each element accumulates the $P/L for each of the five days based on when the trade was initiated.

vars: mp(0);
array: weekArray[5](0);

method void dayOfWeekAnalysis()   {method definition}
var: double tradeProfit;
	If mp = 1 and mp[1] = -1 then tradeProfit = (entryPrice(1) - entryPrice(0))*bigPointValue;
	If mp = -1 and mp[1] = 1 then tradeProfit = (entryPrice(0) - entryPrice(1))*bigPointValue;
	weekArray[dayOfWeek(entryDate(1))] = weekArray[dayOfWeek(entryDate(1))] + tradeProfit;
Buy next bar at highest(high,9)[1] stop;
Sellshort next bar at lowest(low,9)[1] stop;

mp = marketPosition;

if mp <> mp[1] then dayOfWeekAnalysis();

If lastBarOnChart then
	print("Monday ",weekArray[1]);
	print("Tuesday ",weekArray[2]);
	print("Wednesday ",weekArray[3]);
	print("Thursday ",weekArray[4]);
	print("Friday ",weekArray[5]);
Code using METHOD and ARRAY manipulation

Here is an example of the print out created by running this simple EasyLanguage strategy.  Maybe don’t trade on Monday?  Or is that curve fitting.  This is an interesting tool and might carry more weight if applied to day trade algorithm.  Maybe!

  • Monday -8612.50
  • Tuesday 6350.00
  • Wednesday 2612.50
  • Thursday -937.50
  • Friday -1987.50
Please follow and like us:

Using Strings in EL for multi-step System

This little strategy uses EasyLanguage’s string manipulation to keep track of a multi-step, mutli-criteria, multi-state trade entry. You don’t buy until the buyString is equal to “BUY”. The sell side is just the opposite. When you program a multi-step entry you also need to build a reset situation. In the case of this system you reset the string to null(“”) when the price dips back down below the 9 day moving average. After resetting the process starts over again.

{Use curly brackets for mult-line
 This system needs three criteria to be met
 before a trade is initiated
 Buy Criteria 1:  C > 9 day movAvg - trend Up
 Buy Criteria 2:  H = HighestHigh 10 days - break Out
 Buy Criteria 3:  C < C[2] - retracement }
 if marketPosition = 0 then {If flat then reset strings}
 	buyString = "";
 	sellString = "";
 if c >= average(c,9) then buyString = "B";  //First criteria met
 if c < average(c,9) then buyString = "";
 if c > average(c,9) then sellString = "";
 if c <= average(c,9) then sellString = "S"; 
 if buyString = "B" then
 	if h > highest(h,10)[1] then buyString = buyString + "U"; //Second Criteria met
 if buyString = "BU" then
 	if c < c[2] then buyString = buyString + "Y"; //Third criteria met
 if buyString = "BUY" then buy ("BuyString") next bar at open; //Read BUY
 if sellString = "S" then
 	if l > lowest(l,10)[1] then sellString = sellString + "E";
 if sellString = "SE" then
 	if c > c[2] then sellString = sellString + "LL";
 if sellSTring = "SELL" then sellShort ("sellString") next bar at open; 

 SetPercentTrailing(1000, 30);  

Please follow and like us: