Source Code

Below you will find source code for MultiCharts and PowerLanguage. Simply cut and paste  the below code into the PowerLanguage Editor and then compile.

In some instance you will need to declare / assign variables and or inputs to function properly.

Initial Script

The following code is a working example of a fully functional script.

Entry conditional statements both buy and sellshort statements have been omitted to allow you to input your own algorithm.

Please follow the below steps to import this signal.

Step 1: Click on the PLE icon on your desktop

Step 2: Select "file" then select "new"

Step 3: Enter a name

Step 4: Copy all of the below source code and paste into the PLE Editor.

Step 5: Click "compile"

To insert this newly compiled signal, go to "format" then "signal" then "add" in your MC Workspace.

// SECTION 1 Title - Security Settings
 
// SECTION 1 Purpose - This is where your script can include your credentials and an expiration date to protect from theft or other misuse.
 
	// File Name:
 
	// Revision Date:
 
	// Revision Number:
 
Variables:	// For SECTION 1 only
 
	UserName("replace with user name"),	
	var50("replace with userID");
 
	//IF GetUserName <> UserName OR GetUserID <> var50 OR DATE > 1181231	// Date format is YYYMMDD
 
		//Then 
 
			//RaiseRunTimeError("Unable to verify license information for this system");
 
	// The following line determines if IOG is on or off
 
		[IntraBarOrderGeneration=True] 	// Enables IOG mode. To turn on, remove comment hash marks and use IntraBarPersist in variable declarations below
 
	// The following line is used to force time based script calculations
 
		ReCalcLastBarAfter(5)		// Enables script calculations every (n) seconds. Initial value is 5. To turn on, remove comment hash marks
 
 
// SECTION 2 Title - Inputs and Variables
 
// SECTION 2 Purpose - This is where inputs and variables that are used throughout your script are introduced
 
	// Input Declarations
 
		// NOTES: When declaring inputs, an initial value is entred between ( )
 
Inputs:
 
	Price(Close),			// Last tick
	MA1 ( 5 ),			// Moving Average 1, initial value = 5 periods
	MA2 ( 10 ),			// Moving Average 2, initial value = 10 periods
	MA3 ( 15 ),			// Moving Average 3, initial value = 15 periods
	UpperBB ( 2),			// Upper bollinger band, initial value = 2 standard deviations
	LowerBB ( 2 ),		        // Lower Bollinger Band, initial value = 2 standard deviations
	MovAvgBB ( 20 ),		// Moving Average for Bollinger Band, initial value = 20 periods
	RSILength ( 14 ),		// RSI length, initial value = 14 periods
	MACDFast ( 16 ),		// MACD fast length, initial value = 16 periods
	MACDSlow ( 26 ),		// MACD slow length, initial value = 26 periods
	LongShares ( 100 ),		// Number of shares to buy long for equity, initial value is 100 shares
	ShortShares ( 100 ),		// Number of shares to sell short for equity, initial value is 100 shares
	LongContracts ( 0 ),		// Number of contracts to buy long for futures, initial value is 0 contract
	ShortContracts ( 0 ),	        // Number of contracts to sell short for futures, initial value is 0 contract
	LongLimit ( 5 ),		// Limit order value for long entry, initial value = 5 ticks
	ShortLimit ( 5 ),		// Limit order value for short entry, initial value = 5 ticks
	LongStop ( 10 ),		// Stop order value for long entry, initial value = 10 ticks
	ShortStop ( 10 );		// Stop order value for short entry, initial value = 10 ticks
 
Variable:	
 
	// Variable Declarations
 
		// NOTES: When declaring variables, the variable NAME, TYPE and VALUE is defined
 
		// NOTES: Variable types are numeric, Boolean (True or False) and text string
 
	TickSize ( MinMove / PriceScale ),	// Calculates size of one tick based on instrument traded				
	var1( 0 ),				// If using IOG = False then turn off				
	var2( 0 ),				// If using IOG = False then turn off				
	var3( 0 ),				// If using IOG = False then turn off				
	var4( 0 ),				// If using IOG = False then turn off				
	var5( 0 ),				// If using IOG = False then turn off				
	var6( 0 ),				// If using IOG = False then turn off				
	var7( 0 ),				// If using IOG = False then turn off				
	var8( 0 ),				// If using IOG = False then turn off				
	var9( 0 ),				// If using IOG = False then turn off				
	var10( 0 ),				// If using IOG = False then turn off
	var11( 0 ),				// If using IOG = False then turn off		
	var12( 0 ),				// If using IOG = False then turn off			
	var13( 0 ),				// If using IOG = False then turn off				
	var14( 0 );				// If using IOG = False then turn off
 
	//IntraBarPersist var1( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var2( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var3( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var4( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var5( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var6( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var7( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var8( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var9( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var10( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var11( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var12( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var13( 0 ),	// If using IOG = True then turn on
	//IntraBarPersist var14( 0 ),	// If using IOG = True then turn on
 
	// Variables Assignments
 
	var1 = AverageFC( Close, MA1 );			// Moving average based on input value of MA1
	var2 = AverageFC( Close, MA2 );			// Moving average based on input value of MA2
	var3 = AverageFC( Close, MA3 );			// Moving average based on input value of MA3
	var4 = StandardDev( Close, MovAvgBB, 1 );		// 1 standard deviation based on input value of MovAvgBB
	var5 = ( var4 * UpperBB );				// Upper Bollinger Band absent MA based on input value of UpperBB
	var6 = ( var4 * LowerBB );				// Lower Bollinger Band absent MA based on input value of LowerBB
	var7 = MovAvgBB + var5;				// Upper Bollinger Band based on input value of UpperBB
	var8 = MovAvgBB - var6;				// Upper Bollinger Band based on input value of UpperBB
	var9 = MACD( Close, MACDFast, MACDSlow );		// MACD based on input value of MACDFast and MACDSlow
	var10 = RSI( Close, RSILength );			// RSI based on input value of RSILength
 
	var11 = LongLimit * TickSize;			// Limit for long OCO orders based on input value of LongLimit
	var12 = ShortLimit * TickSize;			// Limit for short OCO orders based on input value of ShortLimit
	var13 = LongStop * TickSize;			// Stop for long OCO orders based on input value of LongStop
	var14 = ShortStop * TickSize;			// Stop for short OCO orders based on input value of ShortStop
 
