Programmers Corner
Programmers CornerIntroduction to IntelliScript
If you have programming experience then this section can help you! Interested in creating your own alerts? Please read on to learn about the IntelliScript programming language. The Desktop IntelliScript is a programming feature that allows users to draft and create their own Customized Alerts and Indicators. The IntelliScript is designed for the advanced chartist, with some programming experience.
The Desktop IntelliScript is a programming feature that allows users to draft and create their own Customized Alerts and Indicators. IntelliScript is designed for the advanced chartist, with some programming experience. The IntelliScript is similar to the C or Pascal language. It is not a full-blown programming language, but suitable to be considered as a much more simplified version of it. The functions and syntax used in the IntelliScript are really close to a script language.
For clients who do not have any programming experience, we recommend referring to a basic tutorial on C, paying attention to the following sections within the tutorial:
- Variable declaration, including different types of variables, like Boolean, String, Int, Float, etc.
- Variable value assignment.
- IF statements and how to define a condition (A condition would return true or false).
- WHILE statements.
- What is a function, what are parameters passed in a function, and the return value of a function (or if the function does not return any value).
Basic Concepts and detailed examples and definition of all the commands and functions can be found in our Manual online by clicking this button here:
Already understand IntelliScript, then here is a great list of FAQ's for drafting code:
Q1: How do I program an alert that will send me an email alert and/or a message to my cell phone?
For example, generating a buy when TMA (5) crosses above the SMMA (10) and vice-versa (a sell)?
(Note: To receive these alerts to your cell phone or email address, you must enter the addresses under "To" on the "Email" tab of the IntelliScript feature.)A1: Example:
IF CrossUP(TMA[0](Close, 5) , SmoothedMA[0](Close, 10)) THEN
AddBuyEntry
SendMail "TMA5 crossed above SMMA 10"
ENDIF
IF CrossDOWN(TMA[0](Close, 5) , SmoothedMA[0](Close, 10)) THEN
AddSellEntry
SendMail "TMA5 crossed below SMMA 10"
ENDIFQ2: How would I create a custom indicator?
A2: Custom indicators are created by specifying the Indicator name, the channel you wish it to reside, the color you wish to represent the indicator on your chart of choice and the value the indicator will use.
Below is an example of a custom indicator using EMA(10) of the DPO (20):
//Indicator EMADPO
Indicator EMADPO
EMADPO.Channel=1
EMADPO.Color="Black"
EMADPO.Value=EMA[0](Detrend_Price_Oscillator[0](Close, 20), 10)
EMADPO.DrawQ3: How do I program a crossover to generate a buy signal when the current bar close is 20 pips or greater than the line being crossed?
For example when WMA (5) crosses above the WMA (20) and the currency is 20 pips or greater above the WMA 20. How can I program the reverse for a short order WMA 5 cross down WMA 20?A3: Example:
IF CrossUP(WMA(close, 5), WMA(Close, 20)) and Close > WMA(Close, 20) + Point(20) THEN
AddBuyentry
Endif
/*Close < WMA(Close, 20) - Point(20) or Close < WMA(Close, 5) - Point(20)*/
IF CrossDOWN(WMA(close, 5), WMA(Close, 20)) and Close < WMA(Close, 20) - Point(20) THEN
AddSellentry
EndifQ4: How can I program a "trailing" stop?
A4: Using a trailing stop allows you to let profits run while cutting losses at the same time. Below is an example of a 50-pip trailing stop:
local short_trailing=0
local buy_trailing=0
IF isBuyPosition() THEN
if GetTradeBarIndex(0) =0 then
buy_trailing=max(LastTradePrice[0], price)
endif
if GetTradeBarIndex(0) >0 then
buy_trailing=HHV(high[1],GetTradeBarIndex(0)-1)
endif
IF buy_trailing-low > Point(20) THEN
AddBuyExit AT buy_trailing - Point(50)
ENDIF
ENDIF
IF isSellPosition() THEN
if GetTradeBarIndex(0) =0 then
short_trailing=min(-LastTradePrice[0], price)
endif
if GetTradeBarIndex(0) >0 then
short_trailing=LLV(low[1],GetTradeBarIndex(0)-1)
endif
IF high-short_trailing > Point(20) THEN
AddSellExit AT short_trailing + Point(50)
ENDIF
ENDIFQ5: How can I set up a sell or buy alert when two indicators reach a certain level? How can I also include a trailing stop of say 20 pips?
For example, generating a sell when RSI (14) crosses over 70 and ADX (14,14) is greater than 25 with a trailing stop of 20A5: To create this script a trailing stop is drafted first. Using a trailing stop allows you to let profits run while cutting losses at the same time. Below is an example of a 20 pip trailing stop:
local short_trailing=0
local buy_trailing=0
IF isBuyPosition() THEN
if GetTradeBarIndex(0) =0 then
buy_trailing=max(LastTradePrice[0], price)
endif
if GetTradeBarIndex(0) >0 then
buy_trailing=HHV(high[1],GetTradeBarIndex(0)-1)
endif
IF buy_trailing-low > Point(20) THEN
AddBuyExit AT buy_trailing - Point(20)
ENDIF
ENDIF
IF isSellPosition() THEN
if GetTradeBarIndex(0) =0 then
short_trailing=min(-LastTradePrice[0], price)
endif
if GetTradeBarIndex(0) >0 then
short_trailing=LLV(low[1],GetTradeBarIndex(0)-1)
endif
IF high-short_trailing > Point(20) THEN
AddSellExit AT short_trailing + Point(20)
ENDIF
ENDIF
To complete the script, add the following to the end of above codes for the RSI cross alerts for a sell alert and a buy alert:
IF CrossUP(RSI[0](close, 14), 70)) and ADX[0](Close, 14, 14) > 25 THEN
AddSellentry
Endif
IF CrossDOWN(RSI[0](close, 14),30)) and ADX[0](Close, 14, 14) > 25 THEN
AddBuyentry
EndifQ6: How can I create an alert that will let me know if a candle changes by 10 or more pips?
A6: Example:
IF High[0] - Low[0] > Point(10) THEN
AlertOnly "Change Over 10 Points"
ENDIFQ7: I have created a custom Indicator which is attached to a 15-min 10-day GBP/USD chart to read a bar from 1-hr 30-day data series. The syntax I have used is as follows:
tp=GetTimePoint(0)
Midnight1=GetHour(tp) + 1
Midnight0=24+midnight1
C=getValue("GBP/USD, 1hr. 30 day", Close[Midnight1])
O=getValue("GBP/USD, 1hr. 30 day)", Close[Midnight0])However, the getValue returns closing price from the 15-min chart instead of one-hour chart! Why is this happening?
A7: In many cases it is very important to pay particular attention the syntax that needs to be used for each command option available in the IntelliScript. The above command uses the correct commands, however the use of parenthesis or commands are incorrectly used. When the syntax is properly configured it will compile correctly and yield the desired results. For this request, here is the proper syntax to use:
local tp=GetTimePoint(0)
local Midnight1=GetHour(tp) + 1
local Midnight0=24+midnight1
Local C=getValue("GBP/USD, 1 hr. 30 day", Close[Midnight1])
Local O=getValue("GBP/USD, 1 hr. 30 day", Close[Midnight0])Q8: How do I add a filter of 10 pips, so I only get an alert when and if the price breaks above an indicator, then keeps moving by 10 pips?
A8: This example shows the answerusing the Chaos Fractal indicator:
IF crossup(close[1], Chaos_Fractal_UP[1](Close) + Point(10)) THEN
AddBuyEntry
ENDIF
IF crossdown(close[1], Chaos_Fractal_DOWN[1](Close) - Point(10)) THEN
AddSellEntry
ENDIFQ9: How can I retrieve last weeks' high?
For example, when using a 1 hr 20 day chart.A9: Retrieving this data requires using the "local" and "getvalue" IntelliScript commands.
The "Local" command allows you to declare a local variable in the chart. These variables remain accessible only within the particular script in which it is included.
The "getValue" command returns the value of the expression set forth in the script. This function enables you to retrieve the value from a different data series than the one to which the script is attached.
The script for retrieving last weeks high, using a 1hr 20 day chart would be written as follows:
Local wkhigh
wkhigh=getValue("eur/usd ,1 wk. 10 yr.", high[1])
HLine myhigh=wkhighQ10: How can I set up my charts so that every time an indicator crosses above or below the ??line it will give me an alert?
A10: The following example uses DPO (16), you can substitute any indicator that uses a ??line:
IF CrossUP(Detrend_Price_Oscillator[0](Close, 16), 0) THEN
AlertOnly "DPO UP"
ENDIF
IF CrossDOWN(Detrend_Price_Oscillator[0](Close, 16), 0) THEN
AlertOnly "DPO DOWN"
ENDIFQ11: How can I apply a buy signal when an indicator crosses below a specific value and take profit of 15 pips later? How can I apply a sell signal when an indicator goes above a specific value and take profit 15 pips later?
A11: The IntelliScript does feature specific commands for taking profit for both the buy and sell. These are "BuyTakeProfit" and "SellTakeProfit". To set these to take the profit at 15 pips, the Point command is used.
The following example illustrates the above case using RSI (9) as the indicator:
BuyTakeProfit Point(15)
SellTakeProfit Point(15)
IF CrossDOWN(RSI(Close, 9), 25) THEN
AddBuyEntry
ENDIF
IF CrossUP(RSI(Close, 9), 75) THEN
AddSellEntry
ENDIFQ12: How do I program an alert based on two conditions (two indicators)? For example, generating a buy when the price crosses over BLG_UP(20,2) and CCI (20) is greater than 100.
A12: In this example, we will use the AND function:
IF CrossUP(Price[0],BLG_U[0](Close, 20, 2)) AND CCI[0](Close, 20)> 100 THEN
AddBuyEntry
ENDIFQ13: How can I create a custom indicator to plot the highest high for the last 20 periods, as well as the lowest low over the last twenty periods?
A13: The IntelliScript features a user-friendly method when creating your own indicators making it hassle free.
Simply launch the IntelliScript Organizer and select the tab labeled Indicator. In the area labeled "Create Customized Indicator, you may assign a Name, select the channel to place your indicator, the color you would like it to appear in, as well as what this indicator will do in the Value box. Once you have entered your changes, the script will be shown in the window under "Expression"
Here is an example of a script referencing high and low for the request above:
//Indicator Ind1
Indicator Ind1
Ind1.Channel=0
Ind1.Color="Yellow"
Ind1.Value= HHV(High, 20)
Ind1.Draw
//Indicator Ind2
Indicator Ind2
Ind2.Channel=0
Ind2.Color="Green"
Ind2.Value=LLV(Low, 20)
Ind2.DrawQ14: I would like to create an alert when two indicators come within 6 pips of each other.
For example when WMA(34) and WMA(100) are within 6 pips of each other.A14: Example:
IF ABS(WMA(Close, 34) - WMA(Close, 100)) <= Point(6) THEN
AlertOnly "WMA in Range"
ENDIFQ15: How can I create an alert for the Heikin Ashi to alert me when the bar changes color?
A15: Example:
IF HA_Close[0](Close) > HA_Open[0](Close) THEN
AlertOnly "Heikin Ashi is Blue"
ELSE
AlertOnly "Heikin Ashi is Red"
ENDIFQ16: I would like to write my own Daily Pivot Points calculated from midnight to midnight. Is this possible to do in the IntelliScript?
A16: Example script for the Daily Pivot Points calculated from midnight to midnight that will be shown on hourly and smaller time frames:
Local midnighttp,midinx
Global dayO=-1
Global dayC=-1
Global dayH=-1
Global dayL=-1
If getBarTime(1)<getBarTime(2) then //midnight midnighttp=GetTimePoint(0)-86400000
midinx=GetIndexByTimePoint(midnighttp)
If midinx>0 then
dayC=close[1]
dayO=open[midinx]
dayH=HHV(high,midinx)
dayL=LLV(low,midinx)
Endif
Endif
If dayH>0 then
Local MyPivot=(dayH+dayL+dayC)*0.333
Local S1 = MyPivot - (dayH - MyPivot) //S1 Line
Local S2 = MyPivot - (dayH - dayL) //S2 Line
Local S3 = dayL - (dayH - dayL) //S3 Line
Local R1 = MyPivot + (MyPivot - dayL) //R1 Line
Local R2 = MyPivot + (dayH - dayL) //R2 Line
Local R3 = dayH + (dayH - dayL) //R3 Line
HLine MyS1 = S1
MyS1.Color = "Blue"
HLine MyS2 = S2
MyS2.Color = "Blue"
HLine MyS3 = S3
MyS3.Color = "Blue"
HLine MyR1 = R1
MyR1.Color = "Red"
HLine MyR2 = R2
MyR2.Color = "Red"
HLine MyR3 = R3
MyR3.Color = "Red"
HLine MyLastHigh = dayH
MyLastHigh.Color = "Black"
HLine MyLastLow = dayL
MyLastLow.Color = "Black"
Endif
To complete the script, check the box for "Generate Historical Alerts" under "Set Alert Properties" on the "Alert" tab before attaching to a chart.Q17: When I draw support and resistance lines using the "add line" tool, is there any way these lines can be recognized using the IntelliScript code?
A17: You may reference lines on the chart within code using the IntelliScript. To do so, right mouse click on the line of your choice and assign a label. You may then use the line label preceded by an underscore within your code to reference this specific line. For example, if a trend line has been labeled ABC, to refer to this line in your code use this syntax: _ABC