| Coding Forum Collaborate, receive help, or discuss coding related issues. |
![]() | | Tweet | |
| | #1 | ||
![]() | Loops (EasyLanguage) For Used in combination with To or DownTo to form a loop statement that will execute a set of instructions repeatedly until the loop count reaches the specified final value. The loop statement specifies a numerical variable that holds the loop count, as well as initial and final counter values. To specifies that the value of the counter variable is to be increased by one on the completion of each loop, while DownTo specifies that the value of the counter variable is to be decreased by one on the completion of each loop. The use of Begin and End statements is required to group the instructions for execution within the loop; a Begin must always be followed by an End. Begin should not be followed by a semicolon (;), code lines within an instruction group should end with a semicolon (;), and End should be followed by a semicolon (;). Usage For Counter = IValue To FValue Begin Instruction1; Instruction2; End; or: For Counter = IValue DownTo FValue Begin Instruction1; Instruction2; End; Where: Counter - a numerical variable used store the loop count IValue - a numerical expression specifying the initial counter value FValue - a numerical expression specifying the final counter value Example Add the high prices of the last 10 bars to the HighPriceSum variable: Code: For BarBackNo = 0 To 9 Begin HighPriceSum = HighPriceSum + High[BarBackNo]; End; Add the high prices of the last 10 bars to the HighPriceSum variable: Code: For BarBackNo = 9 DownTo 0 Begin HighPriceSum = HighPriceSum + High[BarBackNo]; End; source: EasyLanguage manual
__________________ Only an idiot would reply to a stupid post | ||
| |
|
| The Following 3 Users Say Thank You to Tams For This Useful Post: | ||
| | #2 | ||
![]() | re: Loops (EasyLanguage) https://www.tradestation.com/support...ops_and_Arrays | ||
| |
|
| The Following 2 Users Say Thank You to Frank For This Useful Post: | ||
Tams (10-31-2009), TIKITRADER (11-01-2009) | ||
| | #3 | ||
![]() | re: Loops (EasyLanguage) this loop will keep running untill the condition is valid, make sure that will happen otherwhise we are in a infinite loop Code: index = 0;
While
ArrayToSearch[index] < Highest_A( ArrayToSearch, Array_Size ){condition}
Begin
index = index + 1;{instruction to repeat untill condition is true}
End;
IndexOfHighestArray = index; | ||
| |
|
| The Following User Says Thank You to flyingdutchmen For This Useful Post: | ||
Tams (10-31-2009) | ||
| | #4 | ||
![]() | re: Loops (EasyLanguage) if one is trying to aply value(s) to a certain variable make sure to reset the variable to "0" or whatever initial value you would like to use before the beginning of the loop. if you do not do this it will take the old value of the former candle calculated from last loop and it will use that value to apply next value's resulting in wrong calculations it does not matter if you use a "for", "while" or "repeat / untill"-loop in this example you will recieve a correct value only on the first bar as the variable does not reset before the calculation.on the next bar it will take that old value for its new calculation. the reason you will recieve a correct value on the first bar/loop is simply because the variable has been declared as "0" which gives it an initial first bar value of "0" ( Variables: HighPriceSum(0); ) untill this value will be changed, this is emediatly after the first calculation. Code: For BarBackNo = 0 To 9 Begin HighPriceSum = HighPriceSum + High[BarBackNo]; End; Code: HighPriceSum = 0; For BarBackNo = 0 To 9 Begin HighPriceSum = HighPriceSum + High[BarBackNo]; End; Last edited by flyingdutchmen; 10-31-2009 at 07:11 PM. | ||
| |
|
| The Following 3 Users Say Thank You to flyingdutchmen For This Useful Post: | ||
| | #5 | ||||
![]() | Re: Loops (EasyLanguage) Reserved word used to transfer control to an associated Case or Default statement. Syntax Code: Switch ( expression ) Begin Case case-expression: statements; Default: statements; End; The switch statement can include any number of case instances, but no two case constants within the same switch statement can have the same constant value. Note Once the statements associated with a matching case are evaluated, control passes to the end of the switch statement. This is an implied break and is different than a similar structure found in some other languages that require an explicit break. Remarks A single case statement can carry multiple values, as the following example shows: Quote:
Quote:
if case-expression equals any number between 1 and 6 or equal to 20, a function is called and assigned to a value. In addition, logical operators may be used with case statements including: >, <, >=, <=, <> and =. Quote:
Quote:
Example Code: Switch(Value1)
Begin
Case 1 to 5:
Value2 = Value2 + 1;
Case 10, 20, 30:
Value3 = Highest(High,10);
Case is > 40:
Value3 = Value3 + 1;
Default:
Value5 = Value5 + 1;
End; The above switch statement Increments Value2 when the switch expression (Value1) is a value from 1 to 5; assigns Value3 to the highest high of 10 bars ago when the switch expression is either 10, 20 or 30; increments Value4 for all switch expression values above 40; and increments Value5 for any other values of the switch expression. source: EasyLanguage manual
__________________ Only an idiot would reply to a stupid post Last edited by Tams; 11-03-2009 at 03:35 PM. | ||||
| |
|
| The Following 4 Users Say Thank You to Tams For This Useful Post: | ||
| | #6 | ||
![]() | Re: Loops (EasyLanguage) Used in combination with Begin and End to form a conditional loop statement that will execute a set of instructions repeatedly as long as a logical expression is true. If the logical expression is not true, the instructions will not be executed. Begin and End statements are used to group instructions for conditional execution; a Begin must always be followed by an End. Begin should not be followed by a semicolon (;), code lines within an instruction group should end with a semicolon (;), and End should be followed by a semicolon (;). Usage Code: While Condition1 = True
Begin
Instruction1;
Instruction2;
Instruction3;
End; Condition1 - a true/false expression InstructionX - conditional instructions Example Add the high prices of the last 10 bars to the HighPriceSum variable: Code: BarBackNo = 0;
While BarBackNo < 10
Begin
HighPriceSum = HighPriceSum + High[ BarBackNo ];
BarBackNo = BarBackNo + 1;
End; Source: EasyLanguage manual
__________________ Only an idiot would reply to a stupid post | ||
| |
|
| The Following User Says Thank You to Tams For This Useful Post: | ||
TIKITRADER (11-04-2009) | ||
| | #7 | ||
![]() | Re: Loops (EasyLanguage) it will keep running like Tam's loop untill the "Until" condition is met. This Loop is not yet supported in the old 2000i version but i believe it is supported in the newer versions of TradeStations and most likely in MC. it will produce the exact same outcome as the loop in the last post with the exeption that there is no need for "Begin" or "End" regardless of how many statements one would place between and this one is likely a bit easyer to understand for "LoopStarters" Code: HighPriceSum = 0;
BarBackNo = -1;
Repeat
BarBackNo = BarBackNo + 1;
HighPriceSum = HighPriceSum + High[ BarBackNo ];
Until BarBackNo = 9; Last edited by flyingdutchmen; 11-04-2009 at 02:50 PM. | ||
| |
|
| The Following 2 Users Say Thank You to flyingdutchmen For This Useful Post: | ||
Tams (11-04-2009), TIKITRADER (11-04-2009) | ||
| | #8 | ||
![]() | Re: Loops (EasyLanguage) Often there is a way to do things without using them at all.e.g. using the original example. HighPriceSum = HighPriceSum + High - High[9]; Will return the same value though it should be noted that this is 'unstable' for the first 9 bars on the chart (mind you so is the other looping code). Both tradestation and Multicharts do a pretty decent job of detecting how many bars are needed before an indicator 'works' and so there is no need to worry about this (unless you are a purist). | ||
| |
|
| The Following User Says Thank You to BlowFish For This Useful Post: | ||
Tams (11-09-2009) | ||
![]() |
| Tags |
| loop |
| Thread Tools | |
| Display Modes | Help Others By Rating This Thread |
| |
| ∧ Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Buy at Open with Easylanguage | cleon | Coding Forum | 5 | 03-02-2011 11:16 AM |
| Alert (EasyLanguage) | Tams | Coding Forum | 0 | 10-27-2009 12:47 PM |
| Easylanguage Error #408 and #410?? | isisisis | Coding Forum | 2 | 04-10-2009 06:30 PM |
| Looking For Coder That Knows MQL & EasyLanguage | CafeTrader | Coding Forum | 3 | 03-18-2009 07:05 PM |
| Some EasyLanguage Help Please | jjthetrader | Coding Forum | 8 | 06-02-2008 04:20 PM |