// SECTION 3 Title - Global Conditionals
 
// SECTION 3 Purpose - This is where conditional statements that apply to the entire script are listed
 
	// GLOBAL CONDITIONAL #1 - Prevents trades on certain calendar dates
 
	IF	Date <> 1161231
 
		Then Begin
 
	// GLOBAL CONDITIONAL #2 - Prevent trades on certain days		
 
	IF	DayOfWeek(Date) = 1		
 
	//OR	DayOfWeek(Date) = 2
 
	//OR	DayOfWeek(Date) = 3
 
	//OR	DayOfWeek(Date) = 4
 
	//OR	DayOfWeek(Date) = 5
 
		Then Begin
 
	// GLOBAL CONDITIONAL #3 - Prevent trades on certain times
 
	IF	TIME > 0905 AND TIME < 1400
 
		Then Begin
 
// SECTION 4 Title - Position Entry Conditional Statements
 
// SECTION 4 Purpose - This is where conditional statements that generate buy or sell short orders are listed
 
	// Long Entry Conditional Statements
 
	IF	MarketPosition = 0 		// For live production change to Market_Position_At_Broker
 
		Then Begin
 
		IF	2 = 3			// Delete 2 = 3 and add long entry conditional statements here
 
		AND	1 = 2			// Delete 1 = 2 and add long entry conditional statements here
 
		Then Begin
 
			Buy  ( "Long Entry" ) LongContracts Contracts Next Bar At Market;
 
			Alert;
 
		End; 
 
	// Short Entry Conditional Statements
 
		IF	2 = 3
 
		AND	1 = 2
 
		Then Begin
 
			SellShort ( "Short Entry" ) ShortContracts Contracts Next Bar At Market;
 
			Alert;
 
		End;
 
End;	// Position Entry Conditional Statements
 
End;	// GLOBAL CONDITIONAL - #3: Prevents trades on cetain times
 
End;	// GLOBAL CONDITIONAL - #2: Prevents trades on certain days
 
End;	// GLOBAL CONDITIONAL - #1: Prevents trades on certain calendar dates
 
 
// SECTION 5 Title - Position Exit Conditional Statements
 
// SECTION 5 Purpose - This is where conditional statements to sell or buy to cover are listed
 
	// Long Exit Conditional Statements
 
	IF	MarketPosition > 0		// For live production change to Market_Position_At_Broker
 
		AND EntryPrice > 0
 
		Then Begin
 
			Sell ( "Long Exit Limit" ) Next Bar at ( EntryPrice + var11 ) Limit;
			Sell ( "Long Exit Stop" ) Next Bar at ( EntryPrice - var13 ) Stop;
 
		End;
 
	// Short Exit Conditional Statements
 
	IF	MarketPosition < 0		// For live production change to Market_Position_At_Broker
 
		AND EntryPrice > 0
 
		Then Begin
 
			BuyToCover ( "Short Exit Limit" ) Next Bar at var12 Limit;
			BuyToCover ( "Short Exit Stop" ) Next Bar at var14 Stop;
 
		End;
 
// Print Statements Entered Below
 
	Print();

Daily Circuit Breaker

The following code is designed to set a daily circuit breaker for each trading day. The script does not use input values but rather hard codes the levels on a per share / lot basis.

The code should be the first global conditional statement and come immediately after variables have been assigned.

To use, simply cut and paste the following into your existing script. Then declare variables c3 and YNP and compile.

If you wish to use inputs versus hard coding the values, you need to declare the input, assign an initial value and insert the input(s) where applicable. Input values should be set to your desired amount on either a per share/lot amount or total share / lot amount.

// GLOBAL CONDITIONAL - #1: Circuit breaker for the entire trading day
 
	IF	Date <> Date[1]											
 
			Then 	
 
			YNP = NetProfit;	
 
	IF	Date <> Date[1]
 
			Then								
 
			C3 = ( NetProfit - YNP );
 
	IF	C3 > -187.50		// Max allowable drawdown in dollars for one trading day				
 
	AND	C3 < 156.25		// Max allowable runup in dollars for one trading day