NexusFi: Find Your Edge


Home Menu

 





Trading Systems Code in Pruitt Trading Strategies


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Shaban with 3 posts (1 thanks)
    2. looks_two bacou with 2 posts (2 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 RichardV2 with 1 posts (0 thanks)
    1. trending_up 2,548 views
    2. thumb_up 3 thanks given
    3. group 8 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

Trading Systems Code in Pruitt Trading Strategies

  #1 (permalink)
RichardV2
San Diego California
 
Posts: 3 since Dec 2019
Thanks Given: 0
Thanks Received: 4

Experienced programmer, new to TradeStation/EasyLanguage has questions:

I just entered the code for four of the trading systems in the Pruitt text. Here are my results:

King Keltner, page 129: Code compiles when added to charts, I get no response or visible output.

Bollinger Bandit, page 133: Works and I love it!! This is the a really great example of the kind of systems I'd like to write.

Thermostat Program, page 138: My compile error is:
cmiVal = ChoppyMarketIndex(30);
Unknown Identifier
I think I know what's going on, but not how to fix it. I am guessing that the capital C in Choppy tells me that this an internal function inside EL, and that all I have to do is call it. My reasoning is that all user defined functions in the text start with a lower case letter and since this function appears nowhere else in the code, it must be inside the EL code library and I just don't know how to call it properly.

Dynamic Breakout II, page 143: Same as Kink Keltner above. Compiles but no visible output.

I'll continue looking for systems source code so I can speed up my learning curve for EasyLanguage.
My goal for my first two systems programs are:
1. Scan for all stocks that have been in a tight trading range for ten days or more.
2. Write a strategy that draws two boundaries above and below the trading range (using points or percents) and that alerts for a Buy or Sell when either boundary is crossed.


My questions:
1. Any solutions or hints to the problems above?
2. Can you provide any sources for systems programs that I can code, run and learn from?

Since the Bollinger Bandit worked, here is the EasyLanguage source code for those that don't have the text:

 
Code
// Bollinger Bandit
// Code from page 133 of Building Winning Trading Systems... Pruitt

Inputs: bollingerLengths(50), liqLength(50), rocCalcLength(30);

Vars: upBand(0), dnBand(0), liqDays(50), rocCalc(0);

upBand = BollingerBand(Close, bollingerLengths, 1.25);
dnBand = BollingerBand(Close, bollingerLengths, -1.25);
rocCalc = Close - Close [rocCalcLength - 1];
if(MarketPosition <> 1 and rocCalc > 0) Then
	Buy("BanditBuy") tomorrow upBand stop;
if(Marketposition <> -1 and rocCalc < 0) Then
	SellShort("BanditSell") tomorrow dnBand stop;
if(Marketposition = 0) then liqDays = liqLength;
if(Marketposition <> 0) Then
begin
	liqDays = liqDays - 1;
	liqDays = MaxList(liqDays, 10);
end;

if(Marketposition = 1 and Average(Close, liqDays) < upBand) Then
	Sell ("Long Liq") tomorrow Average(Close, liqDays) stop;
if(Marketposition = -1 and Average(Close, liqDays) > dnBand) Then
	BuyToCover("Short Liq") tomorrow Average(Close, liqDays) stop;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Better Renko Gaps
The Elite Circle
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #3 (permalink)
Shaban
Turin + Italy
 
Posts: 194 since Feb 2020
Thanks Given: 24
Thanks Received: 129


Hi,

A few years ago, a friend of mine told me that to get the signals of the Trading System: Dynamic Breakout II, in the window: Format Analysis Techniques & Strategies (Properties for All label), you have to write: 1500 in the voice:
Maximum number of bars study will reference and then OK.

For the Trading System Thermostat, I found in my archive, the function: ChoppyIndex, which could be similar to the function: ChoppyMarketIndex;
you can try it, of course you'll have to give it the name: ChoppyMarketIndex(30)

This is the Function: ChoppyIndex:

If HighestBar(TrueHigh,30) <= LowestBar(TrueLow,30)
then ChoppyIndex = 10*(Highest(TrueHigh,30)-Lowest(TrueLow,30))
else ChoppyIndex = - 10*(Highest(TrueHigh,30)-Lowest(TrueLow,30));

Reply With Quote
Thanked by:
  #4 (permalink)
bacou
St. Louis, MO
 
Posts: 2 since Mar 2020
Thanks Given: 1
Thanks Received: 1

Choppy Market Index is a function that you create in chapter 4. Make sure the name you give it when creating in chapter 4 is what you update the code to. In mine below you will see I named in $PruittChoppyMarketIndex. Same as Shaban's before, but this is pasted directly from the book.

 
Code
{Choppy Market Index FunctionThis function returns a value from 0 to 100. 
A lower value denotes higher market indecisiveness (choppiness), 
whereas a higher value denotes a trending market. 
The only input is the number of bars that we look back.}

Inputs: periodLength(NumericSimple);

Vars:
	num(0),
	denom(1);
		
If 
	(periodLength <> 0)
Then
	Begin
		denom = Highest(high,periodLength) - Lowest(low,periodLength);
		num = close[periodLength-1] - close;
		num = Absvalue(num);
		$PruittChoppyMarketIndex = 0.0;
		
		If	
			(denom <> 0)
			Then
			$PruittChoppyMarketIndex = num/denom*100;
	end;

Reply With Quote
Thanked by:
  #5 (permalink)
Shaban
Turin + Italy
 
Posts: 194 since Feb 2020
Thanks Given: 24
Thanks Received: 129

I've tried the T.S. King Keltner and it doesn't give any signal, even setting: Maximum number of bars study will reference: at 1500 and also at 2000;
if anyone has any suggestions for solving this little problem....

This is the code:

{King Keltner}

Inputs: avgLength(40), atrLength(40);
Vars: upBand(0),dnBand(0),liquidPoint(0),movAvgVal(0);

movAvgVal = Average((High + Low + Close),avgLength);
upBand = movAvgVal + AvgTrueRange(atrLength);
dnBand = movAvgVal - AvgTrueRange(atrLength);
if(movAvgVal > movAvgVal[1]) then Buy ("KKBuy") tomorrow at upBand stop;
if(movAvgVal < movAvgVal[1]) then Sell Short("KKSell") tomorrow at dnBand
stop;
liquidPoint = movAvgVal;

If(MarketPosition = 1) then Sell tomorrow at liquidPoint stop;
If(MarketPosition = -1) then Buy To Cover tomorrow at liquidPoint stop;

Reply With Quote
  #6 (permalink)
bacou
St. Louis, MO
 
Posts: 2 since Mar 2020
Thanks Given: 1
Thanks Received: 1

Shaban thanks for your note on the Dynamic Breakout, I just had to update my number of bars to reference.

For the King Keltner there was an error in the book. I think he posted the correction on his website if you google it. For the movAvgVal calculation it needs to be divded by 3 as below-



 
Code
{This program—based on a trading system presented by
Chester Keltner—is an example of a simple, robust and effective strategy.}
 
Inputs: 
	avgLength(40),
	atrLength(40),
	numATRs(1.0);
Vars: 
	upBand(0),
	dnBand(0),
	liquidPoint(0),
	movAvgVal(0);
 
movAvgVal = average((h+l+c)/3,avgLength);

upBand = movAvgVal + AvgTrueRange(atrLength);
dnBand = movAvgVal - AvgTrueRange(atrLength);

{Remember buy stops are above the market and sell stops are below the market
 -- if the market gaps above the buy stop, then the order turns into a market order
 vice versa for the sell stop}

if(movAvgVal > movAvgVal[1]) then Buy ("KKBuy") tomorrow at upBand stop;
if(movAvgVal < movAvgVal[1]) then SellShort("KKSell")tomorrow at dnBand stop;

liquidPoint = movAvgVal;
 
if(MarketPosition = 1) then Sell tomorrow at liquidPoint stop;
if(MarketPosition =-1) then BuyTocover tomorrow at liquidPoint stop;

Reply With Quote
  #7 (permalink)
Shaban
Turin + Italy
 
Posts: 194 since Feb 2020
Thanks Given: 24
Thanks Received: 129

Thank you bacou for correcting King Keltner's formula, in my haste I hadn't noticed.
P.S. What is the Input: numATRs(1.0) for?

Probably for T.S.: Dynamic Breakout II, maybe it depends on the version of Tradestation, e.g. for Tradestation 2000i you might need to set: Maximum number of bars study... to 1500, while I tried Tradestation 8.2, 100 is enough.

Reply With Quote




Last Updated on April 2, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts