Beginner's Guide to MultiCharts Programming: Difference between revisions
From MultiCharts
Beginner's Guide to MultiCharts Programming (view source)
Revision as of 09:50, 27 January 2012
, 27 January 2012no edit summary
(Created page with "This article highlights some PowerLanguage formatting tips, as discussed in a forum topic <ref>[http://www.multicharts.com/discussion/viewtopic.php?f=1&t=9792 MC Programing - ...") |
No edit summary |
||
Line 17: | Line 17: | ||
1 17/12/2011 Start | 1 17/12/2011 Start | ||
} | } | ||
</syntaxhighlight> | |||
=== Script Inputs === | |||
By including comments in the section of the script where the inputs and variables are defined the comprehension of the variables will be greater. | |||
An example of poor formatting would be the following. | |||
<syntaxhighlight> | |||
Inputs : High_MA_Len(10),Low_MA_Len(8),MedLen(8),PointSize(0.0001), StopLossSize(5), BreakEvenSize(7); | |||
</syntaxhighlight> | |||
A better formatting, both cleaner and easier to understand, would be: | |||
<syntaxhighlight> | |||
Inputs : | |||
High_MA_Len(10), Low_MA_Len(8), // Moving average lengths | |||
MedLen(8), // Median Look back Length | |||
PointSize(0.0001); // Actual Point size of the instrument | |||
</syntaxhighlight> | |||
==== Other Input formatting suggestions ==== | |||
* Start[[IntraBarPersist]] variables with a captial letter (e.g. ''MyDefinedVariable'') and start regular variables with a normal letter (e.g. ''myDefinedVariable''). This helps to keep track of which variables are regular and which ones are IntraBarPersist. | |||
== If else statements == | |||
When writing [[Comparisons_and_Loops|if else statements]] the use of '''tabs''' are highly recommend. | |||
Some examples of poor formatting would be: | |||
<syntaxhighlight> | |||
If UpTrend Then Begin | |||
Buy Next Bar Market; | |||
End | |||
Else Begin | |||
SellShort Next Bar Market; | |||
End; | |||
</syntaxhighlight> | |||
<syntaxhighlight> | |||
If UpTrend Then Buy Next Bar Market | |||
Else SellShort Next Bar Market; | |||
</syntaxhighlight> | |||
<syntaxhighlight> | |||
If UpTrend Then Buy Next Bar Market Else SellShort Next Bar Market; | |||
</syntaxhighlight> | |||
Better formatting would be: | |||
<syntaxhighlight> | |||
if (UpTrend = True) then begin | |||
Buy Next Bar Market; | |||
Initial_Stop = Low[1]; | |||
else begin | |||
SellShort Next Bar Market; | |||
Initial_Stop = High[1]; | |||
end; | |||
</syntaxhighlight> | |||
=== Closing of 'begin'... 'end' statements === | |||
A little tip for the closing of ''begin'' and ''end'' statements would be to include '//: ' after the end statement followed by a description of the if statement. This makes it relatively easy in debugging to see what the code block the 'end;' statement closes. | |||
For example: | |||
<syntaxhighlight> | |||
if (MarketPosition(0) = 0) then begin | |||
if (CurrentContracts < posSize) then begin | |||
if (enterLong = True) then | |||
Buy ("EL Limit") posSize contracts next bar at ELPrice limit; | |||
if (enterShort = True) then | |||
SellShort ("ES Limit") posSize contracts next bar at ESPrice limit; | |||
end; //: CurrentContracts < PosSize | |||
end; //: No MarketPosition Intrabar | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== References == | == References == | ||
<references /> | <references /> |