Difference between revisions of "DownTo"

From MultiCharts
Jump to navigation Jump to search
Line 1: Line 1:
Used in combination with [[For]] to form a loop statement that will execute a set of instructions repeatedly until the loop count reaches the specified final value.  
+
Used in combination with [[For]] to form a loop statement that will execute a set of instructions repeatedly until the loop count reaches the specified final value.
[[DownTo]] specifies that the value of the counter variable is to be decreased by one on the completion of each loop.
+
 +
'''DownTo''' specifies that the value of the counter variable is to be decreased by one on the completion of each loop.
  
For more information see [[For.]]
+
== Usage ==
 
==== Usage ====
 
 
<syntaxhighlight>For Counter=IValue DownTo FValue Begin
 
<syntaxhighlight>For Counter=IValue DownTo FValue Begin
I1;
+
  I1;
I2;
+
  I2;
 
End;</syntaxhighlight>
 
End;</syntaxhighlight>
  
Where: [[Counter]] - a numerical variable used store the loop count
+
Where:  
  
[[IValue]] - a numerical expression specifying the initial counter value
+
:'''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.
  
[[FValue]] - a numerical expression specifying the final counter value 
+
== Notes ==
 +
* For more information see [[For]].
 +
* It's not needed to increment the counter variable yourself - that is done by PowerLanguage itself.
  
==== Example ====
+
== Example ==
Add the high prices of the last 10 bars to the [[HighPriceSum]] variable:
+
Add the high prices of the last 10 bars to the ''HighPriceSum'' variable:
  
 
<syntaxhighlight>For BarBackNo=9 DownTo 0 Begin
 
<syntaxhighlight>For BarBackNo=9 DownTo 0 Begin
HighPriceSum=HighPriceSum+High[BarBackNo];
+
 
 +
  HighPriceSum=HighPriceSum+High[BarBackNo];
 +
 
 
End;</syntaxhighlight>   
 
End;</syntaxhighlight>   
 +
 +
To print the closing values of the last 10 bars:
 +
 +
<syntaxhighlight>
 +
if (LastBarOnChart_s = True) then begin
 +
 +
for value1 = 9 DownTo 0 begin
 +
 +
Print("Close: ", Close[value1]);
 +
 +
end;
 +
 +
end;
 +
</syntaxhighlight>
 +
  
 
[[Category:Comparisons and Loops]]
 
[[Category:Comparisons and Loops]]

Revision as of 11:04, 19 February 2012

Used in combination with For to form a loop statement that will execute a set of instructions repeatedly until the loop count reaches the specified final value.

DownTo specifies that the value of the counter variable is to be decreased by one on the completion of each loop.

Usage

For Counter=IValue DownTo FValue Begin
  I1;
  I2;
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.

Notes

  • For more information see For.
  • It's not needed to increment the counter variable yourself - that is done by PowerLanguage itself.

Example

Add the high prices of the last 10 bars to the HighPriceSum variable:

For BarBackNo=9 DownTo 0 Begin

  HighPriceSum=HighPriceSum+High[BarBackNo];

End;

To print the closing values of the last 10 bars:

if (LastBarOnChart_s = True) then begin

	for value1 = 9 DownTo 0 begin
	
		Print("Close: ", Close[value1]);
	
	end;

end;