A test EA generated by Expert Advisor Studio (4th pattern)
This EA is generated by Expert Advisor Studio. It is based on the fourth pattern: Candlesticks with the Same Color.
A test EA generated by Expert Advisor Studio (4th pattern)
registerEA(
"sample_using_nonindicator",
"A test EA based on nonindicator",
[{ // parameters
name: "period",
value: 3,
required: true,
type: PARAMETER_TYPE.INTEGER,
range: [1, 100]
}],
function (context) { // Init()
var account = getAccount(context, 0)
var brokerName = getBrokerNameOfAccount(account)
var accountId = getAccountIdOfAccount(account)
var symbolName = "EUR/USD"
getQuotes(context, brokerName, accountId, symbolName)
window.chartHandle = getChartHandle(context, brokerName, accountId, symbolName, TIME_FRAME.M1)
},
function(context) { // Deinit()
delete window.currTime
},
function(context) { // OnTick()
var arrTime = getData(context, window.chartHandle, DATA_NAME.TIME)
if (typeof window.currTime == "undefined") {
window.currTime = arrTime[arrTime.length - 1]
} else if (window.currTime != arrTime[arrTime.length - 1]) {
window.currTime = arrTime[arrTime.length - 1]
} else {
return
}
var account = getAccount(context, 0)
var brokerName = getAccountIdOfAccount(account)
var accountId = getAccountIdOfAccount(account)
var symbolName = "EUR/USD"
var period = getEAParameter(context, "period")
var arrClose = getData(context, window.chartHandle, DATA_NAME.CLOSE)
var arrOpen = getData(context, window.chartHandle, DATA_NAME.OPEN)
var ask = getAsk(context, brokerName, accountId, symbolName)
var bid = getBid(context, brokerName, accountId, symbolName)
var limitPrice = 0.0003
var stopPrice = 0.0003
var volume = 0.01
var buyOrSell = "neither"
for (var i = 1; i <= period; i++) {
if (arrClose[arrClose.length - i] - arrOpen[arrOpen.length - i] > 0 && (buyOrSell == "buy" || i == 1)) {
buyOrSell = "buy"
} else if (arrClose[arrClose.length - i] - arrOpen[arrOpen.length - i] < 0 && (buyOrSell == "sell" || i == 1)) {
buyOrSell = "sell"
} else {
buyOrSell = "neither"
break
}
}
if (buyOrSell == "buy") {
sendOrder(brokerName, accountId, symbolName, ORDER_TYPE.OP_BUYLIMIT, ask - limitPrice, 0, volume, ask + limitPrice, bid - 3 * stopPrice, "")
} else if (buyOrSell == "sell") {
sendOrder(brokerName, accountId, symbolName, ORDER_TYPE.OP_SELLLIMIT, bid + limitPrice, 0, volume, bid - limitPrice, ask + 3 * stopPrice, "")
}
}
)