Articles & Videos & Calculators                 Product guide             Trading IQ Game with great prizes                  Support HomeSite Map - Testimonials


Beginners guide to Easy Language code. How to make indicators, functions, signals and strategies in Tradestaion or MultiCharts


Programming is a subject which can put fear into those who are trying to learn it. Some aspects of it can be complex.

Here is this guide I will make some simple to understand examples so you can learn what each part does.

More code examples can be found  in the << MEMBER FORUM >>


Beginners example no1 ( Price up and down counter demonstration only)



vars: move(0),summove(0);

If close > close [1] then move = 1;

if close < close [1] then move=-1;

if close = close [1] then move=0;

summove= summation(move,length);



Copy and paste the code above into your development environment in Tradestation or MultiCharts as Indicator. Then click on compile, or verify.

This code detects if the closing price today is greater than or less that the closing price of yesterday. ( This can be put on daily charts or minute charts and the close[1] refers to the previous bar or previous day)

If you typed close[2] it would refer to the close 2 days or bars ago instead.

Then we have the summation of the last ( length 20 ) bars.

To see how it works, you can change this line of code plot1(summove,"up-downcount"); to this plot1(move,"up-downcount");  Then click compile.

You can then see your indicator plots a line which is either 1, -1 or 0 

The inputs written at the top represent values that can be changed by the user when plotting the indicator on the chart. Once you plot the indicator in its original form you can change the length to 50 or 20 or 100 to see how it affects the plot.

Variables are shown here as "vars" and these are values I created to store the values outputted by the 3 lines of code starting if close ...and the summove variable.

Summove= summation( move,length); This means the variable summove is created from adding up the sum of the last 20 bars ( or length period ) bars with all the 1 and -1 and 0 values.

You can experiment by playing around with different values.


Beginners example no2 ( Adjustable weighting percent blended moving average)



variables: slow(0),fast(0),blended(0);

slow= average(close,length1);
fast= average(close,length2);


if value1<0 then value1=0;
if value1>1 then value1=1;

value2= 1-factor;

blended= (slow*value1)+(fast*value2);



You can read the above code first before creating this indicator and see if you can see what it is doing.

There are two moving averages used with slow length of 50 and a fast length of 20, the input called factor is adjustable to assign a weighting to each one.

If factor is set to 0.5 it will add 50% of the slow average to 50% of the fast average and create a blended average of the two period.

To see maximum values of the slow average set factor to 1, to see the plot constructed entirely of the faster average you can set factor to 0.

You can experiment with values like 0.1 and 0.9 to see the affects of adjustments to the weighting.

Code tips

  • If you use the name value1 or value2 or value 99 as variables, then you do not need to declare the names of these at the top part.

  • Value2= 1-factor is a very neat way to get 2 variables to automatically assign 1% of one part and 99% of the other part so when added they will always = 100%

  • Limit the user error by restricting inputs by making the variables read them. ( The code for value1 does this after reading the factor input )

Code tricks to try

  • If you look at the slow and fast variables you will see they both use averages (average is this code means simple average).

  • You can try making the slow one into a weighted average or an exponential average and mixing these up to make your own blended average combination.


Beginners example no3 ( Simple binary trend indicator )

{This example is for making a plot that goes into sub graph 2 and does not overlay over the price as the 2 above examples do.}

inputs: slow_length(80),fast_length(12);

variables: binary_trend(0);

if average(close,fast_length) > average(close,slow_length)

then begin binary_trend=1; end else binary_trend =-1;

{commenting code is done by using these squiggly brackets around text}




This indictor decides the "binary trend"  which means it converts it to a number. Thus uptrend =1 downtrend =-1 and the initial value is assigned as 0.

Code tips

  • If you plot the 80 period moving average and the 12 period moving average on the chart you can check the trend indicator is working.

  • Using end else statements to reduce code length. EG above assumes that if the trend is not 1 then it must be -1.

Code tricks to try

  • If you try using another method to assign the trend is up or down and replace the code with your idea. EG. You use the stochastic oscillator with above 50 being uptrend and below 50 being down trend.

  • The equal to 50 can be caught by saying this. If stochastic is >=50 then count as uptrend ( psuedo code)



Beginners example no4 ( Simple length adjusting algorithm )



variables: used_length(0),monitor(0);

if close = highest(close,basic_length) or
close = lowest(close,basic_length)


then begin monitor= monitor[1]-1; end else monitor=monitor[1]+0.5;

if monitor < min_length then monitor = min_length;
if monitor > max_length then monitor = max_length;


This is the first stage of making an algorithm to control length applied to an indicator.

You can see that if you plot this indicator in subgraph 2 it ranges between 50 and 10 which are the max and min lengths allowed. ( But these are adjustable inputs )

If the price is making a new high or low for the basic length period it will slow down by 1 length increment for each bar that the condition is true.

If the price not making a new high or low for the same period it will reduce length by 0.5 length increment for each bar the condition is true.

Code tricks to try

  • If you try changing the values of the -1 and the 0.5 to larger or smaller amounts you can tune it to suit your requirements.

  • Below I will show you how to build this code into a length changing indicator.


Beginners example no5 ( Simple length adjusting weighted moving average )



variables: used_length(0),monitor(0),l_changer(0);

if close = highest(close,basic_length) or
close = lowest(close,basic_length)

then begin monitor= monitor[1]-1; end else monitor=monitor[1]+0.5;

if monitor < min_length then monitor = min_length;
if monitor > max_length then monitor = max_length;





You can see that another variable has been added which is a weighted moving average and the trick here is to replace the usual field of length with the algorithm monitor which is adjusting the length applied.

