Changes

Jump to navigation Jump to search

Beginner's Guide to MultiCharts Programming

2,502 bytes added, 09:50, 27 January 2012
no edit summary
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>
== References ==
<references />

Navigation menu