EasyLanguage for Loop – MultiCharts and TradeStation

Today, you’ll learn how to use the EasyLanguage Loop for TradeStation and MultiCharts.

A loop is a code command that repeats a set of instructions until a certain condition is satisfied. It’s a fundamental programming concept that is frequently employed in code writing.

Let’s say we have to construct an indicator called ShowMe that highlights five consecutive lows.

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 might be a difficult code to write: Consider setting more candles than five. A loop in EasyLanguage for TradeStation and MultiCharts allows us to code this. You may repeat particular actions an infinite amount of times with a MultiCharts for loop.

The for-to loop is the most frequent loop. You may execute code repeatedly until the loop count reaches a certain value using this loop. At the end of each cycle, the program adds one to the loop.

The loop is complete when we set the starting and ending values of the loop.

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 have the ability to use this MultiCharts for loop instruction to change our Show Me Lower Lows indicator.

Multicharts for loop Tradestation EasyLanguage code

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 may use the loop in EasyLanguage to compare numerous values and identify the best or worst.

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.