Today you will discover how to use the loop in EasyLanguage for TradeStation and MultiCharts.

A loop is a code instruction that repeats a sequence until a specific condition is met.

It’s a fundamental programming idea that is commonly used in writing programs.

Suppose we have to create an indicator ShowMe that highlights 5 consecutive lower lows.

We can write this code:

Vars:
   Signal (false);

Signal = Low<Low[1] and Low[1]<Low[2] and Low[2]<Low[3] and Low[3]<Low[4] and Low[4]<Low[5];

If Signal = True then

Plot1(Low-Low*0.01);

This is a very stressful code, imagine if you need to use more candle then five.

We can write this code using a loop in EasyLanguage for TradeStation and MultiCharts. With the loop, you can repeat infinite times certain actions.

The most common loop is the for-to loop. Whit this loop you can execute code repeatedly until the loop count reaches a certain value.

The program increases the loop by one at the end of each cycle.

We set the starting and the ending value of the loop and that’s all.

Variables:
   count(0);

for counter = 0 to 5 begin

Print(“Value of ‘count’: “, count);

end;

//> Value of ‘count’: 0.00
//> Value of ‘count’: 1.00
//> Value of ‘count’: 2.00
//> Value of ‘count’: 3.00
//> Value of ‘count’: 4.00
//> Value of ‘count’: 5.00

Now we can modify our Show Me Lower Lows indicator with this loop instruction.

This is the code with loop in EasyLanguage for TradeSTation and MultiCharts

Inputs:
   LookBack(5);

Vars:
   x(0),
   Signal (false);

Signal = True;

For x=0 to LookBack-1
Begin

Signal = Signal=True and Low[x] < Low[x+1];

End;

If Signal = True then

Plot1(Low-Low*0.01);

This is the TradeStation or MultiCharts charts with our Show Me indicator.

Loop-EasyLanguage-PowerLanguage-for-TradeStation-MultiCharts

You can use the loop in EasyLanguage also to compare many values and find the higher or the lower.

myValue = -999 ;

for x = 0 to 200 
begin
if High[x] > myValue then
myValue = High[x] ;
end ;

To learn how to build an indicator in EasyLanguage and PowerLanguage for Tradestation or Multicharts, start here.

Resources:

WIKIPEDIA