Code tricks to try

  • If you plot a 20 period weighted average next to it on the subgraph one. You can see how the code above length changing average is slower at some period and faster in other periods.

  • The above indicator is place in subgraph no1 overlayed with the price. Example code no4 is placed in sub 2.

  • You can observe the length changing algorithm in action and see how it affects the speed of the weighted average.


Beginners example no6 ( How to prevent division by zero errors )


This example shows how to correct division by zero errors in Tradestation Easy language or MultiCharts

Division by zero is a frequent problem experienced in programming. The answer is always infinity, so we have to prevent anything getting divided by zero in the first place.

There are two methods of doing this.

Method 1

If value1 = 0 then value1=value1+0.0000000001;

So we simply add a tiny number to it, which is so tiny it will not make too much difference to the outputs.

Method 2

If value1 <> 0 then value2 = value3 / value1

This forces the computer to ask if the value1 is 0 or not before doing its calculations. If it is 0 it will return the default value that was assigned to value1 in the variables when you created it.



Solving the problem of not having entry price function in Tradestation

A useful function for Tradestation programmers.

User of Tradestation's programming environment may have experienced difficulties with multiple entry price models as the built in function ENTRYPRICE(NUMBER) only refers to the entry price of a new "overall position" rather than an entry of sequence of trades which go to make up an overall position.

The software does not have a function to call the 2nd or 3rd or greater entry prices in a position where several trades are placed.
While developing a Martingale model I ended up creating a special function to do just that so it was easier to call from.

The function is called "LastEntryPrice" and will always call the most recent entryprice regardless of how many entries are employed.

So if you need a triple entry model to work you can use the regular "ENTRYPRICE" function to call the first trade and then the LASTENTRYPRICE function to call the next ones.

Sample code below

//First exit

IF currentcontracts= first_size and marketposition=-1
THEN BUYTOCOVER ("1st exit short") next bar on highest(high,5) stop;

//Second exit

IF currentcontracts= first_size+Second_Size
and marketposition=-1 and LASTENTRYPRICE-CLOSE > 25

This product will be available upon request on the Tradestation app store if anyone asks me for it.

Some of my other products are now listed there for sale, copy and paste the link below into your browser to see them

Beginners example no8 ( How to use Hilbert Transform )
Beginners example no8 ( Understanding Goertzel algorithm )


More examples of using Easy Language code to create functions, indicators and signals that call from other functions


More code example can be found  in the member forum


Precision Trading Systems is provider of the following



 Precision Trading Systems is partnered  with MultiCharts.


 Precision Trading Systems is part of the NinjaTrader ecosystem.


 Systems and Indicators for Tradestation, NinjaTrader and MultiCharts.


 Top quality paid & FREE trading systems and indicators for most platforms


 Members can receive some paid products completely FREE


 Roger Medcalf is a vendor on the Tradestation App store


 Roger Medcalf is a vendor of products of MetaTrader 4



  Free to play Trading IQ Game with generous PRIZES  from our sponsors.


  Member log in



FREE and paid Systems and Indicators for Tradestation MultiCharts, MetaTrader4  and NinjaTrader, detailed articles on trading systems, trend following, risk control analytics, optimization, optimal trade size formulas, online calculators, FREE to play Trading IQ Game with massive prizes from our two sponsors NinjaTrader and MultiCharts, tutorial videos, expert trader videos, no nonense content that does exactly as it is described...Time is running out... Credit availability is drying up....US National debt to be equal to 35% of the entire worlds GDP in 3 years....33% of all USA tax revenues will be required just to make the INTEREST PAYMENTS on the collosal national debt...... Eventually the US will have no option other than to print money or default on their debt repayments...... US Dollars will likely cease to be the reserve currency of the world........Stimulus is running out, the Federal reserve has fired all its bullets and the only options left are to print more money or to default on the debt payments.....The problem is infinitely worse than in 1929 due to the added problem of this huge government debt...... In 1929 the USA still had a positive trade surplus and a manufacturing based economy..... In 2011 the USA will have no such resources to fall back on........The two most likely scenarios are both likely to lead to disaster......Hyper-Inflation at 40%+ or Deflationary implosion....... Either of the two possibilities will lead to huge moves in the worlds financial markets........Trading of these massive moves could be the only way out..........Wise proffessional traders have already started building huge dollar short posistions in anticipation of the debacles to come.....Many people will suffer as a result of the irresponsible un-elected Federal reserve operatives..........Many more people will lose their homes......Millions of jobs will be lost......Those who are unprepared will become impoverished in ways that they could never imagine.....What is your strategy to trade these violent market trends?.........ARE YOU  READY?

Precision Trading Systems is partnered with MultiCharts and part of the NinjaTrader Ecosystem

  • Products are provided for both these platforms.
  • Our partners also sponsor the Trading IQ Game
  • Both these trading platforms are excellent




  • Futures, Forex and Stock trading contain substantial risk and are not for every investor.

  • An investor could potentially lose all or more of the initial investment.

  • Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle.

  • Only risk capital should be used for trading

  • Only those with sufficient risk capital should consider trading.

  • Past performance is not necessarily indicative of future results.





Hypothetical performance results have many inherent limitations, some of which are described below. no representation is being made that any account will or is likely to achieve profits or losses similar to those shown; in fact, there are frequently sharp differences between hypothetical performance results and the actual results subsequently achieved by any particular trading program. One of the limitations of hypothetical performance results is that they are generally prepared with the benefit of hindsight. In addition, hypothetical trading does not involve financial risk, and no hypothetical trading record can completely account for the impact of financial risk of actual trading. for example, the ability to withstand losses or to adhere to a particular trading program in spite of trading losses are material points which can also adversely affect actual trading results. There are numerous other factors related to the markets in general or to the implementation of any specific trading program which cannot be fully accounted for in the preparation of hypothetical performance results and all which can adversely affect trading results.