Today you will discover how to use the EasyLanguage Loop 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 called ShowMe that highlights 5 consecutive lower lows.
Vars: Signal (false); Signal = Low<Low and Low<Low and Low<Low and Low<Low and Low<Low; If Signal = True then Plot1(Low-Low*0.01);
This can be a very stressful code to create: Imagine using more candles than five.
We can write this code using a loop in EasyLanguage for TradeStation and MultiCharts. With a MultiCharts for loop, you can repeat certain designated actions infinite times.
The most common loop is the for-to loop. With 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 then it is complete.
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 MultiCharts for loop instruction.
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.
You can also use the loop in EasyLanguage 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.
More from Finance Strategy System