registerEA(
“nn_example”,
“A take a look at EA to run neuron mannequin for XOR(v1.0)”,
[
{name: “h11”, value: 20, required: true, type: “Number”, range: [-100, 100], step: 10},
{title: “h12”, worth: 20, required: true, sort: “Quantity”, vary: [-100, 100], step: 10},
{title: “b1”, worth: –10, required: true, sort: “Quantity”, vary: [-100, 100], step: 10},
{title: “h21”, worth: –20, required: true, sort: “Quantity”, vary: [-100, 100], step: 10},
{title: “h22”, worth: –20, required: true, sort: “Quantity”, vary: [-100, 100], step: 10},
{title: “b2”, worth: 30, required: true, sort: “Quantity”, vary: [-100, 100], step: 10},
{title: “o1”, worth: 20, required: true, sort: “Quantity”, vary: [-100, 100], step: 10},
{title: “o2”, worth: 20, required: true, sort: “Quantity”, vary: [-100, 100], step: 10},
{title: “b”, worth: –30, required: true, sort: “Quantity”, vary: [-100, 100], step: 10},
],
perform (context) {
var account = getAccount(context, 0)
var brokerName = getBrokerNameOfAccount(account)
var accountId = getAccountIdOfAccount(account)
var symbolName = “EUR/USD”
getQuotes (context, brokerName, accountId, symbolName)
},
perform (context) {
var h11 = getEAParameter(context, “h11”)
var h12 = getEAParameter(context, “h12”)
var b1 = getEAParameter(context, “b1”)
var h21 = getEAParameter(context, “h21”)
var h22 = getEAParameter(context, “h22”)
var b2 = getEAParameter(context, “b2”)
var o1 = getEAParameter(context, “o1”)
var o2 = getEAParameter(context, “o2”)
var b = getEAParameter(context, “b”)
var sigmoid = perform (t) {
return 1 / (1 + Math.pow(Math.E, -t))
}
var nn = perform (p1, p2) {
return sigmoid(o1 * sigmoid(h11 * p1 + h12 * p2 + b1) + o2 * sigmoid(h21 * p1 + h22 * p2 + b2) + b)
}
var error = 0
error += nn(1, 1)
error += 1 – nn(1, 0)
error += 1 – nn(0, 1)
error += nn(0, 0)
setOptimizationResult(context, -error)
printMessage(“error: “ + error + “, “ + Math.spherical(nn(1, 1)) + ” “ + Math.spherical(nn(1, 0)) + ” “ + Math.spherical(nn(0, 1)) + ” “ + Math.spherical(nn(0, 0)))
},
perform (context) {
})
2.
registerEA(
“sample_run_neuron_model”,
“A take a look at EA to run neuron mannequin(v1.04)”,
[{
name: “period”,
value: 20,
required: true,
type: PARAMETER_TYPE.INTEGER,
range: [1, 100]
},{
title: “inputNum”,
worth: 20,
required: true,
sort: PARAMETER_TYPE.INTEGER,
vary: [1, 100]
},{
title: “threshold”,
worth: 0.3,
required: true,
sort: PARAMETER_TYPE.NUMBER,
vary: [0, 1]
},{
title: “takeProfit”,
worth: 0.0001,
required: true,
sort: PARAMETER_TYPE.NUMBER,
vary: [0, 100]
}],
perform (context) {
if (typeof localStorage.reservedZone == “undefined”) return
var reservedZone = JSON.parse(localStorage.reservedZone)
if (typeof reservedZone.sample_training_neuron_model == “undefined”) return
context.myPerceptron = synaptic.Community.fromJSON(reservedZone.sample_training_neuron_model)
var account = getAccount(context, 0)
var brokerName = getBrokerNameOfAccount(account)
var accountId = getAccountIdOfAccount(account)
var symbolName = “EUR/USD”
getQuotes (context, brokerName, accountId, symbolName)
context.chartHandle = getChartHandle(context, brokerName, accountId, symbolName, TIME_FRAME.M1)
var interval = getEAParameter(context, “interval”)
context.indiHandle = getIndicatorHandle(context, brokerName, accountId, symbolName, TIME_FRAME.M1, “rsi”, [{
name: “period”,
value: period
}])
},
perform (context) {
},
perform (context) {
var arrTime = getData(context, context.chartHandle, DATA_NAME.TIME)
if (typeof context.currTime == “undefined”) {
context.currTime = arrTime[arrTime.length – 1]
} else if (context.currTime != arrTime[arrTime.length – 1]) {
context.currTime = arrTime[arrTime.length – 1]
} else {
return
}
var account = getAccount(context, 0)
var brokerName = getBrokerNameOfAccount(account)
var accountId = getAccountIdOfAccount(account)
var symbolName = “EUR/USD”
var interval = getEAParameter(context, “interval”)
var inputNum = getEAParameter(context, “inputNum”)
var threshold = getEAParameter(context, “threshold”)
var takeProfit = getEAParameter(context, “takeProfit”)
var arrRsi = getData(context, context.indiHandle, “rsi”)
if (inputNum + interval – 1 > arrRsi.size) throw new Error(“No sufficient information.”)
var enter = []
for (var i = arrRsi.size – inputNum – 1; i < arrRsi.size – 1; i++) {
enter.push(arrRsi[i] / 100)
}
var end result = context.myPerceptron.activate(enter)[0]
printMessage(end result)
var ask = null
var bid = null
var quantity = 0.01
strive {
ask = getAsk(context, brokerName, accountId, symbolName)
bid = getBid(context, brokerName, accountId, symbolName)
} catch (e) {
printErrorMessage(e.message)
return
}
if (end result < 0.5 – threshold) {
sendOrder(brokerName, accountId, symbolName, ORDER_TYPE.OP_BUY, 0, 0, quantity, ask+takeProfit, bid-3*takeProfit, “”, 0, 0)
} else if (end result > 0.5 + threshold) {
sendOrder(brokerName, accountId, symbolName, ORDER_TYPE.OP_SELL, 0, 0, quantity, bid-takeProfit, ask+3*takeProfit, “”, 0, 0)
}
}
)
3.
registerEA(
“sample_training_neuron_model”,
“A take a look at EA to coach neuron mannequin(v1.03)”,
[{
name: “period”,
value: 20,
required: true,
type: PARAMETER_TYPE.INTEGER,
range: [1, 100]
},{
title: “inputNum”,
worth: 20,
required: true,
sort: PARAMETER_TYPE.INTEGER,
vary: [1, 100]
},{
title: “hiddenNum”,
worth: 50,
required: true,
sort: PARAMETER_TYPE.INTEGER,
vary: [1, 100]
},{
title: “diffPrice”,
worth: 0.0001,
required: true,
sort: PARAMETER_TYPE.NUMBER,
vary: [0, 10]
}],
perform (context) {
var account = getAccount(context, 0)
var brokerName = getBrokerNameOfAccount(account)
var accountId = getAccountIdOfAccount(account)
var symbolName = “EUR/USD”
context.chartHandle = getChartHandle(context, brokerName, accountId, symbolName, TIME_FRAME.M1)
var interval = getEAParameter(context, “interval”)
context.indiHandle = getIndicatorHandle(context, brokerName, accountId, symbolName, TIME_FRAME.M1, “rsi”, [{
name: “period”,
value: period
}])
},
perform (context) {
var interval = getEAParameter(context, “interval”)
var inputNum = getEAParameter(context, “inputNum”)
var hiddenNum = getEAParameter(context, “hiddenNum”)
var arrOpen = getData(context, context.chartHandle, DATA_NAME.OPEN)
var arrClose = getData(context, context.chartHandle, DATA_NAME.CLOSE)
var arrRsi = getData(context, context.indiHandle, “rsi”)
if (arrRsi.size <= interval + 1) return
if (inputNum + interval – 1 > arrRsi.size) throw new Error(“No sufficient information.”)
Perceptron.prototype = new synaptic.Community()
Perceptron.prototype.constructor = Perceptron
var myPerceptron = new Perceptron(inputNum, hiddenNum, 1)
var myTrainer = new synaptic.Coach(myPerceptron)
var diffPrice = getEAParameter(context, “diffPrice”)
var trainingSet = []
var longCount = 0
var shortCount = 0
for (var i = interval – 1; i < arrRsi.size – inputNum; i++) {
if (arrClose[i * inputNum + inputNum] – arrOpen[i * inputNum + inputNum] > diffPrice) {
var enter = []
for (var j = 0; j < inputNum; j++) {
enter.push(arrRsi[i * inputNum + j] / 100)
}
trainingSet.push({
enter: enter,
output: [0]
})
longCount++
} else if (arrOpen[i * inputNum + inputNum] – arrClose[i * inputNum + inputNum] > diffPrice) {
var enter = []
for (var j = 0; j < inputNum; j++) {
enter.push(arrRsi[i * inputNum + j] / 100)
}
trainingSet.push({
enter: enter,
output: [1]
})
shortCount++
}
}
myTrainer.prepare(trainingSet)
if (typeof localStorage.reservedZone == “undefined”) {
localStorage.reservedZone = JSON.stringify({sample_training_neuron_model: myPerceptron.toJSON()})
} else {
var reservedZone = JSON.parse(localStorage.reservedZone)
reservedZone.sample_training_neuron_model = myPerceptron.toJSON()
localStorage.reservedZone = JSON.stringify(reservedZone)
}
printMessage(longCount + “, “ + shortCount)
printMessage(JSON.stringify(trainingSet))
printMessage(JSON.stringify(myPerceptron.toJSON()))
},
perform (context) {
}
)
ReadMe….
“sample_training_neuron_model” and “sample_run_neuron_model” are two neural network-based EAs that should be used collectively. One can not perform with out the opposite.
“sample_training_neuron_model” trains the mannequin, whereas “sample_run_neuron_model” generates alerts based mostly on the mannequin educated by “sample_training_neuron_model”.
To assist perceive how a neural community works, i’ve included a easy instance referred to as “nn_example”.
The algorithm carried out right here is predicated on Synaptic, an AI framework. Tensorflow, a extra superior framework, runs convolutional neural networks. For extra particulars on Tensorflow, discuss with plugin_for_tensorflow.
That is higher than fireplace…
Greatest regards.
Foreign exchange Mastery, a community of Corporations specializing within the growth of Strict and sophisticated Software program utilized in buying and selling growth and automation.