Initial Commit ...
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
#
|
||||
Logs
|
||||
Images
|
||||
Include
|
||||
Scripts
|
||||
Profiles
|
||||
Experts/Advisors
|
||||
Experts/Examples
|
||||
Indicators/Examples
|
||||
|
||||
#
|
||||
experts.dat
|
||||
*.ex5
|
||||
*.log
|
||||
|
||||
#
|
||||
node_modules
|
||||
package-lock.json
|
||||
|
||||
#
|
||||
.VSCodeCounter
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Compile XEA",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"runtimeExecutable": "npm",
|
||||
"runtimeArgs": [
|
||||
"run-script", "compileEA"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"C_Cpp.errorSquiggles": "disabled",
|
||||
"C_Cpp.intelliSenseEngineFallback": "enabled",
|
||||
"C_Cpp.default.compilerPath": ""
|
||||
}
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Compile XEA",
|
||||
"type": "shell",
|
||||
"command": "C:\\Users\\saherelm\\AppData\\Roaming\\MetaQuotes\\Terminal\\D0E8209F77C8CF37AD8BF550E51FF075\\MQL5\\Compile-MQL.ps1 C:\\Users\\saherelm\\AppData\\Roaming\\MetaQuotes\\Terminal\\D0E8209F77C8CF37AD8BF550E51FF075\\MQL5\\Experts\\x-saherelm.ea.mq5",
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "always",
|
||||
"focus": false,
|
||||
"panel": "shared",
|
||||
"showReuseMessage": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Compile-MQL",
|
||||
"type": "shell",
|
||||
"command": "C:\\Users\\saherelm\\AppData\\Roaming\\MetaQuotes\\Terminal\\D0E8209F77C8CF37AD8BF550E51FF075\\MQL5\\Compile-MQL.ps1 ${file}",
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "always",
|
||||
"focus": false,
|
||||
"panel": "shared",
|
||||
"showReuseMessage": false
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
+785
@@ -0,0 +1,785 @@
|
||||
{
|
||||
"todo": [
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T05:52:38.201Z",
|
||||
"description": {
|
||||
"content": "- [] add supports for OAuth implementation;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "28",
|
||||
"references": [],
|
||||
"title": "Add Support for OAuth"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T05:53:36.313Z",
|
||||
"description": {
|
||||
"content": "- [] add a Mechanism for Push Commands to Robot;\n- [] enable all base configurations to locally changes using commands;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "29",
|
||||
"references": [],
|
||||
"title": "Add SUpport for Push Commands"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-22T01:30:28.887Z",
|
||||
"description": {
|
||||
"content": "- [] Pause/Resume;\n- [] Restart;\n- [] Stop Opening New Positions for Withdrawal Actions;\n- [] add support for enable disable signallers;\n- [] etc;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "45",
|
||||
"references": [],
|
||||
"title": "add support for some actions button on chart of EA"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-28T08:23:14.444Z",
|
||||
"id": "56",
|
||||
"references": [],
|
||||
"title": "add Support for XSupport and InDirectional Support Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T17:22:24.427Z",
|
||||
"description": {
|
||||
"content": "- [] XTD;\n- [] XSI;\n- [] XOBDLH;\n- [] XCHMACC;\n- [] XCHMACMN;\n- [] XCHMACMX;\n\nthis task is not so important at the moment, doint this later ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "36",
|
||||
"references": [],
|
||||
"title": "Do a Refactor On Long Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T09:48:13.509Z",
|
||||
"id": "32",
|
||||
"references": [],
|
||||
"title": "R&D about placing stop limit orders for Indirectional Supports",
|
||||
"description": {
|
||||
"content": "since there are many issues to manage them, for the moment i will ignore this.\n,aybe working on it later ...",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-23T22:21:14.112Z",
|
||||
"description": {
|
||||
"content": "ignore adding sl on partial closed and risk free signals for the moment ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "46",
|
||||
"references": [],
|
||||
"title": "resolve InvalidStop on Partial Closing"
|
||||
}
|
||||
],
|
||||
"in-progress": [
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2024-01-19T15:09:51.323Z",
|
||||
"description": {
|
||||
"content": "- Attack Guards Duplicate if Profit less than Prev Guard Attack;\n- When Guard Attacks Multiple times, Start Grid Support Trades;\n- Remove Signal Protector Stuffs;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "59",
|
||||
"references": [],
|
||||
"title": "Change Guard Mechanism"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-30T06:09:35.026Z",
|
||||
"details": {
|
||||
"content": "- [x] Found Conditions related to new Indicator/Oscillator(s);\n- [x] attached Conditions to XEU5 Provider;\n- [x] fix and Refactor Signals Issues on Brokers and Logs;\n- [x] Re Test in all Brokers;\n- [x] implement Signal Providers based on New Indicator/Oscillator(s);\n- [x] add supports for TP and SL adding for each Signaller;\n- [x] Complete Support mechanism in Guard class;\n- [x] Test Support before Cleanup and Refactor Signals;\n- [x] do some test on guard stopout;\n- [x] Register AMarket Account;\n- [x] Register Alpari Account;\n- [x] Register Errante Account;\n- [] fix server hdd issues;\n- [] complete all rust desk and anydesk ids for systems;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "57",
|
||||
"references": [],
|
||||
"title": "IMP Works TODO:"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-24T01:13:49.250Z",
|
||||
"id": "49",
|
||||
"references": [],
|
||||
"title": "start backbone of XAUUSD robot for MQL5"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2024-01-19T15:26:34.083Z",
|
||||
"id": "60",
|
||||
"references": [],
|
||||
"title": "remove virtual TP SL from Inputs"
|
||||
}
|
||||
],
|
||||
"testing": [
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-23T22:56:31.075Z",
|
||||
"description": {
|
||||
"content": "- [] Nothing;\n- [] Close If In DD;\n- [] Partial Close if in DD _5;\n- [] Partial Close if in DD _10;\n- [] Partial Close if in DD _15;\n- [] Partial Close if in DD _20;\n- [] Partial Close if in DD _25;\n",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "48",
|
||||
"references": [],
|
||||
"title": "add a mechanism for acting for long time trades ..."
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-23T22:21:39.744Z",
|
||||
"id": "47",
|
||||
"references": [],
|
||||
"title": "add a method for generating Collector logs ..."
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-22T01:07:29.299Z",
|
||||
"description": {
|
||||
"content": "- [x] report library;\n- [x] define report models;\n- [x] define report mechanism;\n- [x] implement Logger Reports;\n- [x] report String Generators;\n- [x] use reports in ea;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "44",
|
||||
"references": [],
|
||||
"title": "add a Report library and define all required reports inside it"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T11:07:59.089Z",
|
||||
"description": {
|
||||
"content": "- [x] XTD;\n- [x] XSI;\n- [x] XOBDLH;\n- [x] XCHMACC;\n- [x] XCHMACMX;\n- [x] XCHMACMN;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "33",
|
||||
"references": [],
|
||||
"title": "add config sections to select providers long and short signalling"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-27T11:37:45.679Z",
|
||||
"id": "54",
|
||||
"references": [],
|
||||
"title": "add handlers for TakeProfit or LoseProfit Events"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-19T10:19:40.648Z",
|
||||
"id": "40",
|
||||
"references": [],
|
||||
"title": "add settings for Trade Management and risk management"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-20T13:38:04.017Z",
|
||||
"description": {
|
||||
"content": "add Start Alert and Prompt Some Values on it ...\nprepare Comments for informing usefull data ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "41",
|
||||
"references": [],
|
||||
"title": "add start Alert"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:06:27.820Z",
|
||||
"description": {
|
||||
"content": "- [x] Check Signal State;\n- [x] Calculate Volume;\n- [x] In Directional Supporting;\n\nimplemented, but since have issues on managing, ignore use them ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "24",
|
||||
"references": [],
|
||||
"title": "add Support for Indirectional Supporting Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T05:51:40.742Z",
|
||||
"description": {
|
||||
"content": "- [x] Add Support for Hourly Alarams;\n- [x] Add Support for Daily Alarams;\n- [x] Add Support for Weekly Info Alarams;\n- [x] ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "27",
|
||||
"references": [],
|
||||
"title": "Add support for Info Alarms"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:07:37.092Z",
|
||||
"description": {
|
||||
"content": "- [x] Calculate How CLose Pyramid in Count;\n- [x] How Close Pyramid in Profit;\n- [x] How Close Pyramid in Max Draw Down;\n\nthese functionalities implemented successfully, but since we don't use any Supporting mechanism and limit number of same time trades.",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "25",
|
||||
"references": [],
|
||||
"title": "add Support for Pyramid Closing Trades"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-20T20:08:43.804Z",
|
||||
"description": {
|
||||
"content": "wee need this buffer to Increase or Decrease volumes ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "42",
|
||||
"references": [],
|
||||
"title": "Add Support for Save Max In DrawDown in Buffer",
|
||||
"details": {
|
||||
"content": "- [] add an specific library;\n- [] define all requirement;\n- [] add utility functions;\n- [] use it;",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-28T08:21:10.141Z",
|
||||
"id": "55",
|
||||
"references": [],
|
||||
"title": "add support for Stop Out Action in Guard Class",
|
||||
"details": {
|
||||
"content": "attached it but need to test ...",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:05:41.976Z",
|
||||
"description": {
|
||||
"content": "- [x] Max Count;\n- [x] for In DD Long Signals;\n- [x] Volume Calculations;\n\nimplemented, but ignore to use them, for moment, since they have issues on managing ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "23",
|
||||
"references": [],
|
||||
"title": "add Support for Support Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:04:44.044Z",
|
||||
"description": {
|
||||
"content": "check partial Closing works correctly;\n\n- [x] for Longs;\n- [x] for Shorts;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "22",
|
||||
"references": [],
|
||||
"title": "Check Partial Closing"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T17:03:45.572Z",
|
||||
"id": "35",
|
||||
"references": [],
|
||||
"title": "Complete Input Validators for XEU5",
|
||||
"description": {
|
||||
"content": "- [x] XTM;\n- [x] XTD;\n- [x] XRSI;\n- [x] XOBD;\n- [x] XLH;\n- [x] XCHLH;\n- [x] XCHMA;",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:03:50.981Z",
|
||||
"description": {
|
||||
"content": "Complete Remained Short Signals:\n\n- [x] XCHMA Crosses;\n- [x] XCHMA Under Max;\n- [x] XCHMA Under Min;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "20",
|
||||
"references": [],
|
||||
"title": "Complete Remained Short Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-24T01:15:14.065Z",
|
||||
"id": "50",
|
||||
"references": [],
|
||||
"title": "create a signal protector class for handling signals states on time pasted"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T11:08:47.584Z",
|
||||
"id": "34",
|
||||
"references": [],
|
||||
"title": "Disbale Conditions Logs ..."
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-24T07:37:10.876Z",
|
||||
"id": "52",
|
||||
"references": [],
|
||||
"title": "extends new section based indicators"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:04:18.085Z",
|
||||
"description": {
|
||||
"content": "fix volume calculation for signals;\n\n- [x] static volume;\n- [x] base volume multiplier;\n- [x] grow rate based on balance increasing;\n- [x] max volume duplicator;\n- [x] decrease volume for support trades;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "21",
|
||||
"references": [],
|
||||
"title": "Fix Volume Calculation"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-24T07:36:28.060Z",
|
||||
"description": {
|
||||
"content": "- [] implement helpers lib for new indicators;\n- [] try to test them into a new ea;\n- [] combine them with our product;\n",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "51",
|
||||
"references": [],
|
||||
"title": "implement new indicators helpers lib"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-21T00:12:42.225Z",
|
||||
"id": "43",
|
||||
"references": [],
|
||||
"title": "increase min balance for trading based on account balance ..."
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2024-01-03T12:04:41.939Z",
|
||||
"id": "58",
|
||||
"references": [],
|
||||
"title": "make settings input related to Indicators and Oscillators hidden or private"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T09:27:48.310Z",
|
||||
"description": {
|
||||
"content": "- [x] Close Support Trades;\n- [x] Close InDirectional Trades;\n- [x] Increase/Decrease Volume Multiplier based on TP(s) and SL(s);\n\nimplement OnTrade requirements for later usage, everythings works correctly, but for the moment i ignore use it ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "31",
|
||||
"references": [],
|
||||
"title": "Read OnTrade Event Documentation"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-24T17:48:18.009Z",
|
||||
"description": {
|
||||
"content": "- [] XSignal Structure;\n- [] XTrader Class;\n- [] Draw Signal, TP's and SL, and Volumes;\n",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "53",
|
||||
"references": [],
|
||||
"title": "Refactor XSignal and Create a new One also New Trader"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-19T08:18:38.795Z",
|
||||
"id": "39",
|
||||
"references": [],
|
||||
"title": "Remove UnUsed Settings for Production"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T06:44:02.085Z",
|
||||
"description": {
|
||||
"content": "- [x] XTD;\n- [x] XSI;\n- [x] XOBDLH;\n- [x] XCHMACC;\n- [x] XCHMACMX;\n- [x] XCHMACMN;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "30",
|
||||
"references": [],
|
||||
"title": "rename signal providers to propper names"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-19T08:17:38.115Z",
|
||||
"id": "38",
|
||||
"references": [],
|
||||
"title": "Test and Add support for Equity and Max Drawdown Management"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-17T13:13:33.447Z",
|
||||
"id": "37",
|
||||
"references": [],
|
||||
"title": "there is an stop on combining on meta quote broker fix this ...",
|
||||
"details": {
|
||||
"content": "do a refactor on all brokers, higgh priority criterias ...",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
}
|
||||
],
|
||||
"done": [
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-06T16:40:25.004Z",
|
||||
"description": {
|
||||
"content": "add supports to plot trend arrow in tdma indicator",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "18",
|
||||
"references": [],
|
||||
"title": "add supports to plot trend arrow in tdma indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:07:56.408Z",
|
||||
"details": {
|
||||
"content": "- [x] cleanup old structure supports;\n- [x] cleanup old structure indirectional;\n- [x] cleanup old structure max in draw down;\n- [x] cleanup old structure old signals;\n- etc ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "26",
|
||||
"references": [],
|
||||
"title": "Cleanup Provider UnUsed Functions;"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T09:30:44.836Z",
|
||||
"description": {
|
||||
"content": "handle all requirement for neural network class.",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"details": {
|
||||
"content": "required many things for testing ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "11",
|
||||
"references": [],
|
||||
"title": "create a neural network class"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-05T20:24:26.792Z",
|
||||
"description": {
|
||||
"content": "create a signal provider template based on XRSI",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "14",
|
||||
"references": [],
|
||||
"title": "create a signal provider template based on XRSI"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T08:05:13.515Z",
|
||||
"description": {
|
||||
"content": "create account info library",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"details": {
|
||||
"content": "define it as a class in class lib ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "9",
|
||||
"references": [],
|
||||
"title": "create account info library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T15:43:14.906Z",
|
||||
"details": {
|
||||
"content": "create alert library:\n\n- [] add configurationinputs;\n- [] add alert functions;\n- [] mail;\n- [] push;\n- [] terminal;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "4",
|
||||
"references": [],
|
||||
"title": "create alert library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T09:30:05.284Z",
|
||||
"description": {
|
||||
"content": "create an x-ea provider template:\n\n- [x] create event handlers;\n- [x] add required config inputs;\n- [x] define access to classes;\n- [x] etc ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "10",
|
||||
"references": [],
|
||||
"title": "create an x-ea provider template"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T13:34:50.719Z",
|
||||
"description": {
|
||||
"content": "create common library",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"details": {
|
||||
"content": "created but must add required functions in working times ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "13",
|
||||
"references": [],
|
||||
"title": "create common library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T21:31:53.418Z",
|
||||
"details": {
|
||||
"content": "create draw library:\n\n- [x] configurations input like objPrefix;\n- [x] draw functions;\n- [x] draw chart setting;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "5",
|
||||
"references": [],
|
||||
"title": "create draw library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T09:41:01.882Z",
|
||||
"description": {
|
||||
"content": "create http library",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "12",
|
||||
"references": [],
|
||||
"title": "create http library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T12:23:14.619Z",
|
||||
"details": {
|
||||
"content": "- [x] add input for logTag;\n- [x] add input for enableLogging;\n- [x] add reuired logging functions;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "1",
|
||||
"references": [],
|
||||
"title": "create logger library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T15:40:11.509Z",
|
||||
"description": {
|
||||
"content": "create ma colorify indicator.\nsomething like TrendMagic ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "3",
|
||||
"references": [],
|
||||
"title": "create ma colorify indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T15:39:38.300Z",
|
||||
"description": {
|
||||
"content": "create ma indicator",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "2",
|
||||
"references": [],
|
||||
"title": "create ma indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T21:38:20.129Z",
|
||||
"description": {
|
||||
"content": "create models library",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "6",
|
||||
"references": [],
|
||||
"title": "create models library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-05T20:25:20.394Z",
|
||||
"description": {
|
||||
"content": "create OrderBlock Finder Indicator",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "17",
|
||||
"references": [],
|
||||
"title": "create OrderBlock Finder Indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T08:04:33.131Z",
|
||||
"description": {
|
||||
"content": "create Trade Class",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "8",
|
||||
"references": [],
|
||||
"title": "create Trade Class"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T23:54:36.761Z",
|
||||
"description": {
|
||||
"content": "create XTrendDetector Indicator ",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "7",
|
||||
"references": [],
|
||||
"title": "create XTrendDetector Indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-07T19:28:10.103Z",
|
||||
"details": {
|
||||
"content": "- [x] Adaptive Moving Average; Implemented\n- [x] Bolinger Bands; No\n- [x] Envelopes; No\n- [x] Fractal Adaptive Moving Average; No\n- [x] Bears/Bulls Power; No\n- [x] Chaikin Oscillator; MayBe\n- [X] Commodity Channel Index; AN No\n- [] DeMarker;\n- [] Force Index;\n- [] MACD;\n- [] Momentum;\n- [] Moving Average Of Oscillators;\n- [] Accumulation/Distribution;\n- [] On Balance Volume;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "19",
|
||||
"references": [],
|
||||
"title": "R&D about Exists Examples"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-05T20:24:44.656Z",
|
||||
"description": {
|
||||
"content": "rename XRSI Provider Name to something else",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "15",
|
||||
"references": [],
|
||||
"title": "rename XRSI Provider Name to something else"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-05T20:25:01.625Z",
|
||||
"description": {
|
||||
"content": "start implementing XTPW indicator",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "16",
|
||||
"references": [],
|
||||
"title": "start implementing XTPW indicator"
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
+738
@@ -0,0 +1,738 @@
|
||||
{
|
||||
"todo": [
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T05:52:38.201Z",
|
||||
"description": {
|
||||
"content": "- [] add supports for OAuth implementation;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "28",
|
||||
"references": [],
|
||||
"title": "Add Support for OAuth"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T05:53:36.313Z",
|
||||
"description": {
|
||||
"content": "- [] add a Mechanism for Push Commands to Robot;\n- [] enable all base configurations to locally changes using commands;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "29",
|
||||
"references": [],
|
||||
"title": "Add SUpport for Push Commands"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-22T01:30:28.887Z",
|
||||
"description": {
|
||||
"content": "- [] Pause/Resume;\n- [] Restart;\n- [] Stop Opening New Positions for Withdrawal Actions;\n- [] add support for enable disable signallers;\n- [] etc;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "45",
|
||||
"references": [],
|
||||
"title": "add support for some actions button on chart of EA"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T17:22:24.427Z",
|
||||
"description": {
|
||||
"content": "- [] XTD;\n- [] XSI;\n- [] XOBDLH;\n- [] XCHMACC;\n- [] XCHMACMN;\n- [] XCHMACMX;\n\nthis task is not so important at the moment, doint this later ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "36",
|
||||
"references": [],
|
||||
"title": "Do a Refactor On Long Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T09:48:13.509Z",
|
||||
"id": "32",
|
||||
"references": [],
|
||||
"title": "R&D about placing stop limit orders for Indirectional Supports",
|
||||
"description": {
|
||||
"content": "since there are many issues to manage them, for the moment i will ignore this.\n,aybe working on it later ...",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-23T22:21:14.112Z",
|
||||
"description": {
|
||||
"content": "ignore adding sl on partial closed and risk free signals for the moment ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "46",
|
||||
"references": [],
|
||||
"title": "resolve InvalidStop on Partial Closing"
|
||||
}
|
||||
],
|
||||
"in-progress": [
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-28T08:23:14.444Z",
|
||||
"id": "56",
|
||||
"references": [],
|
||||
"title": "add Support for XSupport and InDirectional Support Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-24T07:37:10.876Z",
|
||||
"id": "52",
|
||||
"references": [],
|
||||
"title": "extends new section based indicators"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-24T07:36:28.060Z",
|
||||
"description": {
|
||||
"content": "- [] implement helpers lib for new indicators;\n- [] try to test them into a new ea;\n- [] combine them with our product;\n",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "51",
|
||||
"references": [],
|
||||
"title": "implement new indicators helpers lib"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-24T01:13:49.250Z",
|
||||
"id": "49",
|
||||
"references": [],
|
||||
"title": "start backbone of XAUUSD robot for MQL5"
|
||||
}
|
||||
],
|
||||
"testing": [
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-23T22:56:31.075Z",
|
||||
"description": {
|
||||
"content": "- [] Nothing;\n- [] Close If In DD;\n- [] Partial Close if in DD _5;\n- [] Partial Close if in DD _10;\n- [] Partial Close if in DD _15;\n- [] Partial Close if in DD _20;\n- [] Partial Close if in DD _25;\n",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "48",
|
||||
"references": [],
|
||||
"title": "add a mechanism for acting for long time trades ..."
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-23T22:21:39.744Z",
|
||||
"id": "47",
|
||||
"references": [],
|
||||
"title": "add a method for generating Collector logs ..."
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-22T01:07:29.299Z",
|
||||
"description": {
|
||||
"content": "- [x] report library;\n- [x] define report models;\n- [x] define report mechanism;\n- [x] implement Logger Reports;\n- [x] report String Generators;\n- [x] use reports in ea;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "44",
|
||||
"references": [],
|
||||
"title": "add a Report library and define all required reports inside it"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T11:07:59.089Z",
|
||||
"description": {
|
||||
"content": "- [x] XTD;\n- [x] XSI;\n- [x] XOBDLH;\n- [x] XCHMACC;\n- [x] XCHMACMX;\n- [x] XCHMACMN;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "33",
|
||||
"references": [],
|
||||
"title": "add config sections to select providers long and short signalling"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-27T11:37:45.679Z",
|
||||
"id": "54",
|
||||
"references": [],
|
||||
"title": "add handlers for TakeProfit or LoseProfit Events"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-19T10:19:40.648Z",
|
||||
"id": "40",
|
||||
"references": [],
|
||||
"title": "add settings for Trade Management and risk management"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-20T13:38:04.017Z",
|
||||
"description": {
|
||||
"content": "add Start Alert and Prompt Some Values on it ...\nprepare Comments for informing usefull data ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "41",
|
||||
"references": [],
|
||||
"title": "add start Alert"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:06:27.820Z",
|
||||
"description": {
|
||||
"content": "- [x] Check Signal State;\n- [x] Calculate Volume;\n- [x] In Directional Supporting;\n\nimplemented, but since have issues on managing, ignore use them ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "24",
|
||||
"references": [],
|
||||
"title": "add Support for Indirectional Supporting Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T05:51:40.742Z",
|
||||
"description": {
|
||||
"content": "- [x] Add Support for Hourly Alarams;\n- [x] Add Support for Daily Alarams;\n- [x] Add Support for Weekly Info Alarams;\n- [x] ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "27",
|
||||
"references": [],
|
||||
"title": "Add support for Info Alarms"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:07:37.092Z",
|
||||
"description": {
|
||||
"content": "- [x] Calculate How CLose Pyramid in Count;\n- [x] How Close Pyramid in Profit;\n- [x] How Close Pyramid in Max Draw Down;\n\nthese functionalities implemented successfully, but since we don't use any Supporting mechanism and limit number of same time trades.",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "25",
|
||||
"references": [],
|
||||
"title": "add Support for Pyramid Closing Trades"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-20T20:08:43.804Z",
|
||||
"description": {
|
||||
"content": "wee need this buffer to Increase or Decrease volumes ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "42",
|
||||
"references": [],
|
||||
"title": "Add Support for Save Max In DrawDown in Buffer",
|
||||
"details": {
|
||||
"content": "- [] add an specific library;\n- [] define all requirement;\n- [] add utility functions;\n- [] use it;",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:05:41.976Z",
|
||||
"description": {
|
||||
"content": "- [x] Max Count;\n- [x] for In DD Long Signals;\n- [x] Volume Calculations;\n\nimplemented, but ignore to use them, for moment, since they have issues on managing ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "23",
|
||||
"references": [],
|
||||
"title": "add Support for Support Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:04:44.044Z",
|
||||
"description": {
|
||||
"content": "check partial Closing works correctly;\n\n- [x] for Longs;\n- [x] for Shorts;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "22",
|
||||
"references": [],
|
||||
"title": "Check Partial Closing"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T17:03:45.572Z",
|
||||
"id": "35",
|
||||
"references": [],
|
||||
"title": "Complete Input Validators for XEU5",
|
||||
"description": {
|
||||
"content": "- [x] XTM;\n- [x] XTD;\n- [x] XRSI;\n- [x] XOBD;\n- [x] XLH;\n- [x] XCHLH;\n- [x] XCHMA;",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:03:50.981Z",
|
||||
"description": {
|
||||
"content": "Complete Remained Short Signals:\n\n- [x] XCHMA Crosses;\n- [x] XCHMA Under Max;\n- [x] XCHMA Under Min;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "20",
|
||||
"references": [],
|
||||
"title": "Complete Remained Short Signals"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-24T01:15:14.065Z",
|
||||
"id": "50",
|
||||
"references": [],
|
||||
"title": "create a signal protector class for handling signals states on time pasted"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T11:08:47.584Z",
|
||||
"id": "34",
|
||||
"references": [],
|
||||
"title": "Disbale Conditions Logs ..."
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:04:18.085Z",
|
||||
"description": {
|
||||
"content": "fix volume calculation for signals;\n\n- [x] static volume;\n- [x] base volume multiplier;\n- [x] grow rate based on balance increasing;\n- [x] max volume duplicator;\n- [x] decrease volume for support trades;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "21",
|
||||
"references": [],
|
||||
"title": "Fix Volume Calculation"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-21T00:12:42.225Z",
|
||||
"id": "43",
|
||||
"references": [],
|
||||
"title": "increase min balance for trading based on account balance ..."
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T09:27:48.310Z",
|
||||
"description": {
|
||||
"content": "- [x] Close Support Trades;\n- [x] Close InDirectional Trades;\n- [x] Increase/Decrease Volume Multiplier based on TP(s) and SL(s);\n\nimplement OnTrade requirements for later usage, everythings works correctly, but for the moment i ignore use it ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "31",
|
||||
"references": [],
|
||||
"title": "Read OnTrade Event Documentation"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-24T17:48:18.009Z",
|
||||
"description": {
|
||||
"content": "- [] XSignal Structure;\n- [] XTrader Class;\n- [] Draw Signal, TP's and SL, and Volumes;\n",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "53",
|
||||
"references": [],
|
||||
"title": "Refactor XSignal and Create a new One also New Trader"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-19T08:18:38.795Z",
|
||||
"id": "39",
|
||||
"references": [],
|
||||
"title": "Remove UnUsed Settings for Production"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T06:44:02.085Z",
|
||||
"description": {
|
||||
"content": "- [x] XTD;\n- [x] XSI;\n- [x] XOBDLH;\n- [x] XCHMACC;\n- [x] XCHMACMX;\n- [x] XCHMACMN;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "30",
|
||||
"references": [],
|
||||
"title": "rename signal providers to propper names"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-19T08:17:38.115Z",
|
||||
"id": "38",
|
||||
"references": [],
|
||||
"title": "Test and Add support for Equity and Max Drawdown Management"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-17T13:13:33.447Z",
|
||||
"id": "37",
|
||||
"references": [],
|
||||
"title": "there is an stop on combining on meta quote broker fix this ...",
|
||||
"details": {
|
||||
"content": "do a refactor on all brokers, higgh priority criterias ...",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-28T08:21:10.141Z",
|
||||
"id": "55",
|
||||
"references": [],
|
||||
"title": "add support for Stop Out Action in Guard Class",
|
||||
"details": {
|
||||
"content": "attached it but need to test ...",
|
||||
"mime": "text/markdown"
|
||||
}
|
||||
}
|
||||
],
|
||||
"done": [
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-06T16:40:25.004Z",
|
||||
"description": {
|
||||
"content": "add supports to plot trend arrow in tdma indicator",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "18",
|
||||
"references": [],
|
||||
"title": "add supports to plot trend arrow in tdma indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"category": "XEU5",
|
||||
"creation_time": "2023-12-16T03:07:56.408Z",
|
||||
"details": {
|
||||
"content": "- [x] cleanup old structure supports;\n- [x] cleanup old structure indirectional;\n- [x] cleanup old structure max in draw down;\n- [x] cleanup old structure old signals;\n- etc ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "26",
|
||||
"references": [],
|
||||
"title": "Cleanup Provider UnUsed Functions;"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T09:30:44.836Z",
|
||||
"description": {
|
||||
"content": "handle all requirement for neural network class.",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"details": {
|
||||
"content": "required many things for testing ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "11",
|
||||
"references": [],
|
||||
"title": "create a neural network class"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-05T20:24:26.792Z",
|
||||
"description": {
|
||||
"content": "create a signal provider template based on XRSI",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "14",
|
||||
"references": [],
|
||||
"title": "create a signal provider template based on XRSI"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T08:05:13.515Z",
|
||||
"description": {
|
||||
"content": "create account info library",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"details": {
|
||||
"content": "define it as a class in class lib ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "9",
|
||||
"references": [],
|
||||
"title": "create account info library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T15:43:14.906Z",
|
||||
"details": {
|
||||
"content": "create alert library:\n\n- [] add configurationinputs;\n- [] add alert functions;\n- [] mail;\n- [] push;\n- [] terminal;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "4",
|
||||
"references": [],
|
||||
"title": "create alert library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T09:30:05.284Z",
|
||||
"description": {
|
||||
"content": "create an x-ea provider template:\n\n- [x] create event handlers;\n- [x] add required config inputs;\n- [x] define access to classes;\n- [x] etc ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "10",
|
||||
"references": [],
|
||||
"title": "create an x-ea provider template"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T13:34:50.719Z",
|
||||
"description": {
|
||||
"content": "create common library",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"details": {
|
||||
"content": "created but must add required functions in working times ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "13",
|
||||
"references": [],
|
||||
"title": "create common library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T21:31:53.418Z",
|
||||
"details": {
|
||||
"content": "create draw library:\n\n- [x] configurations input like objPrefix;\n- [x] draw functions;\n- [x] draw chart setting;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "5",
|
||||
"references": [],
|
||||
"title": "create draw library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T09:41:01.882Z",
|
||||
"description": {
|
||||
"content": "create http library",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "12",
|
||||
"references": [],
|
||||
"title": "create http library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T12:23:14.619Z",
|
||||
"details": {
|
||||
"content": "- [x] add input for logTag;\n- [x] add input for enableLogging;\n- [x] add reuired logging functions;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "1",
|
||||
"references": [],
|
||||
"title": "create logger library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T15:40:11.509Z",
|
||||
"description": {
|
||||
"content": "create ma colorify indicator.\nsomething like TrendMagic ...",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "3",
|
||||
"references": [],
|
||||
"title": "create ma colorify indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T15:39:38.300Z",
|
||||
"description": {
|
||||
"content": "create ma indicator",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "2",
|
||||
"references": [],
|
||||
"title": "create ma indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T21:38:20.129Z",
|
||||
"description": {
|
||||
"content": "create models library",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "6",
|
||||
"references": [],
|
||||
"title": "create models library"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-05T20:25:20.394Z",
|
||||
"description": {
|
||||
"content": "create OrderBlock Finder Indicator",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "17",
|
||||
"references": [],
|
||||
"title": "create OrderBlock Finder Indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-04T08:04:33.131Z",
|
||||
"description": {
|
||||
"content": "create Trade Class",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "8",
|
||||
"references": [],
|
||||
"title": "create Trade Class"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-01T23:54:36.761Z",
|
||||
"description": {
|
||||
"content": "create XTrendDetector Indicator ",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "7",
|
||||
"references": [],
|
||||
"title": "create XTrendDetector Indicator"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-12-07T19:28:10.103Z",
|
||||
"details": {
|
||||
"content": "- [x] Adaptive Moving Average; Implemented\n- [x] Bolinger Bands; No\n- [x] Envelopes; No\n- [x] Fractal Adaptive Moving Average; No\n- [x] Bears/Bulls Power; No\n- [x] Chaikin Oscillator; MayBe\n- [X] Commodity Channel Index; AN No\n- [] DeMarker;\n- [] Force Index;\n- [] MACD;\n- [] Momentum;\n- [] Moving Average Of Oscillators;\n- [] Accumulation/Distribution;\n- [] On Balance Volume;",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "19",
|
||||
"references": [],
|
||||
"title": "R&D about Exists Examples"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-05T20:24:44.656Z",
|
||||
"description": {
|
||||
"content": "rename XRSI Provider Name to something else",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "15",
|
||||
"references": [],
|
||||
"title": "rename XRSI Provider Name to something else"
|
||||
},
|
||||
{
|
||||
"assignedTo": {
|
||||
"name": "Hadi Khazaee Asl"
|
||||
},
|
||||
"creation_time": "2023-11-05T20:25:01.625Z",
|
||||
"description": {
|
||||
"content": "start implementing XTPW indicator",
|
||||
"mime": "text/markdown"
|
||||
},
|
||||
"id": "16",
|
||||
"references": [],
|
||||
"title": "start implementing XTPW indicator"
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,258 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 NN Class Library
|
||||
// ----------------------------------------
|
||||
// Name: XNNClass
|
||||
// Description: provides all classes for implementing
|
||||
// Neural Network ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
class XCNNBase
|
||||
{
|
||||
//
|
||||
// Public Definitions ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCNNBase(
|
||||
int nodes = 10, // Number of Input Nodes
|
||||
double starterWeight = 0.5, // start weight for each input
|
||||
double coEfficient = 0.1, // COEfficient Multiplier
|
||||
double upperRange = 1, // Upper Normal Range Value
|
||||
double lowerRange = -1, // Lower Normal Range Value
|
||||
double learningRates = 0.1 // Back Propagation Learning Rate
|
||||
) {
|
||||
//
|
||||
mNodes = nodes;
|
||||
mUpperRange = upperRange;
|
||||
mLowerRange = lowerRange;
|
||||
mCoEfficient = coEfficient;
|
||||
mLearningRates = learningRates;
|
||||
mStarterWeight = starterWeight;
|
||||
|
||||
//
|
||||
ReConstructWeights();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCNNBase() {}
|
||||
|
||||
//
|
||||
// Protected Definitions ...
|
||||
void NormalizeInputs(double &inputs[], double &result[])
|
||||
{
|
||||
//
|
||||
ArrayFree(result);
|
||||
ArrayResize(result, 1);
|
||||
|
||||
//
|
||||
// Validate inputs ...
|
||||
if (ArraySize(inputs) != mNodes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Result ...
|
||||
ArrayResize(result, mNodes);
|
||||
|
||||
//
|
||||
// Calculating min and max range value ...
|
||||
double minRangeValue = inputs[ArrayMinimum(inputs)];
|
||||
double maxRangeValue = inputs[ArrayMaximum(inputs)];
|
||||
|
||||
//
|
||||
// Loop through Inputs nd Normalize them ...
|
||||
for (int i = 0; i < mNodes; i++)
|
||||
{
|
||||
//
|
||||
double normalValue = (((inputs[i] - minRangeValue) * (mUpperRange - mLowerRange)) / (maxRangeValue - minRangeValue)) + mLowerRange;
|
||||
result[i] = normalValue;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Hyperbolic Tangent Activation Function ...
|
||||
double TanHActivationFunction(double weightedInputs)
|
||||
{
|
||||
//
|
||||
double result = (exp(weightedInputs) - exp(-weightedInputs)) / (exp(weightedInputs) + exp(-weightedInputs));
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Weighted Inputs ...
|
||||
double CalculateWeightedInputs(
|
||||
double &inputs[],
|
||||
bool applyCOEfficient = true)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes)
|
||||
{
|
||||
//
|
||||
result = -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < mNodes; i++)
|
||||
{
|
||||
result += inputs[i] * mWeights[i];
|
||||
}
|
||||
|
||||
//
|
||||
// Multiply if required ...
|
||||
if (applyCOEfficient)
|
||||
{
|
||||
result *= mCoEfficient;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Hidden Layers ...
|
||||
virtual double CalculateHiddenLayer(double &inputs[])
|
||||
{
|
||||
//
|
||||
// this is Default Activation Function which used ...
|
||||
// you can override this by writing your own ...
|
||||
double totalWeightedInputs = CalculateWeightedInputs(inputs);
|
||||
double result = TanHActivationFunction(totalWeightedInputs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Output Layers ...
|
||||
double CalculateOutputLayer(double &inputs[])
|
||||
{
|
||||
//
|
||||
double result = -1;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double normalizedInputs[];
|
||||
NormalizeInputs(inputs, normalizedInputs);
|
||||
if (ArraySize(normalizedInputs) != mNodes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double hiddenLayerResult = CalculateHiddenLayer(normalizedInputs);
|
||||
|
||||
//
|
||||
result = 1 * hiddenLayerResult;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Basck Propaggation Learning ...
|
||||
void BackPropagation(
|
||||
double &inputs[],
|
||||
double &outputs,
|
||||
double targetOutput
|
||||
) {
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double normalizedInputs[];
|
||||
NormalizeInputs(inputs, normalizedInputs);
|
||||
if (ArraySize(normalizedInputs) != mNodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double error = targetOutput - outputs;
|
||||
double derivative = 1 - MathPow(outputs, 2);
|
||||
|
||||
//
|
||||
for (int i = 0; i < mNodes; i++) {
|
||||
//
|
||||
double gradient = error * derivative * inputs[i];
|
||||
mWeights[i] = mLearningRates * gradient;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
//
|
||||
// Private Definitions ...
|
||||
private:
|
||||
//
|
||||
// Number of Input Nodes ...
|
||||
int mNodes;
|
||||
|
||||
//
|
||||
// Specify Upper range of Normal Values ...
|
||||
double mUpperRange;
|
||||
|
||||
//
|
||||
// Specify Lower range of Normal Values ...
|
||||
double mLowerRange;
|
||||
|
||||
//
|
||||
// Starter Weight for each input node ...
|
||||
double mStarterWeight;
|
||||
|
||||
//
|
||||
// double Input Node Weights ...
|
||||
double mWeights[];
|
||||
|
||||
//
|
||||
// CoEfficient is a multiplyer for weighted inputs ...
|
||||
double mCoEfficient;
|
||||
|
||||
//
|
||||
// Back Propagation Learning Rates ...
|
||||
double mLearningRates;
|
||||
|
||||
//
|
||||
// ReConstruct Weights ...
|
||||
void ReConstructWeights() {
|
||||
//
|
||||
ArrayFree(mWeights);
|
||||
ArrayResize(mWeights, mNodes);
|
||||
|
||||
//
|
||||
for (int i = 0; i< mNodes; i++) {
|
||||
mWeights[i] = mStarterWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,347 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// ----------------------------------------
|
||||
// Name: XAUUSD
|
||||
// Description: this is an expert controller
|
||||
// advisors which provides a mechanism for use them ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XEU5 EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "Commons";
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Logger Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Alert Library ...
|
||||
#include "../Libraries/x-saherelm.alert.lib.mq5"
|
||||
|
||||
//
|
||||
// Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// XEU5 Signal Provider ...
|
||||
#include "../Providers/x-saherelm.xeu5.provider.lib.mq5"
|
||||
|
||||
//
|
||||
// END Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
bool isXEU5NewHour;
|
||||
bool isXEU5NewDay;
|
||||
bool isXEU5NewWeek;
|
||||
bool isXEU5NewMonth;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
logTag = "XEU5EA";
|
||||
drawPrefix = logTag;
|
||||
alertPrefix = logTag;
|
||||
|
||||
//
|
||||
// Apply default Chart Style for EA ...
|
||||
ApplyChartStyle();
|
||||
|
||||
//
|
||||
// Reset Timings ...
|
||||
ResetTiming();
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize XEU5 Provider ...
|
||||
if (!XEU5InitSignalProviderLibrary())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
// De Initialize XEU5 Provider ...
|
||||
XEU5DeinitSignalProviderLibrary(reason);
|
||||
|
||||
//
|
||||
// De Init XDraw Library ...
|
||||
// OnDeinitDrawLibrary();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// Handle Monthly Alert ...
|
||||
bool isFirstMonth = xMonth == -1;
|
||||
isXEU5NewMonth = IsNewMonth();
|
||||
bool canMonthlyAlert =
|
||||
isXEU5NewMonth &&
|
||||
xEU5EnableAlerts &&
|
||||
xEU5EnableMonthlyAlerts;
|
||||
bool canMonthlyReport =
|
||||
!isFirstMonth &&
|
||||
canMonthlyAlert &&
|
||||
xEU5EnableMonthlyReports;
|
||||
if (canMonthlyAlert)
|
||||
{
|
||||
//
|
||||
string message = "New Month ...";
|
||||
|
||||
//
|
||||
// Prepare Monthly Report ...
|
||||
if (canMonthlyReport)
|
||||
{
|
||||
//
|
||||
string report = xEU5Reporter.GenerateReportString(XREPORT_MONTHLY);
|
||||
|
||||
//
|
||||
message = "Last Month Report:\n" + report;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset Report ...
|
||||
xEU5Reporter.Reset(XREPORT_MONTHLY);
|
||||
|
||||
//
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Weekly Alert ...
|
||||
bool isFirstWeek = xDayOfWeek == -1;
|
||||
isXEU5NewWeek = IsNewWeek();
|
||||
bool canWeeklyAlert =
|
||||
isXEU5NewWeek &&
|
||||
xEU5EnableAlerts &&
|
||||
xEU5EnableWeeklyAlerts;
|
||||
bool canWeeklyReport =
|
||||
!isFirstWeek &&
|
||||
canWeeklyAlert &&
|
||||
xEU5EnableWeeklyReports;
|
||||
if (canWeeklyAlert)
|
||||
{
|
||||
//
|
||||
string message = "New Week ...";
|
||||
|
||||
//
|
||||
// Prepare Weekly Report ...
|
||||
if (canWeeklyReport)
|
||||
{
|
||||
//
|
||||
string report = xEU5Reporter.GenerateReportString(XREPORT_WEEKLY);
|
||||
|
||||
//
|
||||
message = "Last Week Report:\n" + report;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset Report ...
|
||||
xEU5Reporter.Reset(XREPORT_WEEKLY);
|
||||
|
||||
//
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Daily Alert ...
|
||||
bool isFirstDay = xDay == -1;
|
||||
isXEU5NewDay = IsNewDay();
|
||||
bool canDailyAlert =
|
||||
isXEU5NewDay &&
|
||||
xEU5EnableAlerts &&
|
||||
xEU5EnableDailyAlerts;
|
||||
bool canDailyReport =
|
||||
!isFirstDay &&
|
||||
canDailyAlert &&
|
||||
xEU5EnableDailyReports;
|
||||
if (canDailyAlert)
|
||||
{
|
||||
//
|
||||
string message = "New Day ...";
|
||||
|
||||
//
|
||||
// Prepare Daily Report ...
|
||||
if (canDailyReport)
|
||||
{
|
||||
//
|
||||
string report = xEU5Reporter.GenerateReportString(XREPORT_DAILY);
|
||||
|
||||
//
|
||||
message = "Last Week Report:\n" + report;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset Report ...
|
||||
xEU5Reporter.Reset(XREPORT_DAILY);
|
||||
|
||||
//
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Hourly Alert ...
|
||||
bool isFirstHour = xHour == -1;
|
||||
isXEU5NewHour = IsNewHour();
|
||||
bool canHourlyAlert =
|
||||
isXEU5NewHour &&
|
||||
xEU5EnableAlerts &&
|
||||
xEU5EnableHourlyAlerts;
|
||||
if (canHourlyAlert)
|
||||
{
|
||||
//
|
||||
string message = "New Hour ...";
|
||||
|
||||
//
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xEU5EnableProvider)
|
||||
{
|
||||
//
|
||||
// Handle Processing on XEU5 Signal Provider ...
|
||||
XEU5SignalProviderDoControlState();
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsNewCandle())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xEU5EnableProvider)
|
||||
{
|
||||
//
|
||||
// Handle Processing on XEU5 Signal Provider ...
|
||||
XEU5SignalProviderHandleTick();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Trade Events ...
|
||||
void OnTrade()
|
||||
{
|
||||
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xEU5EnableProvider)
|
||||
{
|
||||
//
|
||||
// Handle Processing Trades on XEU5 Signal Provider ...
|
||||
XEU5SignalProviderHandleTrade();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
|
||||
//
|
||||
// Validate XEU5 Provider Inputs ...
|
||||
result = XEU5ValidateInputs();
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging State ...
|
||||
string message = "Validation of (" + logTag + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,607 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XAMA Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XAMA Indicator States ...
|
||||
enum ENUM_X_XAMA_STATES
|
||||
{
|
||||
X_XAMA_BULLISH = 1,
|
||||
X_XAMA_BEARISH = -1,
|
||||
X_XAMA_NEUTURAL = 0,
|
||||
};
|
||||
|
||||
//
|
||||
// XAMA Indicator Buffer Lines ...
|
||||
enum ENUM_X_XAMA_BUFFER_LINES
|
||||
{
|
||||
X_XAMA_MA_LINE = 0,
|
||||
X_XAMA_MC_COLOR_LINE = 1,
|
||||
X_XAMA_STATE_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XAMA Indicator";
|
||||
|
||||
//
|
||||
// input int xAMALength = 18; // Market Length
|
||||
// input int xAMAFastEMA = 2; // Fast EMA Period
|
||||
// input int xAMASlowEMA = 30; // Slow EMA Period
|
||||
// input int xAMAShift = 0; // Shift
|
||||
// input ENUM_APPLIED_PRICE xAMAAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xAMALength = 18; // Market Length
|
||||
int xAMAFastEMA = 2; // Fast EMA Period
|
||||
int xAMASlowEMA = 30; // Slow EMA Period
|
||||
int xAMAShift = 0; // Shift
|
||||
ENUM_APPLIED_PRICE xAMAAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xAMAHandler = INVALID_HANDLE;
|
||||
double xAMAMaBuffer[];
|
||||
double xAMAStateBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XAMAValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
xAMALength > 2 &&
|
||||
xAMAFastEMA < xAMALength &&
|
||||
xAMAFastEMA < xAMASlowEMA &&
|
||||
xAMAShift >= 0;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XAMA Indicator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XAMAInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Indicator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XAMA Handler ...
|
||||
ArraySetAsSeries(xAMAMaBuffer, true);
|
||||
ArraySetAsSeries(xAMAStateBuffer, true);
|
||||
xAMAHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xama.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xAMALength,
|
||||
xAMAFastEMA,
|
||||
xAMASlowEMA,
|
||||
xAMAShift,
|
||||
xAMAAppliedTo
|
||||
//
|
||||
);
|
||||
if (xAMAHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XAMA Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XAMAReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xAMAHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XAMAReadBuffers(
|
||||
int xAMAItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XAMA Ma Buffer ...
|
||||
CopyBuffer(
|
||||
xAMAHandler,
|
||||
X_XAMA_MA_LINE,
|
||||
0,
|
||||
xAMAItemsPerTick,
|
||||
xAMAMaBuffer);
|
||||
|
||||
//
|
||||
// XAMA State Buffer ...
|
||||
CopyBuffer(
|
||||
xAMAHandler,
|
||||
X_XAMA_STATE_LINE,
|
||||
0,
|
||||
xAMAItemsPerTick,
|
||||
xAMAStateBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XAMA Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check SC is Peak ...
|
||||
bool XAMAIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xAMAMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check SC is Vale ...
|
||||
bool XAMAIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xAMAMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up ...
|
||||
bool XAMAIsStartBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BULLISH &&
|
||||
xAMAStateBuffer[bar_index + 1] != X_XAMA_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up After Neutural State ...
|
||||
bool XAMAIsStartBullishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BULLISH &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Up State ...
|
||||
bool XAMAIsBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State ...
|
||||
bool XAMAIsEndBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] != X_XAMA_BULLISH &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State By Neutural ...
|
||||
bool XAMAIsEndBullishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_NEUTURAL &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down ...
|
||||
bool XAMAIsStartBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BEARISH &&
|
||||
xAMAStateBuffer[bar_index + 1] != X_XAMA_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down After Neutural State ...
|
||||
bool XAMAIsStartBearishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BEARISH &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Down State ...
|
||||
bool XAMAIsBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State ...
|
||||
bool XAMAIsEndBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] != X_XAMA_BEARISH &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State By Neutural ...
|
||||
bool XAMAIsEndBearishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_NEUTURAL &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Neutural State ...
|
||||
bool XAMAIsNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XAMAIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xAMAMaBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XAMA Custom Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,358 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XFI Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XFI Oscillator";
|
||||
|
||||
// //
|
||||
// input int xFILength = 18; // Market Length
|
||||
// input ENUM_MA_METHOD xFIMethod = MODE_SMA; // MA Method
|
||||
// input ENUM_APPLIED_VOLUME xFIAppliedTo = VOLUME_TICK; // Applied To
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xFILength = 18; // Market Length
|
||||
ENUM_MA_METHOD xFIMethod = MODE_SMA; // MA Method
|
||||
ENUM_APPLIED_VOLUME xFIAppliedTo = VOLUME_TICK; // Applied To
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xFIHandler = INVALID_HANDLE;
|
||||
double xFIBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XFIValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xFILength > 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XFI Oscillator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XFIInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XFI Handler ...
|
||||
ArraySetAsSeries(xFIBuffer, true);
|
||||
xFIHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xfi.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
xFILength,
|
||||
xFIMethod,
|
||||
xFIAppliedTo
|
||||
//
|
||||
);
|
||||
if (xFIHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XFI Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XFIReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xFIHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XFIReadBuffers(
|
||||
int xFIItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XFI Signal ...
|
||||
CopyBuffer(
|
||||
xFIHandler,
|
||||
0,
|
||||
0,
|
||||
xFIItemsPerTick,
|
||||
xFIBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XFI Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check SC is Peak ...
|
||||
bool XFIIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xFIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check SC is Vale ...
|
||||
bool XFIIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xFIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect XFI Crossed Over Zero ...
|
||||
bool XFIIsCrossedOverZero(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xFIBuffer[bar_index] > 0 &&
|
||||
xFIBuffer[bar_index + 1] <= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect XFI Over Zero ...
|
||||
bool XFIIsOverZero(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xFIBuffer[bar_index] > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect XFI Crossed Under Zero ...
|
||||
bool XFIIsCrossedUnderZero(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xFIBuffer[bar_index] < 0 &&
|
||||
xFIBuffer[bar_index + 1] >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect XFI Under Zero ...
|
||||
bool XFIIsUnderZero(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xFIBuffer[bar_index] < 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XFIIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xFIBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XFI Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,668 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XLH Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XLH Indicator Buffer Lines ...
|
||||
enum ENUM_X_XLH_BUFFER_LINES
|
||||
{
|
||||
X_XLH_HH_LINE = 0,
|
||||
X_XLH_LL_LINE = 1,
|
||||
X_XLH_SIGNAL_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XLH Indicator";
|
||||
|
||||
// input int xLHLength = 72; // Length
|
||||
// input ENUM_SERIESMODE xLHHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
// input ENUM_SERIESMODE xLHLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xLHLength = 72; // Length
|
||||
ENUM_SERIESMODE xLHHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
ENUM_SERIESMODE xLHLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
int xLHHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
double xLHHHBuffer[];
|
||||
double xLHLLBuffer[];
|
||||
double xLHSignalBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XLHValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xLHLength >= 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XLH Indicator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XLHInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XLH Handler ...
|
||||
ArraySetAsSeries(xLHHHBuffer, true);
|
||||
ArraySetAsSeries(xLHLLBuffer, true);
|
||||
ArraySetAsSeries(xLHSignalBuffer, true);
|
||||
|
||||
//
|
||||
xLHHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xlh.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xLHLength,
|
||||
xLHHHMode,
|
||||
xLHLLMode
|
||||
//
|
||||
);
|
||||
if (xLHHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XLH Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XLHReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xLHHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XLHReadBuffers(
|
||||
int xLHItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// HH Buffer ...
|
||||
CopyBuffer(
|
||||
xLHHandler,
|
||||
X_XLH_HH_LINE,
|
||||
0,
|
||||
xLHItemsPerTick,
|
||||
xLHHHBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// LL Buffer ...
|
||||
CopyBuffer(
|
||||
xLHHandler,
|
||||
X_XLH_LL_LINE,
|
||||
0,
|
||||
xLHItemsPerTick,
|
||||
xLHLLBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
CopyBuffer(
|
||||
xLHHandler,
|
||||
X_XLH_SIGNAL_LINE,
|
||||
0,
|
||||
xLHItemsPerTick,
|
||||
xLHSignalBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XLH Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TODO: What we have to Implement ...
|
||||
// - []
|
||||
|
||||
//
|
||||
// Check Candle High is HH ...
|
||||
bool XLHIsHighAttachedHH(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle.high == xLHHHBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Candle Low is LL ...
|
||||
bool XLHIsLowAttachedLL(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle.low == xLHLLBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Jumping Up Signal ...
|
||||
bool XLHIsPriceCrossedOverSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
XOHCL candle2 = GetCandle(bar_index + 1);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.low > xLHSignalBuffer[bar_index] &&
|
||||
candle2.low < xLHSignalBuffer[bar_index + 1]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Over Signal ...
|
||||
bool XLHIsPriceOverSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.low > xLHSignalBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Jumping Down Signal ...
|
||||
bool XLHIsPriceCrossedUnderSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
XOHCL candle2 = GetCandle(bar_index + 1);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.high < xLHSignalBuffer[bar_index] &&
|
||||
candle2.high > xLHSignalBuffer[bar_index + 1]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Down Signal ...
|
||||
bool XLHIsPriceUnderSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.high < xLHSignalBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Ranging Signal ...
|
||||
bool XLHIsPriceInSignalRange(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.high > xLHSignalBuffer[bar_index] &&
|
||||
candle1.low < xLHSignalBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check HH Increased ...
|
||||
bool XLHIsHHIncreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHHHBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check HH Decreased ...
|
||||
bool XLHIsHHDecreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHHHBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LL Increased ...
|
||||
bool XLHIsLLIncreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHLLBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LL Decreased ...
|
||||
bool XLHIsLLDecreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHLLBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check HH Same in Length ...
|
||||
bool XLHIsHHSameInLength(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 5 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double value1 = xLHHHBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Loop ...
|
||||
result = true;
|
||||
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
||||
{
|
||||
//
|
||||
double iValue = xLHHHBuffer[i];
|
||||
if (iValue != value1)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LL Same in Length ...
|
||||
bool XLHIsLLSameInLength(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 5 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double value1 = xLHLLBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Loop ...
|
||||
result = true;
|
||||
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
||||
{
|
||||
//
|
||||
double iValue = xLHLLBuffer[i];
|
||||
if (iValue != value1)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XLHIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xLHHHBuffer) < size ||
|
||||
ArraySize(xLHLLBuffer) < size ||
|
||||
ArraySize(xLHSignalBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XLH Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,249 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XOBD Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XOBD Indicator";
|
||||
|
||||
// input int xOBDLength = 5; // Swing Length
|
||||
// input uchar xOBDSwingHighArrowCode = 108; // Swing High Arrow Code
|
||||
// input color xOBDSwingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
||||
// input uchar xOBDSwingLowArrowCode = 108; // Swing Low Arrow Code
|
||||
// input color xOBDSwingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xOBDLength = 5; // Swing Length
|
||||
uchar xOBDSwingHighArrowCode = 108; // Swing High Arrow Code
|
||||
color xOBDSwingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
||||
uchar xOBDSwingLowArrowCode = 108; // Swing Low Arrow Code
|
||||
color xOBDSwingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
int xOBDHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
double xOBDBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XOBDValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xOBDLength >= 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XOBD Indicator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XOBDInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XOBD Handler ...
|
||||
ArraySetAsSeries(xOBDBuffer, true);
|
||||
|
||||
//
|
||||
xOBDHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xobd.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xOBDLength,
|
||||
xOBDSwingHighArrowCode,
|
||||
xOBDSwingHighArrowColor,
|
||||
xOBDSwingLowArrowCode,
|
||||
xOBDSwingLowArrowColor
|
||||
//
|
||||
);
|
||||
if (xOBDHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XOBD Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XOBDReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xOBDHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XOBDReadBuffers(
|
||||
int xOBDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// OBD Buffer ...
|
||||
CopyBuffer(
|
||||
xOBDHandler,
|
||||
0,
|
||||
0,
|
||||
xOBDItemsPerTick,
|
||||
xOBDBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XOBD Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check is Swing Low Occured or not ...
|
||||
bool XOBDIsSwingLow(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XOBDIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = xOBDBuffer[bar_index] == X_SWING_LOW;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check is Swing High Occured or not ...
|
||||
bool XOBDIsSwingHigh(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XOBDIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = xOBDBuffer[bar_index] == X_SWING_HIGH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XOBDIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xOBDBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XOBD Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,433 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XRSI Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XRSI Oscillator Buffer Lines ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XRSI Oscillator";
|
||||
|
||||
// //
|
||||
// input group "XRSI Market";
|
||||
// input int xRSILength = 18; // Market Length
|
||||
// input ENUM_APPLIED_PRICE xRSIAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
// //
|
||||
// input group "XRSI Short Entry";
|
||||
// input double xRSIShortEntryValue = 70; // Short Entry Level
|
||||
// input color xRSIShortEntryColor = clrRed; // Short Entry Level Color
|
||||
// input ENUM_LINE_STYLE xRSIShortEntryLineStyle = STYLE_SOLID; // Short Entry Style
|
||||
|
||||
// //
|
||||
// input group "XRSI Short Exit";
|
||||
// input double xRSIShortExitValue = 40; // Short Exit Level
|
||||
// input color xRSIShortExitColor = clrRed; // Short Exit Level Color
|
||||
// input ENUM_LINE_STYLE xRSIShortExitLineStyle = STYLE_DOT; // Short Exit Style
|
||||
|
||||
// //
|
||||
// input group "XRSI Long Entry";
|
||||
// input double xRSILongEntryValue = 30; // Long Entry Level
|
||||
// input color xRSILongEntryColor = clrRed; // Long Entry Level Color
|
||||
// input ENUM_LINE_STYLE xRSILongEntryLineStyle = STYLE_SOLID; // Long Entry Style
|
||||
|
||||
// //
|
||||
// input group "XRSI Long Exit";
|
||||
// input double xRSILongExitValue = 60; // Long Exit Level
|
||||
// input color xRSILongExitColor = clrRed; // Long Exit Level Color
|
||||
// input ENUM_LINE_STYLE xRSILongExitLineStyle = STYLE_DOT; // Long Exit Style
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xRSILength = 18; // Market Length
|
||||
ENUM_APPLIED_PRICE xRSIAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
//
|
||||
double xRSIShortEntryValue = 70; // Short Entry Level
|
||||
color xRSIShortEntryColor = clrRed; // Short Entry Level Color
|
||||
ENUM_LINE_STYLE xRSIShortEntryLineStyle = STYLE_SOLID; // Short Entry Style
|
||||
|
||||
//
|
||||
double xRSIShortExitValue = 40; // Short Exit Level
|
||||
color xRSIShortExitColor = clrRed; // Short Exit Level Color
|
||||
ENUM_LINE_STYLE xRSIShortExitLineStyle = STYLE_DOT; // Short Exit Style
|
||||
|
||||
//
|
||||
double xRSILongEntryValue = 30; // Long Entry Level
|
||||
color xRSILongEntryColor = clrRed; // Long Entry Level Color
|
||||
ENUM_LINE_STYLE xRSILongEntryLineStyle = STYLE_SOLID; // Long Entry Style
|
||||
|
||||
//
|
||||
double xRSILongExitValue = 60; // Long Exit Level
|
||||
color xRSILongExitColor = clrRed; // Long Exit Level Color
|
||||
ENUM_LINE_STYLE xRSILongExitLineStyle = STYLE_DOT; // Long Exit Style
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xRSIHandler = INVALID_HANDLE;
|
||||
double xRSIBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XRSIValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
xRSILongEntryValue < xRSILongExitValue &&
|
||||
xRSIShortEntryValue > xRSIShortExitValue &&
|
||||
xRSIShortEntryValue > xRSILongExitValue &&
|
||||
xRSIShortExitValue < xRSILongExitValue;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XRSI Oscillator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XRSIInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XRSI Handler ...
|
||||
ArraySetAsSeries(xRSIBuffer, true);
|
||||
xRSIHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xrsi.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
xRSILength,
|
||||
xRSIAppliedTo,
|
||||
//
|
||||
// Short Entry ...
|
||||
"",
|
||||
xRSIShortEntryValue,
|
||||
xRSIShortEntryColor,
|
||||
xRSIShortEntryLineStyle,
|
||||
//
|
||||
// Short Exit ...
|
||||
"",
|
||||
xRSIShortExitValue,
|
||||
xRSIShortExitColor,
|
||||
xRSIShortExitLineStyle,
|
||||
//
|
||||
// Long Entry ...
|
||||
"",
|
||||
xRSILongEntryValue,
|
||||
xRSILongEntryColor,
|
||||
xRSILongEntryLineStyle,
|
||||
//
|
||||
// Long Exit ...
|
||||
"",
|
||||
xRSILongExitValue,
|
||||
xRSILongExitColor,
|
||||
xRSILongExitLineStyle
|
||||
//
|
||||
);
|
||||
if (xRSIHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XRSI Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XRSIReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xRSIHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XRSIReadBuffers(
|
||||
int xRSIItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XRSI Signal ...
|
||||
CopyBuffer(
|
||||
xRSIHandler,
|
||||
0,
|
||||
0,
|
||||
xRSIItemsPerTick,
|
||||
xRSIBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XRSI Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check SC is Peak ...
|
||||
bool XRSIIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xRSIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check SC is Vale ...
|
||||
bool XRSIIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xRSIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value GO Up from Long Entry ...
|
||||
bool XRSIIsCrossedOverLongEntry(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] > xRSILongEntryValue &&
|
||||
xRSIBuffer[bar_index + 2] <= xRSILongEntryValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value GO Up from Long Exit ...
|
||||
bool XRSIIsCrossedOverLongExit(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] > xRSILongExitValue &&
|
||||
xRSIBuffer[bar_index + 2] <= xRSILongExitValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value Go Down Short Entry ...
|
||||
bool XRSIIsCrossedUnderShortEntry(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] < xRSIShortEntryValue &&
|
||||
xRSIBuffer[bar_index + 2] >= xRSIShortEntryValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value Go Down Short Exit ...
|
||||
bool XRSIIsCrossedUnderShortExit(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] < xRSIShortExitValue &&
|
||||
xRSIBuffer[bar_index + 2] >= xRSIShortExitValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XRSIIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xRSIBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XRSI Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,931 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTD Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XTD Oscillator States ...
|
||||
enum ENUM_X_XTD_STATES
|
||||
{
|
||||
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
|
||||
X_XTD_BULLISH_OVER_BEARISH = 1,
|
||||
X_XTD_NEUTURAL = 0,
|
||||
X_XTD_BULLISH_UNDER_BEARISH = -1,
|
||||
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
|
||||
};
|
||||
|
||||
//
|
||||
// XTD Oscillator Buffer Lines ...
|
||||
enum ENUM_X_XTD_BUFFER_LINES
|
||||
{
|
||||
X_XTD_BULLISH_POWER_LINE = 0,
|
||||
X_XTD_BEARISH_POWER_LINE = 1,
|
||||
X_XTD_SIGNAL_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XTD Oscillator";
|
||||
|
||||
// input int xTDLength = 18; // Market Length
|
||||
// input bool xTDDrawCrosses = false; // Draw Cross Arrows
|
||||
// input uchar xTDBullishArrowCode = 228; // Cross Over Arrow Code
|
||||
// input color xTDBullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||
// input uchar xTDBearishArrowCode = 230; // Cross Under Arrow Code
|
||||
// input color xTDBearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xTDLength = 18; // Market Length
|
||||
bool xTDDrawCrosses = false; // Draw Cross Arrows
|
||||
uchar xTDBullishArrowCode = 228; // Cross Over Arrow Code
|
||||
color xTDBullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||
uchar xTDBearishArrowCode = 230; // Cross Under Arrow Code
|
||||
color xTDBearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xTDHandler = INVALID_HANDLE;
|
||||
double xTDBullishBuffer[];
|
||||
double xTDBearishBuffer[];
|
||||
double xTDSignalBuffer[];
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XTDValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xTDLength >= 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XTD Oscillator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XTDInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XTD Handler ...
|
||||
ArraySetAsSeries(xTDBullishBuffer, true);
|
||||
ArraySetAsSeries(xTDBearishBuffer, true);
|
||||
ArraySetAsSeries(xTDSignalBuffer, true);
|
||||
xTDHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xtd.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
xTDLength,
|
||||
xTDDrawCrosses,
|
||||
xTDBullishArrowCode,
|
||||
xTDBullishArrowColor,
|
||||
xTDBearishArrowCode,
|
||||
xTDBearishArrowColor);
|
||||
if (xTDHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XTD Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XTDReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xTDHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XTDReadBuffers(
|
||||
int xTDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XTD Bullish Buffer ...
|
||||
CopyBuffer(
|
||||
xTDHandler,
|
||||
X_XTD_BULLISH_POWER_LINE,
|
||||
0,
|
||||
xTDItemsPerTick,
|
||||
xTDBullishBuffer);
|
||||
|
||||
//
|
||||
// XTD Bullish Buffer ...
|
||||
CopyBuffer(
|
||||
xTDHandler,
|
||||
X_XTD_BEARISH_POWER_LINE,
|
||||
0,
|
||||
xTDItemsPerTick,
|
||||
xTDBearishBuffer);
|
||||
|
||||
//
|
||||
// XTD Signal Buffer ...
|
||||
CopyBuffer(
|
||||
xTDHandler,
|
||||
X_XTD_SIGNAL_LINE,
|
||||
0,
|
||||
xTDItemsPerTick,
|
||||
xTDSignalBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XTD Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check Signal Vale ...
|
||||
bool XTDIsSignalVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDSignalBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
bool XTDIsSignalPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDSignalBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Vale ...
|
||||
bool XTDIsBullishVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBullishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
bool XTDIsBullishPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBullishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Vale ...
|
||||
bool XTDIsBearishVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBearishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
bool XTDIsBearishPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBearishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
|
||||
//
|
||||
// Check Bullish Crossed Over Bearish ...
|
||||
bool XTDIsBullCrossedOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossOver(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bullish Over Bearish ...
|
||||
bool XTDIsBullOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsOver(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bullish Crossed Under Bearish ...
|
||||
bool XTDIsBullCrossedUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossUnder(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bullish Under Bearish ...
|
||||
bool XTDIsBullUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsUnder(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Crossed Over Bearish ...
|
||||
bool XTDIsSignalCrossedOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossOver(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Over Bearish ...
|
||||
bool XTDIsSignalOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsOver(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Crossed Under Bearish ...
|
||||
bool XTDIsSignalCrossedUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossUnder(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Under Bearish ...
|
||||
bool XTDIsSignalUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsUnder(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XTDIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
ArraySize(xTDBullishBuffer) < size ||
|
||||
ArraySize(xTDBullishBuffer) < size ||
|
||||
ArraySize(xTDSignalBuffer) < size)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Signal Crossed Over Bear ...
|
||||
int XTDCountSignalCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Signal Crossed Under Bear ...
|
||||
int XTDCountSignalCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Bull Crossed Over Bear ...
|
||||
int XTDCountBullCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Bull Crossed Under Bear ...
|
||||
int XTDCountBullCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Signal Crossed Over Bear ...
|
||||
int XTDFindLastSignalCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Signal Crossed Onder Bear ...
|
||||
int XTDFindLastSignalCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Bull Crossed Over Bear ...
|
||||
int XTDFindLastBullCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Bull Crossed Under Bear ...
|
||||
int XTDFindLastBullCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XTD Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,598 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTM Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XTM Indicator States ...
|
||||
enum ENUM_X_XTM_STATES
|
||||
{
|
||||
X_XTM_BULLISH = 1,
|
||||
X_XTM_BEARISH = -1,
|
||||
X_XTM_NEUTURAL = 0,
|
||||
};
|
||||
|
||||
//
|
||||
// XTM Indicator Buffer Lines ...
|
||||
enum ENUM_X_XTM_BUFFER_LINES
|
||||
{
|
||||
X_XTM_MA_LINE = 0,
|
||||
X_XTM_MC_COLOR_LINE = 1,
|
||||
X_XTM_STATE_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XTM Indicator";
|
||||
|
||||
// input int xTMMaPeriod = 18; // Period
|
||||
// input int xTMMaShift = 0; // Shift
|
||||
// input ENUM_MA_METHOD xTMMaMethod = MODE_EMA; // Method
|
||||
// input ENUM_APPLIED_PRICE xTMMaAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xTMMaPeriod = 18; // Period
|
||||
int xTMMaShift = 0; // Shift
|
||||
ENUM_MA_METHOD xTMMaMethod = MODE_EMA; // Method
|
||||
ENUM_APPLIED_PRICE xTMMaAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xTMHandler = INVALID_HANDLE;
|
||||
double xTMMaBuffer[];
|
||||
double xTMStateBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XTMValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xTMMaPeriod >= 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XTM Indicator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XTMInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XTM Handler ...
|
||||
ArraySetAsSeries(xTMMaBuffer, true);
|
||||
ArraySetAsSeries(xTMStateBuffer, true);
|
||||
xTMHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xtm.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xTMMaPeriod,
|
||||
xTMMaShift,
|
||||
xTMMaMethod,
|
||||
xTMMaAppliedTo);
|
||||
if (xTMHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XTM Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XTMReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xTMHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XTMReadBuffers(
|
||||
int xTMItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// Ma Buffer ...
|
||||
CopyBuffer(
|
||||
xTMHandler,
|
||||
X_XTM_MA_LINE,
|
||||
0,
|
||||
xTMItemsPerTick,
|
||||
xTMMaBuffer);
|
||||
|
||||
//
|
||||
// State Buffer ...
|
||||
CopyBuffer(
|
||||
xTMHandler,
|
||||
X_XTM_STATE_LINE,
|
||||
0,
|
||||
xTMItemsPerTick,
|
||||
xTMStateBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XTM Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Find Peak based On this Indicator ...
|
||||
bool XTMIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTMMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Vale based On this Indicator ...
|
||||
bool XTMIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTMMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up ...
|
||||
bool XTMIsStartBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BULLISH &&
|
||||
xTMStateBuffer[bar_index + 1] != X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up After Neutural State ...
|
||||
bool XTMIsStartBullishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BULLISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Up State ...
|
||||
bool XTMIsBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State ...
|
||||
bool XTMIsEndBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] != X_XTM_BULLISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State By Neutural ...
|
||||
bool XTMIsEndBullishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down ...
|
||||
bool XTMIsStartBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BEARISH &&
|
||||
xTMStateBuffer[bar_index + 1] != X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down After Neutural State ...
|
||||
bool XTMIsStartBearishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BEARISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Down State ...
|
||||
bool XTMIsBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State ...
|
||||
bool XTMIsEndBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] != X_XTM_BEARISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State By Neutural ...
|
||||
bool XTMIsEndBearishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Neutural State ...
|
||||
bool XTMIsNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XTMIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xTMMaBuffer) < size ||
|
||||
ArraySize(xTMStateBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XTM Custom Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,353 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XAMA Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XAMA
|
||||
// Description: Trend Magic Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XAMA"
|
||||
|
||||
//
|
||||
// XAMA Indicator States ...
|
||||
enum ENUM_X_XAMA_STATES
|
||||
{
|
||||
X_XAMA_BULLISH = 1,
|
||||
X_XAMA_BEARISH = -1,
|
||||
X_XAMA_NEUTURAL = 0,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 18; // Period
|
||||
input int fastEMA = 2; // Fast EMA Period
|
||||
input int slowEMA = 30; // Slow EMA Period
|
||||
input int maShift = 0; // Shift
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
#define maColorBufferIndex 1
|
||||
#define stateBufferIndex 2
|
||||
|
||||
double maBuffer[];
|
||||
double maColorBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
#property indicator_label1 "XAMA"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
int maHandler = INVALID_HANDLE;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// Initializing MA Handler ...
|
||||
maHandler = iAMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
fastEMA,
|
||||
slowEMA,
|
||||
maShift,
|
||||
appliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Ma Handler ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(maHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(fastEMA, slowEMA);
|
||||
maxLength = MathMax(maxLength, length);
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
string maBufferLabel = "XAMA " + "(" + (string)length + ")";
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// State Buffer ...
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "(", length, ")");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Define State Value ...
|
||||
// lineColorIndex == 0 => Bullish => 1;
|
||||
// lineColorIndex == 1 => Neutural => 0;
|
||||
// lineColorIndex == 2 => Bearish => -1;
|
||||
double stateValue =
|
||||
lineColorIndex == 0 ? X_XAMA_BULLISH : lineColorIndex == 2 ? X_XAMA_BEARISH
|
||||
: X_XAMA_NEUTURAL;
|
||||
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = lineColorIndex;
|
||||
|
||||
//
|
||||
// Set State Buffer Value ...
|
||||
stateBuffer[bar_index] = stateValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,753 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Cycle Channel LH Oscillator
|
||||
// ---------------------------------------------------
|
||||
// Name: XCHLH
|
||||
// Description: detecting HH and LL based on cycles ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XCHLH Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XCHLH"
|
||||
|
||||
//
|
||||
// XCHLH Hot States ...
|
||||
enum ENUM_X_XCHLH_HOT_STATES
|
||||
{
|
||||
X_XCHLH_HOT_HH = 1,
|
||||
X_XCHLH_NEUTURAL = 0,
|
||||
X_XCHLH_HOT_LL = -1,
|
||||
};
|
||||
|
||||
//
|
||||
// Including Models Library ...
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Common ...
|
||||
input group "Hot Areas";
|
||||
input bool drawHotAreas = true; // Draw Hot Areas Symbol
|
||||
input uchar hotHHArrowCode = 234; // Hot HH Arrow Code
|
||||
input color hotHHArrowColor = clrAqua; // Hot HH Arrow Color
|
||||
input uchar hotLLArrowCode = 233; // Hot LL Arrow Code
|
||||
input color hotLLArrowColor = clrFuchsia; // Hot LL Arrow Color
|
||||
|
||||
//
|
||||
// LC Inputs ...
|
||||
input group "Long Cycle";
|
||||
input group "LC Market";
|
||||
input int lcLength = 28; // Length
|
||||
input double lcThresholdInPips = 0.3; // Threshold In Pips
|
||||
input ENUM_SERIESMODE lcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE lcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input group "LC Style";
|
||||
input int lcDrawWidth = 1; // Draw Width
|
||||
input ENUM_DRAW_TYPE lcDrawType = DRAW_LINE; // Draw Type
|
||||
input ENUM_LINE_STYLE lcDrawStyle = STYLE_DOT; // Draw Style
|
||||
input color lcHHColor = clrAqua; // Highest High Color
|
||||
input color lcLLColor = clrFuchsia; // Lowest Low Color
|
||||
input group "LC Drawings";
|
||||
input bool lcDrawHH = true; // Draw Highest High
|
||||
input bool lcDrawLL = true; // Draw Lowest Low
|
||||
|
||||
//
|
||||
// MC Inputs ...
|
||||
input group "Medium Cycle";
|
||||
input group "MC Market";
|
||||
input int mcLength = 14; // Length
|
||||
input double mcThresholdInPips = 0.3; // Threshold In Pips
|
||||
input ENUM_SERIESMODE mcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE mcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input group "MC Style";
|
||||
input int mcDrawWidth = 1; // Draw Width
|
||||
input ENUM_DRAW_TYPE mcDrawType = DRAW_LINE; // Draw Type
|
||||
input ENUM_LINE_STYLE mcDrawStyle = STYLE_DOT; // Draw Style
|
||||
input color mcHHColor = clrLime; // Highest High Color
|
||||
input color mcLLColor = clrRed; // Lowest Low Color
|
||||
input group "MC Drawings";
|
||||
input bool mcDrawHH = true; // Draw Highest High
|
||||
input bool mcDrawLL = true; // Draw Lowest Low
|
||||
|
||||
//
|
||||
// SC Inputs ...
|
||||
input group "Short Cycle";
|
||||
input group "SC Market";
|
||||
input int scLength = 7; // Length
|
||||
input double scThresholdInPips = 0.3; // Threshold In Pips
|
||||
input ENUM_SERIESMODE scHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE scLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input group "SC Style";
|
||||
input int scDrawWidth = 1; // Draw Width
|
||||
input ENUM_DRAW_TYPE scDrawType = DRAW_LINE; // Draw Type
|
||||
input ENUM_LINE_STYLE scDrawStyle = STYLE_DOT; // Draw Style
|
||||
input color scHHColor = clrLightBlue; // Highest High Color
|
||||
input color scLLColor = clrLightSalmon; // Lowest Low Color
|
||||
input group "SC Drawings";
|
||||
input bool scDrawHH = true; // Draw Highest High
|
||||
input bool scDrawLL = true; // Draw Lowest Low
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// LC ...
|
||||
#define lcHHBufferIndex 0
|
||||
#define lcLLBufferIndex 1
|
||||
|
||||
//
|
||||
double lcHHBuffer[];
|
||||
double lcLLBuffer[];
|
||||
|
||||
//
|
||||
// MC ...
|
||||
#define mcHHBufferIndex 2
|
||||
#define mcLLBufferIndex 3
|
||||
|
||||
//
|
||||
double mcHHBuffer[];
|
||||
double mcLLBuffer[];
|
||||
|
||||
//
|
||||
// SC ...
|
||||
#define scHHBufferIndex 4
|
||||
#define scLLBufferIndex 5
|
||||
|
||||
//
|
||||
double scHHBuffer[];
|
||||
double scLLBuffer[];
|
||||
|
||||
//
|
||||
// Hot State ...
|
||||
//
|
||||
#define hotStateBufferIndex 6
|
||||
|
||||
//
|
||||
double hotStateBuffer[];
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
// ReDraw Chart ...
|
||||
ChartRedraw();
|
||||
|
||||
//
|
||||
// De Init Draw Library ...
|
||||
OnDeinitDrawLibrary();
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(lcLength, mcLength);
|
||||
maxLength = MathMax(maxLength, scLength);
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
bool isLCInputsValid =
|
||||
lcLength >= 4 &&
|
||||
lcLength > mcLength &&
|
||||
lcLength > scLength;
|
||||
bool isMCInputsValid =
|
||||
mcLength >= 4 &&
|
||||
mcLength > scLength &&
|
||||
mcLength < lcLength;
|
||||
bool isSCInputsValid =
|
||||
scLength >= 4 &&
|
||||
scLength < mcLength &&
|
||||
scLength < lcLength;
|
||||
if (
|
||||
isLCInputsValid &&
|
||||
isMCInputsValid &&
|
||||
isSCInputsValid)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// LC ...
|
||||
LCDefineBuffers();
|
||||
|
||||
//
|
||||
// MC ...
|
||||
MCDefineBuffers();
|
||||
|
||||
//
|
||||
// SC ...
|
||||
SCDefineBuffers();
|
||||
|
||||
//
|
||||
// Hot State Buffer ...
|
||||
HotStateDefineBuffers();
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, "");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// LC ...
|
||||
LCCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// MC ...
|
||||
MCCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// SC ...
|
||||
SCCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// SIGNAL ...
|
||||
SignalCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// HOT State Buffer ...
|
||||
HotStateCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// After all Calculations we are ready to Draw what we want ...
|
||||
DrawBuffers(bar_index);
|
||||
}
|
||||
|
||||
//
|
||||
// LC Buffers Definitions ...
|
||||
void LCDefineBuffers()
|
||||
{
|
||||
//
|
||||
// LC HH Buffer ...
|
||||
string lcHHBufferLabel = ShortName + " LC HH (" + (string)lcLength + ")";
|
||||
ENUM_DRAW_TYPE lcHHDrawType = lcDrawHH ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(lcHHBuffer, true);
|
||||
SetIndexBuffer(lcHHBufferIndex, lcHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_DRAW_BEGIN, lcLength);
|
||||
PlotIndexSetString(lcHHBufferIndex, PLOT_LABEL, lcHHBufferLabel);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_LINE_COLOR, lcHHColor);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_LINE_STYLE, lcDrawStyle);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_LINE_WIDTH, lcDrawWidth);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_DRAW_TYPE, lcHHDrawType);
|
||||
|
||||
//
|
||||
// LC LL Buffer ...
|
||||
string lcLLBufferLabel = ShortName + " LC LL (" + (string)lcLength + ")";
|
||||
ENUM_DRAW_TYPE lcLLDrawType = lcDrawLL ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(lcLLBuffer, true);
|
||||
SetIndexBuffer(lcLLBufferIndex, lcLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_DRAW_BEGIN, lcLength);
|
||||
PlotIndexSetString(lcLLBufferIndex, PLOT_LABEL, lcLLBufferLabel);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_LINE_COLOR, lcLLColor);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_LINE_STYLE, lcDrawStyle);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_LINE_WIDTH, lcDrawWidth);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_DRAW_TYPE, lcLLDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// MC Buffers Definitions ...
|
||||
void MCDefineBuffers()
|
||||
{
|
||||
//
|
||||
// MC HH Buffer ...
|
||||
string mcHHBufferLabel = ShortName + " MC HH (" + (string)mcLength + ")";
|
||||
ENUM_DRAW_TYPE mcHHDrawType = mcDrawHH ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(mcHHBuffer, true);
|
||||
SetIndexBuffer(mcHHBufferIndex, mcHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_DRAW_BEGIN, mcLength);
|
||||
PlotIndexSetString(mcHHBufferIndex, PLOT_LABEL, mcHHBufferLabel);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_LINE_COLOR, mcHHColor);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_LINE_STYLE, mcDrawStyle);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_LINE_WIDTH, mcDrawWidth);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_DRAW_TYPE, mcHHDrawType);
|
||||
|
||||
//
|
||||
// MC LL Buffer ...
|
||||
string mcLLBufferLabel = ShortName + " MC LL (" + (string)mcLength + ")";
|
||||
ENUM_DRAW_TYPE mcLLDrawType = mcDrawLL ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(mcLLBuffer, true);
|
||||
SetIndexBuffer(mcLLBufferIndex, mcLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_DRAW_BEGIN, mcLength);
|
||||
PlotIndexSetString(mcLLBufferIndex, PLOT_LABEL, mcLLBufferLabel);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_LINE_COLOR, mcLLColor);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_LINE_STYLE, mcDrawStyle);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_LINE_WIDTH, mcDrawWidth);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_DRAW_TYPE, mcLLDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// SC Buffers Definitions ...
|
||||
void SCDefineBuffers()
|
||||
{
|
||||
//
|
||||
// SC HH Buffer ...
|
||||
string scHHBufferLabel = ShortName + " SC HH (" + (string)scLength + ")";
|
||||
ENUM_DRAW_TYPE scHHDrawType = scDrawHH ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(scHHBuffer, true);
|
||||
SetIndexBuffer(scHHBufferIndex, scHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_DRAW_BEGIN, scLength);
|
||||
PlotIndexSetString(scHHBufferIndex, PLOT_LABEL, scHHBufferLabel);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_LINE_COLOR, scHHColor);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_LINE_STYLE, scDrawStyle);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_LINE_WIDTH, scDrawWidth);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_DRAW_TYPE, scHHDrawType);
|
||||
|
||||
//
|
||||
// SC LL Buffer ...
|
||||
string scLLBufferLabel = ShortName + " SC LL (" + (string)scLength + ")";
|
||||
ENUM_DRAW_TYPE scLLDrawType = scDrawLL ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(scLLBuffer, true);
|
||||
SetIndexBuffer(scLLBufferIndex, scLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_DRAW_BEGIN, scLength);
|
||||
PlotIndexSetString(scLLBufferIndex, PLOT_LABEL, scLLBufferLabel);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_LINE_COLOR, scLLColor);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_LINE_STYLE, scDrawStyle);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_LINE_WIDTH, scDrawWidth);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_DRAW_TYPE, scLLDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Hot State Buffer ...
|
||||
void HotStateDefineBuffers()
|
||||
{
|
||||
//
|
||||
// Hot State Buffer ...
|
||||
ArraySetAsSeries(hotStateBuffer, true);
|
||||
SetIndexBuffer(hotStateBufferIndex, hotStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// LC Calculations ...
|
||||
void LCCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Detect Cycle HH and LL ...
|
||||
int length = lcLength;
|
||||
ENUM_SERIESMODE hhMode = lcHHMode;
|
||||
ENUM_SERIESMODE llMode = lcLLMode;
|
||||
double threshold = PipsToPrice(lcThresholdInPips);
|
||||
double hh = GetHighestHigh(
|
||||
length,
|
||||
bar_index,
|
||||
hhMode);
|
||||
double hhValue = hh + threshold;
|
||||
double ll = GetLowestLow(
|
||||
length,
|
||||
bar_index,
|
||||
llMode);
|
||||
double llValue = ll - threshold;
|
||||
|
||||
//
|
||||
lcHHBuffer[bar_index] = hhValue;
|
||||
lcLLBuffer[bar_index] = llValue;
|
||||
}
|
||||
|
||||
//
|
||||
// MC Calculations ...
|
||||
void MCCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Detect Cycle HH and LL ...
|
||||
int length = mcLength;
|
||||
ENUM_SERIESMODE hhMode = mcHHMode;
|
||||
ENUM_SERIESMODE llMode = mcLLMode;
|
||||
double threshold = PipsToPrice(mcThresholdInPips);
|
||||
double hh = GetHighestHigh(
|
||||
length,
|
||||
bar_index,
|
||||
hhMode);
|
||||
double hhValue = hh + threshold;
|
||||
double ll = GetLowestLow(
|
||||
length,
|
||||
bar_index,
|
||||
llMode);
|
||||
double llValue = ll - threshold;
|
||||
|
||||
//
|
||||
mcHHBuffer[bar_index] = hhValue;
|
||||
mcLLBuffer[bar_index] = llValue;
|
||||
}
|
||||
|
||||
//
|
||||
// SC Calculations ...
|
||||
void SCCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Detect Cycle HH and LL ...
|
||||
int length = scLength;
|
||||
ENUM_SERIESMODE hhMode = scHHMode;
|
||||
ENUM_SERIESMODE llMode = scLLMode;
|
||||
double threshold = PipsToPrice(scThresholdInPips);
|
||||
double hh = GetHighestHigh(
|
||||
length,
|
||||
bar_index,
|
||||
hhMode);
|
||||
double hhValue = hh + threshold;
|
||||
double ll = GetLowestLow(
|
||||
length,
|
||||
bar_index,
|
||||
llMode);
|
||||
double llValue = ll - threshold;
|
||||
|
||||
//
|
||||
scHHBuffer[bar_index] = hhValue;
|
||||
scLLBuffer[bar_index] = llValue;
|
||||
}
|
||||
|
||||
//
|
||||
// SIGNAL Calculations ...
|
||||
void SignalCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// LC Values ...
|
||||
double lcHH = lcHHBuffer[bar_index];
|
||||
double lcLL = lcLLBuffer[bar_index];
|
||||
double lcDelta = lcHH - lcLL;
|
||||
double lcAvg = lcDelta / 2;
|
||||
|
||||
//
|
||||
// MC Values ...
|
||||
double mcHH = mcHHBuffer[bar_index];
|
||||
double mcLL = mcLLBuffer[bar_index];
|
||||
double mcDelta = mcHH - mcLL;
|
||||
double mcAvg = mcDelta / 2;
|
||||
|
||||
//
|
||||
// SC Values ...
|
||||
double scHH = scHHBuffer[bar_index];
|
||||
double scLL = scLLBuffer[bar_index];
|
||||
double scDelta = scHH - scLL;
|
||||
double scAvg = scDelta / 2;
|
||||
|
||||
//
|
||||
// Min Value ...
|
||||
double minValue = MathMin(
|
||||
scLL, mcLL);
|
||||
minValue = MathMin(
|
||||
lcLL, minValue);
|
||||
|
||||
//
|
||||
// Max Value ...
|
||||
double maxValue = MathMin(
|
||||
scHH, mcHH);
|
||||
maxValue = MathMin(
|
||||
lcHH, maxValue);
|
||||
}
|
||||
|
||||
//
|
||||
// HOT State Calculate Buffers ...
|
||||
void HotStateCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// LC ...
|
||||
double lcHH = lcHHBuffer[bar_index];
|
||||
double lcLL = lcLLBuffer[bar_index];
|
||||
//
|
||||
double lcHH1 = lcHHBuffer[bar_index + 1];
|
||||
double lcLL1 = lcLLBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
// MC ...
|
||||
double mcHH = mcHHBuffer[bar_index];
|
||||
double mcLL = mcLLBuffer[bar_index];
|
||||
//
|
||||
double mcHH1 = mcHHBuffer[bar_index + 1];
|
||||
double mcLL1 = mcLLBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
// SC ...
|
||||
double scHH = scHHBuffer[bar_index];
|
||||
double scLL = scLLBuffer[bar_index];
|
||||
//
|
||||
double scHH1 = scHHBuffer[bar_index + 1];
|
||||
double scLL1 = scLLBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
bool isHotLLState = scLL == mcLL && mcLL == lcLL;
|
||||
bool isHotLLState1 = scLL1 == mcLL1 && mcLL1 == lcLL1;
|
||||
//
|
||||
bool isHotHHState = scHH == mcHH && mcHH == lcHH;
|
||||
bool isHotHHState1 = scHH1 == mcHH1 && mcHH1 == lcHH1;
|
||||
|
||||
//
|
||||
bool isHotLL = isHotLLState && !isHotLLState1;
|
||||
bool isHotHH = isHotHHState && !isHotHHState1;
|
||||
|
||||
//
|
||||
double hotStateValue = X_XCHLH_NEUTURAL;
|
||||
if (isHotHH)
|
||||
{
|
||||
hotStateValue = X_XCHLH_HOT_HH;
|
||||
}
|
||||
else if (isHotLL)
|
||||
{
|
||||
hotStateValue = X_XCHLH_HOT_LL;
|
||||
}
|
||||
|
||||
//
|
||||
hotStateBuffer[bar_index] = hotStateValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Buffers ...
|
||||
void DrawBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// General Requirements ...
|
||||
|
||||
//
|
||||
// Retrieve Candle Model ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
datetime time = iTime(_Symbol, _Period, bar_index);
|
||||
|
||||
//
|
||||
// Draw Arrow on Hot Areas ...
|
||||
if (drawHotAreas)
|
||||
{
|
||||
//
|
||||
double hotStateValue = hotStateBuffer[bar_index];
|
||||
bool isHotHHArea = hotStateValue == 1;
|
||||
bool isHotLLArea = hotStateValue == -1;
|
||||
if (isHotHHArea || isHotLLArea)
|
||||
{
|
||||
//
|
||||
bool isHH = isHotHHArea;
|
||||
|
||||
//
|
||||
double price = isHH ? candle.high : candle.low;
|
||||
ENUM_ARROW_ANCHOR anchor = isHH ? ANCHOR_BOTTOM : ANCHOR_TOP;
|
||||
color clr = isHH ? hotHHArrowColor : hotLLArrowColor;
|
||||
uchar arrowCode = isHH ? hotHHArrowCode : hotLLArrowCode;
|
||||
string name = "HOT " + (isHH ? "HH" : "LL") + "_" + (string)price + "_" + (string)time;
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
0,
|
||||
name,
|
||||
0,
|
||||
time,
|
||||
price,
|
||||
arrowCode,
|
||||
anchor,
|
||||
clr,
|
||||
STYLE_SOLID,
|
||||
1);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,317 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XFI Oscillator
|
||||
// ---------------------------------------------
|
||||
// Name: XFI
|
||||
// Description: Price Momentum Power Detection
|
||||
// Market Analysor ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XFI Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XFI"
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 18; // Length
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // MA Method
|
||||
input ENUM_APPLIED_VOLUME appliedTo = VOLUME_TICK; // Applied To
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// FI Buffer ...
|
||||
#define fiBufferIndex 0
|
||||
#define fiColorBufferIndex 1
|
||||
|
||||
//
|
||||
double fiBuffer[];
|
||||
double fiColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XFI"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrAqua, clrGray, clrFuchsia
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
int fiHandler = INVALID_HANDLE;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
fiHandler = iForce(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
method,
|
||||
appliedTo);
|
||||
if (fiHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Handler ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(fiHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int fiCalculatedBars = BarsCalculated(fiHandler);
|
||||
if (fiCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedFis = CopyBuffer(fiHandler, 0, 0, limit, fiBuffer);
|
||||
if (copiedFis <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = 0; i < limit && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
string fiBufferLabel = "XFI " + "(" + (string)length + ")";
|
||||
|
||||
//
|
||||
// FI Buffer ...
|
||||
ArraySetAsSeries(fiBuffer, true);
|
||||
SetIndexBuffer(fiBufferIndex, fiBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetString(fiBufferIndex, PLOT_LABEL, fiBufferLabel);
|
||||
|
||||
//
|
||||
// FI Color Buffer ...
|
||||
ArraySetAsSeries(fiColorBuffer, true);
|
||||
SetIndexBuffer(fiColorBufferIndex, fiColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, "");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
double iValue = fiBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iColorIndex =
|
||||
iValue > 0 ? 0 : iValue < 0 ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Set Buffer Color Index ...
|
||||
fiColorBuffer[bar_index] = iColorIndex;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,346 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XLH Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XLH
|
||||
// Description: Moving Average Indicator
|
||||
// Market Analysor ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XLH Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XLH"
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 14; // Length
|
||||
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// HH Buffer ...
|
||||
#define hhBufferIndex 0
|
||||
|
||||
//
|
||||
double hhBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XLH HH"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// LL Buffer ...
|
||||
#define llBufferIndex 1
|
||||
|
||||
//
|
||||
double llBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XLH LL"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrFuchsia
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
#define signalBufferIndex 2
|
||||
|
||||
//
|
||||
double signalBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XLH S"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrGold
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// HH Buffer ...
|
||||
string hhBufferLabel = ShortName + " HH " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(hhBuffer, true);
|
||||
SetIndexBuffer(hhBufferIndex, hhBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(hhBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(hhBufferIndex, PLOT_LABEL, hhBufferLabel);
|
||||
|
||||
//
|
||||
// LL Buffer ...
|
||||
string llBufferLabel = ShortName + " LL " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(llBuffer, true);
|
||||
SetIndexBuffer(llBufferIndex, llBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(llBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(llBufferIndex, PLOT_LABEL, llBufferLabel);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
string signalBufferLabel = ShortName + " S " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(signalBuffer, true);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, "");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate Threshold ...
|
||||
//
|
||||
// HH Buffer ...
|
||||
int hhIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
length,
|
||||
bar_index);
|
||||
double hhValue = GetAppliedPrice(
|
||||
hhIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
hhBuffer[bar_index] = hhValue;
|
||||
|
||||
//
|
||||
// LL Buffer ...
|
||||
int llIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
length,
|
||||
bar_index);
|
||||
double llValue = GetAppliedPrice(
|
||||
llIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
llBuffer[bar_index] = llValue;
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(bar_index);
|
||||
double lhDiff = hhValue - llValue;
|
||||
double signalValue = (lhDiff / 2);
|
||||
|
||||
//
|
||||
signalBuffer[bar_index] = (hhValue - signalValue);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,390 @@
|
||||
/////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 OrderBlock Detector Indicator
|
||||
// -----------------------------------------------------
|
||||
// Name: XOBD
|
||||
// Description: detect Order Blocks based on Swings ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XOBD Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XOBD"
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
input int length = 5; // Swing Length
|
||||
|
||||
//
|
||||
input uchar swingHighArrowCode = 108; // Swing High Arrow Code
|
||||
input color swingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
||||
|
||||
//
|
||||
input uchar swingLowArrowCode = 108; // Swing Low Arrow Code
|
||||
input color swingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Include Common and Models Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Include Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
#define swingBufferIndex 0
|
||||
double swingBuffer[];
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
OnDeinitDrawLibrary();
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length * 3);
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(swingBuffer, true);
|
||||
SetIndexBuffer(swingBufferIndex, swingBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// GetCandleSwing(bar_index);
|
||||
ENUM_X_SWING_TYPE type = X_NO_SWING;
|
||||
|
||||
//
|
||||
// Try To Detect Order Blocks ...
|
||||
bool isSwingLow = false;
|
||||
bool isSwingHigh = false;
|
||||
|
||||
//
|
||||
// Reading Candles Data ...
|
||||
XOHCL candles[];
|
||||
for (int i = bar_index; i < bar_index + ((length * 2) + 2); i++)
|
||||
{
|
||||
//
|
||||
XOHCL iCandle = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
i);
|
||||
|
||||
//
|
||||
Add(
|
||||
iCandle,
|
||||
candles);
|
||||
}
|
||||
|
||||
//
|
||||
// Swing Low ...
|
||||
isSwingLow =
|
||||
//
|
||||
candles[1].close > candles[2].close &&
|
||||
candles[2].close > candles[3].close &&
|
||||
//
|
||||
candles[3].close < candles[4].close &&
|
||||
//
|
||||
candles[5].close > candles[4].close &&
|
||||
candles[6].close > candles[5].close
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (isSwingLow)
|
||||
{
|
||||
type = X_SWING_LOW;
|
||||
}
|
||||
|
||||
//
|
||||
if (!isSwingLow)
|
||||
{
|
||||
//
|
||||
// Swing High ...
|
||||
isSwingHigh =
|
||||
//
|
||||
candles[1].close < candles[2].close &&
|
||||
candles[2].close < candles[3].close &&
|
||||
//
|
||||
candles[3].close > candles[4].close &&
|
||||
//
|
||||
candles[5].close < candles[4].close &&
|
||||
candles[6].close < candles[5].close
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (isSwingHigh)
|
||||
{
|
||||
type = X_SWING_HIGH;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
switch (type)
|
||||
{
|
||||
//
|
||||
// Swing High ...
|
||||
case X_SWING_HIGH:
|
||||
//
|
||||
swingBuffer[bar_index] = type;
|
||||
DrawSwingArrow(1, bar_index);
|
||||
break;
|
||||
|
||||
//
|
||||
// Swinmg Low ...
|
||||
case X_SWING_LOW:
|
||||
//
|
||||
swingBuffer[bar_index] = type;
|
||||
DrawSwingArrow(0, bar_index);
|
||||
break;
|
||||
|
||||
//
|
||||
// No Swing ...
|
||||
default:
|
||||
case X_NO_SWING:
|
||||
//
|
||||
swingBuffer[bar_index] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw a Swing Arrow Shape ...
|
||||
void DrawSwingArrow(
|
||||
int type, // Swing Type: 0 - Low / 1 - High ...
|
||||
int bar_index)
|
||||
{
|
||||
//
|
||||
bool isSwingHigh = type == 1;
|
||||
XOHCL candle = GetCandle(bar_index + 3);
|
||||
double arrowDistanceInPoint = 0;
|
||||
|
||||
//
|
||||
// Define Required Object Properties fro Draw an Arrow ...
|
||||
datetime time = iTime(_Symbol, _Period, bar_index + 3);
|
||||
double purePrice = isSwingHigh ? candle.high : candle.low;
|
||||
color clr = isSwingHigh ? swingHighArrowColor : swingLowArrowColor;
|
||||
ENUM_ARROW_ANCHOR anchor = isSwingHigh ? ANCHOR_BOTTOM : ANCHOR_TOP;
|
||||
uchar arrowCode = uchar(isSwingHigh ? swingHighArrowCode : swingLowArrowCode);
|
||||
double price = isSwingHigh ? purePrice + arrowDistanceInPoint : purePrice - arrowDistanceInPoint;
|
||||
string name = "Swing " + (isSwingHigh ? "High" : "Low") + "_" + (string)time + "_" + (string)purePrice;
|
||||
|
||||
//
|
||||
// Draw desired Arrow ...
|
||||
DrawArrow(
|
||||
0,
|
||||
name,
|
||||
0,
|
||||
time,
|
||||
price,
|
||||
arrowCode,
|
||||
anchor,
|
||||
clr);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,397 @@
|
||||
/////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 OrderBlock Detector Oscillator
|
||||
// ------------------------------------------------------
|
||||
// Name: XRSI
|
||||
// Description: detect market conditions based on RSI ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XRSI Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "XRSI"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 14; // Market Length
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Short Entry";
|
||||
input double shortEntryValue = 70; // Short Entry Level
|
||||
input color shortEntryColor = clrRed; // Short Entry Level Color
|
||||
input ENUM_LINE_STYLE shortEntryLineStyle = STYLE_DOT; // Short Entry Style
|
||||
|
||||
//
|
||||
input group "Short Exit";
|
||||
input double shortExitValue = 40; // Short Exit Level
|
||||
input color shortExitColor = clrRed; // Short Exit Level Color
|
||||
input ENUM_LINE_STYLE shortExitLineStyle = STYLE_DOT; // Short Exit Style
|
||||
|
||||
//
|
||||
input group "Long Entry";
|
||||
input double longEntryValue = 30; // Long Entry Level
|
||||
input color longEntryColor = clrRed; // Long Entry Level Color
|
||||
input ENUM_LINE_STYLE longEntryLineStyle = STYLE_DOT; // Long Entry Style
|
||||
|
||||
//
|
||||
input group "Long Exit";
|
||||
input double longExitValue = 60; // Long Exit Level
|
||||
input color longExitColor = clrRed; // Long Exit Level Color
|
||||
input ENUM_LINE_STYLE longExitLineStyle = STYLE_DOT; // Long Exit Style
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Include Common and Models Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
#define rsiBufferIndex 0
|
||||
#define rsiColorBufferIndex 1
|
||||
|
||||
//
|
||||
double rsiBuffer[];
|
||||
double rsiColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XRSI"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrAqua, clrGray, clrFuchsia
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
rsiHandler = iRSI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
appliedTo);
|
||||
if (rsiHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
IndicatorRelease(rsiHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
||||
if (rsiCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
int rsiCopiedItems = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
||||
if (rsiCopiedItems <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// RSI ...
|
||||
string rsiBufferLabel = ShortName + " (" + (string)length + ")";
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(rsiBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(rsiBufferIndex, PLOT_LABEL, rsiBufferLabel);
|
||||
|
||||
//
|
||||
// RSI Color Buffer ...
|
||||
ArraySetAsSeries(rsiColorBuffer, true);
|
||||
SetIndexBuffer(rsiColorBufferIndex, rsiColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Set Indicator Levels here ...
|
||||
// OB, ExitLong, ExitShort, OS ...
|
||||
IndicatorSetInteger(INDICATOR_LEVELS, 4);
|
||||
|
||||
//
|
||||
// SHORTENTRY ...
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, shortEntryValue);
|
||||
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 0, shortEntryColor);
|
||||
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 0, shortEntryLineStyle);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT, 0, "Short Entry");
|
||||
|
||||
//
|
||||
// LONGEXIT ...
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, longExitValue);
|
||||
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 1, longExitColor);
|
||||
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 1, shortExitLineStyle);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT, 1, "Long Exit");
|
||||
|
||||
//
|
||||
// SHORTEXIT ...
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 2, shortExitValue);
|
||||
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 2, shortExitColor);
|
||||
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 2, longEntryLineStyle);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT, 2, "Short Exit");
|
||||
|
||||
//
|
||||
// LONGENTRY ...
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 3, longEntryValue);
|
||||
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 3, longEntryColor);
|
||||
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 3, longExitLineStyle);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT, 3, "Long Entry");
|
||||
|
||||
//
|
||||
// Set Maximum and Minimum for subwindow
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
IndicatorSetDouble(INDICATOR_MINIMUM, 0);
|
||||
IndicatorSetDouble(INDICATOR_MAXIMUM, 100);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
double iValue = rsiBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iColorIndex = 0;
|
||||
|
||||
//
|
||||
if (
|
||||
iValue >= shortEntryValue ||
|
||||
iValue <= longEntryValue ||
|
||||
(iValue < longExitValue &&
|
||||
iValue > shortExitValue))
|
||||
{
|
||||
iColorIndex = 0;
|
||||
}
|
||||
else if (
|
||||
iValue <= shortEntryValue &&
|
||||
iValue >= longExitValue)
|
||||
{
|
||||
iColorIndex = 2;
|
||||
}
|
||||
else if (
|
||||
iValue < shortExitValue &&
|
||||
iValue > longEntryValue)
|
||||
{
|
||||
iColorIndex = 1;
|
||||
}
|
||||
|
||||
//
|
||||
rsiColorBuffer[bar_index] = iColorIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,465 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Trend Detector Oscillator
|
||||
// --------------------------------------------------
|
||||
// Name: XTD
|
||||
// Description: trend detecting in both sides ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTD Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XTD"
|
||||
|
||||
//
|
||||
// XTD Oscillator States ...
|
||||
enum ENUM_X_XTD_STATES
|
||||
{
|
||||
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
|
||||
X_XTD_BULLISH_OVER_BEARISH = 1,
|
||||
X_XTD_NEUTURAL = 0,
|
||||
X_XTD_BULLISH_UNDER_BEARISH = -1,
|
||||
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Include Models Library ...
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 14; // Market Length
|
||||
input bool drawCrosses = true; // Draw Cross Arrows
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
input uchar bullishArrowCode = 228; // Cross Over Arrow Code
|
||||
input color bullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
input uchar bearishArrowCode = 230; // Cross Under Arrow Code
|
||||
input color bearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
#define bullishBufferIndex 0
|
||||
#define bearishBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
|
||||
//
|
||||
double bullishBuffer[];
|
||||
double bearishBuffer[];
|
||||
double signalBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XBullPower"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#property indicator_label2 "XBearPower"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#property indicator_label3 "XSignal"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrGold
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
int xtdBullishCandleCount = 0;
|
||||
int xtdBearishCandleCount = 0;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
// De Init Draw Library ...
|
||||
OnDeinitDrawLibrary();
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i, close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 5)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Bullish Buffer ...
|
||||
string bullishBufferLabel = ShortName + "BullPow " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(bullishBuffer, true);
|
||||
SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(bullishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(bullishBufferIndex, PLOT_LABEL, bullishBufferLabel);
|
||||
|
||||
//
|
||||
// Bearish Buffer ...
|
||||
string bearishBufferLabel = ShortName + "BearPow " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(bearishBuffer, true);
|
||||
SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(bearishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(bearishBufferIndex, PLOT_LABEL, bearishBufferLabel);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
string signalBufferLabel = ShortName + "Signal " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(signalBuffer, true);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index,
|
||||
const double &close[])
|
||||
{
|
||||
//
|
||||
// Reset Global Counters ...
|
||||
xtdBullishCandleCount = 0;
|
||||
xtdBearishCandleCount = 0;
|
||||
|
||||
//
|
||||
// Loop through Closes ...
|
||||
for (int i = bar_index; i <= bar_index + length; i++)
|
||||
{
|
||||
for (int j = i + 1; j <= bar_index + length; j++)
|
||||
{
|
||||
//
|
||||
if (close[i] > close[j])
|
||||
{
|
||||
xtdBullishCandleCount++;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[i] < close[j])
|
||||
{
|
||||
xtdBearishCandleCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Power Buffer ...
|
||||
bullishBuffer[bar_index] = MathAbs(xtdBullishCandleCount);
|
||||
|
||||
//
|
||||
// Bearish Power Buffer ...
|
||||
bearishBuffer[bar_index] = MathAbs(xtdBearishCandleCount);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
signalBuffer[bar_index] = bullishBuffer[bar_index] - bearishBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Check and Draw Crosses if it's Specified ...
|
||||
if (drawCrosses)
|
||||
{
|
||||
DrawCrosses(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
double GetState(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Cross Points ...
|
||||
// bullishCrossedOverBearish = 2;
|
||||
// bullishOverBearish = 1;
|
||||
// bullishCrossedUnderBearish = -2;
|
||||
// bullishUnderBearish = -1;
|
||||
// OtherWise = 0;
|
||||
bool isBullishCrossedOverBearish = IsCrossOver(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishCrossedUnderBearish = IsCrossUnder(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishOverBearish = IsOver(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishUnderBearish = IsUnder(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double result = X_XTD_NEUTURAL;
|
||||
if (isBullishCrossedOverBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_CROSSED_OVER_BEARISH;
|
||||
}
|
||||
else if (isBullishCrossedUnderBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_CROSSED_UNDER_BEARISH;
|
||||
}
|
||||
else if (isBullishOverBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_OVER_BEARISH;
|
||||
}
|
||||
else if (isBullishUnderBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_UNDER_BEARISH;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = X_XTD_NEUTURAL;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Crosses ...
|
||||
void DrawCrosses(
|
||||
int bar_index // the bars which required to draw cross arrow on it ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double stateValue = GetState(bar_index);
|
||||
|
||||
//
|
||||
bool isOver = stateValue == 2;
|
||||
double low = iLow(_Symbol, _Period, bar_index);
|
||||
double high = iHigh(_Symbol, _Period, bar_index);
|
||||
|
||||
//
|
||||
double price = isOver ? low : high;
|
||||
datetime time = iTime(_Symbol, _Period, bar_index);
|
||||
ENUM_ARROW_ANCHOR anchor = isOver ? ANCHOR_TOP : ANCHOR_BOTTOM;
|
||||
uchar arrowCode = isOver ? bullishArrowCode : bearishArrowCode;
|
||||
color arrowColor = isOver ? bullishArrowColor : bearishArrowColor;
|
||||
string crossName = "Trend " + (isOver ? "Up" : "Down") + "_" + (string)time + "_" + (string)price;
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
0,
|
||||
crossName,
|
||||
0,
|
||||
time,
|
||||
price,
|
||||
arrowCode,
|
||||
anchor,
|
||||
arrowColor);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,349 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XTM
|
||||
// Description: Trend Magic Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTM Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XTM"
|
||||
|
||||
//
|
||||
// XTM Indicator States ...
|
||||
enum ENUM_X_XTM_STATES
|
||||
{
|
||||
X_XTM_BULLISH = 1,
|
||||
X_XTM_BEARISH = -1,
|
||||
X_XTM_NEUTURAL = 0,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int maPeriod = 14; // Period
|
||||
input int maShift = 0; // Shift
|
||||
input ENUM_MA_METHOD maMethod = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Applied To
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
#define maColorBufferIndex 1
|
||||
#define stateBufferIndex 2
|
||||
|
||||
double maBuffer[];
|
||||
double maColorBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
#property indicator_label1 "XTM"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
int maHandler = INVALID_HANDLE;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// Initializing MA Handler ...
|
||||
maHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
maPeriod,
|
||||
maShift,
|
||||
maMethod,
|
||||
maAppliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Ma Handler ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, maPeriod);
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (maPeriod >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
string maBufferLabel = "XTM " + "(" + (string)maPeriod + ")";
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// State Buffer ...
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "(", maPeriod, ")");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Define State Value ...
|
||||
// lineColorIndex == 0 => Bullish => 1;
|
||||
// lineColorIndex == 1 => Neutural => 0;
|
||||
// lineColorIndex == 2 => Bearish => -1;
|
||||
double stateValue =
|
||||
lineColorIndex == 0 ? X_XTM_BULLISH : lineColorIndex == 2 ? X_XTM_BEARISH
|
||||
: X_XTM_NEUTURAL;
|
||||
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = lineColorIndex;
|
||||
|
||||
//
|
||||
// Set State Buffer Value ...
|
||||
stateBuffer[bar_index] = stateValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,558 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTS Oscillator
|
||||
// ---------------------------------------------
|
||||
// Name: XTS
|
||||
// Description: Time Sections Oscillator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTS Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "XTS"
|
||||
|
||||
enum ENUM_X_PERIOD_METHOD
|
||||
{
|
||||
//
|
||||
X_PERIOD_NOTHING,
|
||||
//
|
||||
X_PERIOD_AUTO,
|
||||
//
|
||||
X_PERIOD_MANUALLY
|
||||
};
|
||||
|
||||
//
|
||||
// XTS Oscillator States ...
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Current Period";
|
||||
input ENUM_APPLIED_PRICE currentAppliedTo = PRICE_CLOSE; // Current Applied To
|
||||
//
|
||||
input group "Nearest Period";
|
||||
input ENUM_X_PERIOD_METHOD nearestMethod = X_PERIOD_AUTO; // How to Find Nearest Period
|
||||
input ENUM_TIMEFRAMES nearestPeriod = NULL; // Nearest Time Frame
|
||||
input ENUM_APPLIED_PRICE nearestAppliedTo = PRICE_CLOSE; // Nearest Applied To
|
||||
//
|
||||
input group "Mediest Period";
|
||||
input ENUM_X_PERIOD_METHOD mediestMethod = X_PERIOD_AUTO; // How to Find Mediest Period
|
||||
input ENUM_TIMEFRAMES mediestPeriod = NULL; // Mediest Time Frame
|
||||
input ENUM_APPLIED_PRICE mediestAppliedTo = PRICE_CLOSE; // Mediest Applied To
|
||||
//
|
||||
input group "Farest Period";
|
||||
input ENUM_X_PERIOD_METHOD farestMethod = X_PERIOD_AUTO; // How to Find Farest Period
|
||||
input ENUM_TIMEFRAMES farestPeriod = NULL; // Farest Time Frame
|
||||
input ENUM_APPLIED_PRICE farestAppliedTo = PRICE_CLOSE; // Farest Applied To
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// Current ...
|
||||
#define currentBufferIndex 0
|
||||
|
||||
double currentBuffer[];
|
||||
|
||||
#property indicator_label1 "XTS C"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
#define nearestBufferIndex 1
|
||||
|
||||
double nearestBuffer[];
|
||||
|
||||
#property indicator_label2 "XTS N"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrAqua
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
#define mediestBufferIndex 2
|
||||
|
||||
double mediestBuffer[];
|
||||
|
||||
#property indicator_label3 "XTS M"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrLime
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
#define farestBufferIndex 3
|
||||
|
||||
double farestBuffer[];
|
||||
|
||||
#property indicator_label4 "XTS F"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrLightBlue
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mNearestPeriod = NULL;
|
||||
ENUM_TIMEFRAMES mMediestPeriod = NULL;
|
||||
ENUM_TIMEFRAMES mFarestPeriod = NULL;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Oscillator ShortName ...
|
||||
SetOscillatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
OnDeinitDrawLibrary();
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = 30;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = 0; i < limit && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
int maxLength = 30;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
ArraySetAsSeries(currentBuffer, true);
|
||||
SetIndexBuffer(currentBufferIndex, currentBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(currentBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
ArraySetAsSeries(nearestBuffer, true);
|
||||
SetIndexBuffer(nearestBufferIndex, nearestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(nearestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
ArraySetAsSeries(mediestBuffer, true);
|
||||
SetIndexBuffer(mediestBufferIndex, mediestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mediestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
ArraySetAsSeries(farestBuffer, true);
|
||||
SetIndexBuffer(farestBufferIndex, farestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(farestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Oscillator Short Name and also we can define Buffers Labels ...
|
||||
void SetOscillatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Current ...
|
||||
CalculateCurrent(bar_index);
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
CalculateNearest(bar_index);
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
CalculateMediest(bar_index);
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
CalculateFarest(bar_index);
|
||||
|
||||
//
|
||||
// Commenting ...
|
||||
string comment = GenerateDescriptionComment();
|
||||
Comment(comment);
|
||||
}
|
||||
|
||||
//
|
||||
// Current ...
|
||||
void CalculateCurrent(int bar_index)
|
||||
{
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
currentAppliedTo);
|
||||
|
||||
//
|
||||
currentBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
void CalculateNearest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mNearestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (nearestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mNearestPeriod = GetNearestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mNearestPeriod = nearestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mNearestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
nearestAppliedTo);
|
||||
|
||||
//
|
||||
nearestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
void CalculateMediest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mMediestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (mediestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mMediestPeriod = GetMediestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mMediestPeriod = mediestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mMediestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
mediestAppliedTo);
|
||||
|
||||
//
|
||||
mediestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
void CalculateFarest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mFarestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (farestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mFarestPeriod = GetFarestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mFarestPeriod = farestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mFarestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
farestAppliedTo);
|
||||
|
||||
//
|
||||
farestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Comment ...
|
||||
string GenerateDescriptionComment()
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result += "Nearest : " + EnumToString(mNearestPeriod) + "\n";
|
||||
result += "Mediest : " + EnumToString(mMediestPeriod) + "\n";
|
||||
result += "Farest : " + EnumToString(mFarestPeriod) + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,200 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Alert Library
|
||||
// --------------------------------------
|
||||
// Name: XAlert
|
||||
// Description: provides Alerts abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Alerts";
|
||||
input bool enableAlerts = true; // Enable Alerts
|
||||
input bool logAlerts = true; // Log Alerts
|
||||
input bool terminalAlerts = false; // Terminal Alerts
|
||||
input bool mailAlerts = false; // Mail Alerts
|
||||
input bool pushAlerts = false; // Push Alerts
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
#include "x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string alertPrefix = "X-Alert";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitAlertLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitAlertLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Attach Alert Prefix to Message ...
|
||||
string PrepareAlertMessage(string message)
|
||||
{
|
||||
//
|
||||
StringReplace(message, "\n", " | ");
|
||||
|
||||
//
|
||||
StringConcatenate(message, alertPrefix, " > ", message);
|
||||
|
||||
//
|
||||
return message;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Alert ...
|
||||
void LogAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !logAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
LogMessage(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal Alert ...
|
||||
void TerminalAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !terminalAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
// Send Terminal Alert ...
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail Alert ...
|
||||
void MailAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !mailAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Mail Alert ...
|
||||
SendMail(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Send Push Notification ...
|
||||
void PushAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !pushAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
//
|
||||
// Send Push Notification Alert ...
|
||||
SendNotification(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Sending ...
|
||||
void SendAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Log ...
|
||||
if (logAlerts)
|
||||
{
|
||||
LogAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal ...
|
||||
if (terminalAlerts)
|
||||
{
|
||||
TerminalAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail ...
|
||||
if (mailAlerts)
|
||||
{
|
||||
MailAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Push ...
|
||||
if (pushAlerts)
|
||||
{
|
||||
PushAlert(message);
|
||||
}
|
||||
}
|
||||
void SendAlert(
|
||||
XSignal &signal, // the Signal Object which requred to Alert
|
||||
bool asExecuted = true // determines Alert Signal as Executed Signal or not
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Message ...
|
||||
string message = asExecuted ? ExecutedSignalToString(signal) : SignalToString(signal);
|
||||
|
||||
//
|
||||
// Do Alerting ...
|
||||
SendAlert(message);
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,177 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Http Library
|
||||
// ------------------------------------------
|
||||
// Name: XHttp
|
||||
// Description: provide http communication
|
||||
// abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Model Definition ...
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
//
|
||||
// END Model Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitHttpLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitHttpLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
) {
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
) {
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
@@ -0,0 +1,261 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Logger Library
|
||||
// ---------------------------------------
|
||||
// Name: XLogger
|
||||
// Description: provides Logging abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Logging";
|
||||
input bool enableLogging = true; // Enable Logging
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Including Models ...
|
||||
#include "x-saherelm.models.lib.mq5"
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string logTag = "X-Logger"; // LogTag
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Logging a Message ...
|
||||
void LogMessage(string message)
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, " > ", message);
|
||||
}
|
||||
void LogMessage(string tag, string message)
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(tag, " > ", message);
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Array ...
|
||||
void LogArray(int &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
void LogArray(double &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
void LogArray(string &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
|
||||
//
|
||||
// Convert a Signal to String Message ...
|
||||
string SignalToString(const XSignal &signal)
|
||||
{
|
||||
//
|
||||
string result = "\n";
|
||||
|
||||
//
|
||||
result += "Signal: " + "\n";
|
||||
result += "id: " + (string)signal.id + "\n";
|
||||
result += "symbol: " + signal.symbol + "\n";
|
||||
result += "type: " + EnumToString(signal.type) + "\n";
|
||||
result += "magicNumber: " + (string)signal.magicNumber + "\n";
|
||||
result += "ticket: " + (string)signal.ticket + "\n";
|
||||
result += "entry: " + (string)signal.entry + "\n";
|
||||
result += "tp: " + (string)signal.tp + "\n";
|
||||
result += "sl: " + (string)signal.sl + "\n";
|
||||
result += "riskFreeStep: " + (string)signal.riskFreeStep + "\n";
|
||||
result += "riskFreeRate: " + (string)signal.riskFreeRate + "\n";
|
||||
result += "profit: " + (string)signal.profit + "\n";
|
||||
result += "time: " + (string)signal.time + "\n";
|
||||
result += "volume: " + (string)signal.volume + "\n";
|
||||
result += "comment: " + signal.comment + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Convert an Executed Signal to String Message ...
|
||||
string ExecutedSignalToString(const XSignal &signal)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result += (signal.type == X_SIGNAL_LONG ? "Buy" : "Sell") + " Signal Executed provided on (" + signal.symbol + " _ " + EnumToString(_Period) + ") by this comment: " + signal.comment;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging Signal ...
|
||||
void LogSignal(const XSignal &signal)
|
||||
{
|
||||
//
|
||||
string message = SignalToString(signal);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Log Signal Execution ...
|
||||
void LogExecutedSignal(const XSignal &signal)
|
||||
{
|
||||
//
|
||||
string message = ExecutedSignalToString(signal);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Convert a Deal to String ...
|
||||
string DealToString(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
string result = "\n";
|
||||
|
||||
//
|
||||
result += "Deal:" + "\n";
|
||||
result += " " + "\n";
|
||||
result += "time: " + (string)deal.time + "\n";
|
||||
result += "ticket: " + (string)deal.ticket + "\n";
|
||||
result += "order: " + (string)deal.order + "\n";
|
||||
result += "positionId: " + (string)deal.positionId + "\n";
|
||||
result += "type: " + EnumToString(deal.type) + "\n";
|
||||
result += "entry: " + EnumToString(deal.entry) + "\n";
|
||||
result += "reason: " + EnumToString(deal.reason) + "\n";
|
||||
result += "symbol: " + deal.symbol + "\n";
|
||||
result += "price: " + (string)deal.price + "\n";
|
||||
result += "profit: " + (string)deal.profit + "\n";
|
||||
result += "swap: " + (string)deal.swap + "\n";
|
||||
result += "commission: " + (string)deal.commission + "\n";
|
||||
result += "volume: " + (string)deal.volume + "\n";
|
||||
result += "comment: " + deal.comment + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Log Specific Deal ...
|
||||
void LogDeal(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
string message = DealToString(deal);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Convert an Order to String ...
|
||||
string OrderToString(const XOrder &order)
|
||||
{
|
||||
//
|
||||
string result = "\n";
|
||||
|
||||
//
|
||||
result += "Order: " + "\n";
|
||||
result += "magic: " + (string)order.magic + "\n";
|
||||
result += "positionId: " + (string)order.positionId + "\n";
|
||||
result += "symbol: " + (string)order.symbol + "\n";
|
||||
result += "ticket: " + (string)order.ticket + "\n";
|
||||
result += "timeSetup: " + (string)order.timeSetup + "\n";
|
||||
result += "timeDone: " + (string)order.timeDone + "\n";
|
||||
result += "timeExpiration: " + (string)order.timeExpiration + "\n";
|
||||
result += "priceOpen: " + (string)order.priceOpen + "\n";
|
||||
result += "priceCurrent: " + (string)order.priceCurrent + "\n";
|
||||
result += "priceStopLimit: " + (string)order.priceStopLimit + "\n";
|
||||
result += "stopLoss: " + (string)order.stopLoss + "\n";
|
||||
result += "takeProfit: " + (string)order.takeProfit + "\n";
|
||||
result += "volumeInitial: " + (string)order.volumeInitial + "\n";
|
||||
result += "volumeCurrent: " + (string)order.volumeCurrent + "\n";
|
||||
result += "comment: " + order.comment + "\n";
|
||||
result += "type: " + EnumToString(order.type) + "\n";
|
||||
result += "state: " + EnumToString(order.state) + "\n";
|
||||
result += "typeFilling: " + EnumToString(order.typeFilling) + "\n";
|
||||
result += "typeTime: " + EnumToString(order.typeTime) + "\n";
|
||||
result += "reason: " + EnumToString(order.reason) + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Log Specific Order ...
|
||||
void LogOrder(const XOrder &order)
|
||||
{
|
||||
//
|
||||
string message = OrderToString(order);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
@@ -0,0 +1,438 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Models Library
|
||||
// ---------------------------------------
|
||||
// Name: XModels
|
||||
// Description: provides all required models ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// How To Calculate Static Volume ...
|
||||
enum ENUM_STATIC_VOLUME_METHODS
|
||||
{
|
||||
//
|
||||
// Based On Deposit ...
|
||||
X_STATIC_VOLUME_BASED_ON_DEPOSIT,
|
||||
//
|
||||
// Based On Balance ...
|
||||
X_STATIC_VOLUME_BASED_ON_BALANCE,
|
||||
};
|
||||
|
||||
//
|
||||
// START Model Definitions ...
|
||||
//
|
||||
//
|
||||
// OHCL Candel Model ...
|
||||
enum ENUM_X_PRICE
|
||||
{
|
||||
X_PRICE_HIGH,
|
||||
X_PRICE_OPEN,
|
||||
X_PRICE_CLOSE,
|
||||
X_PRICE_LOW
|
||||
};
|
||||
|
||||
//
|
||||
// Describe an Specific Candle ...
|
||||
struct XOHCL
|
||||
{
|
||||
double high;
|
||||
double open;
|
||||
double close;
|
||||
double low;
|
||||
};
|
||||
|
||||
//
|
||||
// Swing Types Enum ...
|
||||
enum ENUM_X_SWING_TYPE
|
||||
{
|
||||
X_NO_SWING = 0,
|
||||
X_SWING_HIGH = 1,
|
||||
X_SWING_LOW = -1,
|
||||
};
|
||||
|
||||
//
|
||||
// XTrader Execution Signal Result ...
|
||||
enum ENUM_EXECUTION_SIGNAL_RESULT
|
||||
{
|
||||
//
|
||||
X_TRADER_UNKNOWN_ERROR,
|
||||
X_TRADER_SUCCEED_EXECUTION,
|
||||
X_TRADER_INVALID_SIGNAL_ERROR,
|
||||
X_TRADER_NOT_ENOUGH_EQUITY_ERROR,
|
||||
X_TRADER_MAX_TRADES_REACHED_ERROR,
|
||||
X_TRADER_NOT_ENOUGH_BALANCE_ERROR,
|
||||
X_TRADER_NOT_ENOUGH_MARIGIN_ERROR
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Signal Types ...
|
||||
enum ENUM_X_SIGNAL_TYPE
|
||||
{
|
||||
X_SIGNAL_LONG,
|
||||
X_SIGNAL_SHORT,
|
||||
X_SIGNAL_UNKNOWN,
|
||||
};
|
||||
|
||||
//
|
||||
// Signal Structure ...
|
||||
struct XSignal
|
||||
{
|
||||
//
|
||||
// Identifier ...
|
||||
ulong id;
|
||||
|
||||
//
|
||||
// Which Symbol used for Signal ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Which Type of operations ...
|
||||
ENUM_X_SIGNAL_TYPE type;
|
||||
|
||||
//
|
||||
// Magic Number ...
|
||||
ulong magicNumber;
|
||||
|
||||
//
|
||||
// Ticket ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// Entry/Open Price ...
|
||||
double entry;
|
||||
|
||||
//
|
||||
// TP ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// SL ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// Make Risk Free Trade on this Value if provided ...
|
||||
double riskFreeStep;
|
||||
|
||||
//
|
||||
// a Multiplier for determines how much trade volume exit on risk free time ...
|
||||
double riskFreeRate;
|
||||
|
||||
//
|
||||
// Trade Profit ...
|
||||
double profit;
|
||||
|
||||
//
|
||||
// Time of Operation ...
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
double volume;
|
||||
|
||||
//
|
||||
// Comment ...
|
||||
string comment;
|
||||
};
|
||||
|
||||
//
|
||||
// Signal Additional Info ...
|
||||
struct XProvidedSignal
|
||||
{
|
||||
//
|
||||
// Suggested TP ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// Suggested SL ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// Signallers ...
|
||||
string signallers[];
|
||||
};
|
||||
|
||||
//
|
||||
// Model Specific Deal ...
|
||||
struct XDeal
|
||||
{
|
||||
//
|
||||
// the ID of the Expert Advisor, that executed the deal ...
|
||||
ulong magic;
|
||||
|
||||
//
|
||||
// the ID of position, in which the deal was involved ...
|
||||
ulong positionId;
|
||||
|
||||
//
|
||||
// Ticket ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// the name of the deal symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// order by which the deal is executed ...
|
||||
ulong order;
|
||||
|
||||
//
|
||||
// the time of deal execution ...
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Deal price ...
|
||||
double price;
|
||||
|
||||
//
|
||||
// the financial result of the deal (in deposit currency) ...
|
||||
double profit;
|
||||
|
||||
//
|
||||
// the amount of swap when position is closed ...
|
||||
double swap;
|
||||
|
||||
//
|
||||
// the amount of commission of the deal ...
|
||||
double commission;
|
||||
|
||||
//
|
||||
// the volume of deal ...
|
||||
double volume;
|
||||
|
||||
//
|
||||
// the deal comment ...
|
||||
string comment;
|
||||
|
||||
//
|
||||
// the deal type ...
|
||||
// ------------------------------------------------------------------
|
||||
// DEAL_TYPE_BUY => Buy ...
|
||||
// DEAL_TYPE_SELL => Sell ...
|
||||
// DEAL_TYPE_BUY_CANCELED => Canceled buy deal ...
|
||||
// There can be a situation when a previously executed buy deal is canceled. In this case,
|
||||
// the type of the previously executed deal (DEAL_TYPE_BUY) is changed to DEAL_TYPE_BUY_CANCELED,
|
||||
// and its profit/loss is zeroized. Previously obtained profit/loss is charged/withdrawn using a separated balance operation ...
|
||||
//
|
||||
// DEAL_TYPE_SELL_CANCELED => Canceled sell deal ...
|
||||
// There can be a situation when a previously executed sell deal is canceled. In this case,
|
||||
// the type of the previously executed deal (DEAL_TYPE_SELL) is changed to DEAL_TYPE_SELL_CANCELED,
|
||||
// and its profit/loss is zeroized. Previously obtained profit/loss is charged/withdrawn using a separated balance operation
|
||||
//
|
||||
// DEAL_TYPE_BALANCE => Balance ...
|
||||
// DEAL_TYPE_CREDIT => Credit ...
|
||||
// DEAL_TYPE_CHARGE => Additional charge ...
|
||||
// DEAL_TYPE_CORRECTION => Correction ...
|
||||
// DEAL_TAX => Tax charges ...
|
||||
// DEAL_TYPE_BONUS => Bonus ...
|
||||
// DEAL_TYPE_INTEREST => Interest rate ...
|
||||
// DEAL_DIVIDEND => Dividend operations...
|
||||
// DEAL_DIVIDEND_FRANKED => Franked (non-taxable) dividend operations ...
|
||||
// DEAL_TYPE_COMMISSION => Additional commission ...
|
||||
// DEAL_TYPE_COMMISSION_DAILY => Daily commission ...
|
||||
// DEAL_TYPE_COMMISSION_MONTHLY => Monthly commission ...
|
||||
// DEAL_TYPE_COMMISSION_AGENT_DAILY => Daily agent commission ...
|
||||
// DEAL_TYPE_COMMISSION_AGENT_MONTHLY => Monthly agent commission
|
||||
ENUM_DEAL_TYPE type;
|
||||
|
||||
//
|
||||
// the deal direction ...
|
||||
// ----------------------------------
|
||||
// DEAL_ENTRY_IN => Entry in ...
|
||||
// DEAL_ENTRY_OUT => Entry out ...
|
||||
// DEAL_ENTRY_INOUT => Reverse ...
|
||||
// DEAL_ENTRY_OUT_BY => Close a position by an opposite one ...
|
||||
ENUM_DEAL_ENTRY entry;
|
||||
|
||||
//
|
||||
// deal reson ...
|
||||
// ---------------------
|
||||
// DEAL_REASON_SL => The deal was executed as a result of Stop Loss activation ...
|
||||
// DEAL_REASON_TP => The deal was executed as a result of Take Profit activation ...
|
||||
// DEAL_REASON_SO => The deal was executed as a result of the Stop Out event ...
|
||||
// DEAL_REASON_WEB => The deal was executed as a result of activation of an order placed from the web platform ...
|
||||
// DEAL_REASON_SPLIT => The deal was executed after the split (price reduction) of an instrument, which had an open position during split announcement ...
|
||||
// DEAL_REASON_CLIENT => The deal was executed as a result of activation of an order placed from a desktop terminal ...
|
||||
// DEAL_REASON_MOBILE => The deal was executed as a result of activation of an order placed from a mobile application ...
|
||||
// DEAL_REASON_EXPERT => The deal was executed as a result of activation of an order placed from an MQL5 program, i.e. an Expert Advisor or a script ...
|
||||
// DEAL_REASON_VMARGIN => The deal was executed after charging the variation margin ...
|
||||
// DEAL_REASON_ROLLOVER => The deal was executed due to a rollover ...
|
||||
ENUM_DEAL_REASON reason;
|
||||
};
|
||||
|
||||
//
|
||||
// Model Specific Order ...
|
||||
struct XOrder
|
||||
{
|
||||
//
|
||||
// the ID of expert that placed the order ...
|
||||
ulong magic;
|
||||
|
||||
//
|
||||
// the ID of position ...
|
||||
ulong positionId;
|
||||
|
||||
//
|
||||
// the name of order symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// the ticket of an order, previously selected for access ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// the time of order placement ...
|
||||
datetime timeSetup;
|
||||
|
||||
//
|
||||
// the time of order execution or cancellation ...
|
||||
datetime timeDone;
|
||||
|
||||
//
|
||||
// the order expiration time ...
|
||||
datetime timeExpiration;
|
||||
|
||||
//
|
||||
// the order price ...
|
||||
double priceOpen;
|
||||
|
||||
//
|
||||
// the current price by order symbol ...
|
||||
double priceCurrent;
|
||||
|
||||
//
|
||||
// the price of a pending order ...
|
||||
double priceStopLimit;
|
||||
|
||||
//
|
||||
// the order's Stop Loss ...
|
||||
double stopLoss;
|
||||
|
||||
//
|
||||
// the order's Take Profit ...
|
||||
double takeProfit;
|
||||
|
||||
//
|
||||
// the initial volume of order ...
|
||||
double volumeInitial;
|
||||
|
||||
//
|
||||
// the unfilled volume of order ...
|
||||
double volumeCurrent;
|
||||
|
||||
//
|
||||
// the order comment ...
|
||||
string comment;
|
||||
|
||||
//
|
||||
// the order type ...
|
||||
// --------------------
|
||||
// ORDER_TYPE_BUY => Market Buy order ...
|
||||
// ORDER_TYPE_SELL => Market Sell order ...
|
||||
// ORDER_TYPE_BUY_LIMIT => Buy Limit pending order ...
|
||||
// ORDER_TYPE_SELL_LIMIT => Sell Limit pending order ...
|
||||
// ORDER_TYPE_BUY_STOP => Buy Stop pending order ...
|
||||
// ORDER_TYPE_SELL_STOP => Sell Stop pending order ...
|
||||
// ORDER_TYPE_BUY_STOP_LIMIT => Upon reaching the order price, a pending Buy Limit order is placed at the StopLimit price ...
|
||||
// ORDER_TYPE_SELL_STOP_LIMIT => Upon reaching the order price, a pending Sell Limit order is placed at the StopLimit price ...
|
||||
// ORDER_TYPE_CLOSE_BY => Order to close a position by an opposite one ...
|
||||
ENUM_ORDER_TYPE type;
|
||||
|
||||
//
|
||||
// the order state ...
|
||||
// --------------------------
|
||||
// ORDER_STATE_STARTED => Order checked, but not yet accepted by broker ...
|
||||
// ORDER_STATE_PLACED => Order accepted ...
|
||||
// ORDER_STATE_CANCELED => Order canceled by client ...
|
||||
// ORDER_STATE_PARTIAL => Order partially executed ...
|
||||
// ORDER_STATE_FILLED => Order fully executed ...
|
||||
// ORDER_STATE_REJECTED => Order rejected ...
|
||||
// ORDER_STATE_EXPIRED => Order expired ...
|
||||
// ORDER_STATE_REQUEST_ADD => Order is being registered (placing to the trading system)
|
||||
// ORDER_STATE_REQUEST_MODIFY => Order is being modified (changing its parameters) ...
|
||||
// ORDER_STATE_REQUEST_CANCEL => Order is being deleted (deleting from the trading system) ...
|
||||
ENUM_ORDER_STATE state;
|
||||
|
||||
//
|
||||
// the order filling type ...
|
||||
// ----------------------------
|
||||
// ORDER_FILLING_FOK => Fill or Kill
|
||||
// An order can be executed in the specified volume only.
|
||||
// If the necessary amount of a financial instrument is currently unavailable in the market,
|
||||
// the order will not be executed.
|
||||
// The desired volume can be made up of several available offers.
|
||||
// The possibility of using FOK orders is determined at the trade server.
|
||||
// ORDER_FILLING_IOC => Immediate or Cancel
|
||||
// A trader agrees to execute a deal with the volume maximally available in the market within that indicated in the order.
|
||||
// If the request cannot be filled completely, an order with the available volume will be executed,
|
||||
// and the remaining volume will be canceled.
|
||||
// The possibility of using IOC orders is determined at the trade server.
|
||||
// ORDER_FILLING_BOC => Passive (Book or Cancel)
|
||||
// The BoC order assumes that the order can only be placed in the Depth of Market and cannot be immediately executed.
|
||||
// If the order can be executed immediately when placed, then it is canceled.
|
||||
// In fact, the BOC policy guarantees that the price of the placed order will be worse than
|
||||
// the current market. BoC orders are used to implement passive trading,
|
||||
// so that the order is not executed immediately when placed and does not affect current liquidity.
|
||||
// Only limit and stop limit orders are supported (ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT, ORDER_TYPE_BUY_STOP_LIMIT, ORDER_TYPE_SELL_STOP_LIMIT).
|
||||
// ORDER_FILLING_RETURN => Return
|
||||
// In case of partial filling, an order with remaining volume is not canceled but processed further.
|
||||
// Return orders are not allowed in the Market Execution
|
||||
// mode (market execution — SYMBOL_TRADE_EXECUTION_MARKET).
|
||||
ENUM_ORDER_TYPE_FILLING typeFilling;
|
||||
|
||||
//
|
||||
// the type of order at the time of the expiration ...
|
||||
// --------------------------------------------------------
|
||||
// ORDER_TIME_GTC => Good till cancel order ...
|
||||
// ORDER_TIME_DAY => Good till current trade day order ...
|
||||
// ORDER_TIME_SPECIFIED => Good till expired order ...
|
||||
// ORDER_TIME_SPECIFIED_DAY => The order will be effective till 23:59:59 of the specified day.
|
||||
// If this time is outside a trading session, the order expires in the nearest trading time ...
|
||||
ENUM_ORDER_TYPE_TIME typeTime;
|
||||
|
||||
//
|
||||
// The reason for order placing ...
|
||||
// --------------------------------------
|
||||
// ORDER_REASON_SL => The order was placed as a result of Stop Loss activation ...
|
||||
// ORDER_REASON_TP => The order was placed as a result of Take Profit activation ...
|
||||
// ORDER_REASON_SO => The order was placed as a result of the Stop Out event ...
|
||||
// ORDER_REASON_WEB => The order was placed from a web platform ...
|
||||
// ORDER_REASON_CLIENT => The order was placed from a desktop terminal ...
|
||||
// ORDER_REASON_MOBILE => The order was placed from a mobile application ...
|
||||
// ORDER_REASON_EXPERT => The order was placed from an MQL5-program, i.e. by an Expert Advisor or a script ...
|
||||
ENUM_ORDER_REASON reason;
|
||||
};
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,280 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XEU5 Signal Provider Library Inputs
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Include Logger ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Include Classes ...
|
||||
#include "../Classes/x-saherelm.class.lib.mq5"
|
||||
|
||||
//
|
||||
input group "XEU5 Provider";
|
||||
|
||||
//
|
||||
// Commonly Used Configurations ...
|
||||
input group "XEU5 Common";
|
||||
//
|
||||
// Provider ...
|
||||
input bool xEU5EnableProvider = true; // Enable Provider
|
||||
input int xEU5NumberOfItemsPerTick = 30; // Number Of items Readed In Each Tick
|
||||
//
|
||||
// Alerts ...
|
||||
input bool xEU5EnableAlerts = true; // Enable Events Alert
|
||||
input bool xEU5EnableHourlyAlerts = false; // Send Alert on each new Hour
|
||||
input bool xEU5EnableDailyAlerts = false; // Send Alert on each new Day
|
||||
input bool xEU5EnableWeeklyAlerts = false; // Send Alert on each new Week
|
||||
input bool xEU5EnableMonthlyAlerts = true; // Send Alert on each new Month
|
||||
//
|
||||
// Reports ...
|
||||
input bool xEU5EnableDailyReports = false; // Send Report on each new Day
|
||||
input bool xEU5EnableWeeklyReports = false; // Send Report on each new Week
|
||||
input bool xEU5EnableMonthlyReports = true; // Send Report on each new Month
|
||||
|
||||
//
|
||||
// Trader and Expert Specific Configurations ...
|
||||
input group "XEU5 Trader";
|
||||
input int xEU5MagicNumber = 16940560; // Trader MagicNumber
|
||||
input int xEU5Slippage = 10; // Trader Slippage
|
||||
|
||||
//
|
||||
// Trades Management Configurations ...
|
||||
input group "XEU5 Trade Management";
|
||||
input bool xEU5AllowLongTrades = true; // Allow Long Trades
|
||||
input bool xEU5AllowShortTrades = true; // Allow Short Trades
|
||||
|
||||
//
|
||||
// Risk Management Configurations ...
|
||||
input group "XEU5 Risk Management";
|
||||
//
|
||||
input bool xEU5UseVirtualTPSl = false; // Use Virtual TP SL
|
||||
//
|
||||
// Trade Count ...
|
||||
input int xEU5MaxAllowedTrades = 10; // Max Allowed Trades at Same Time
|
||||
input ENUM_X_CROSS_SIGNAL_METHOD xEU5CrossSignalsMethod = X_CROSS_SIGNAL_REGULAR; // Handle Cross Signals Method
|
||||
//
|
||||
// Max Allowed Trade Age ...
|
||||
input int xEU5MaxAllowedTradeAge = 1500; // Detect Long Time Trades
|
||||
input ENUM_X_GUARD_ACTIONS xEU5OldTradesAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // What to do with Old Trades
|
||||
//
|
||||
// Trade Volume Specific Configurations ...
|
||||
input double xEU5StaticVolumeFactor = 0.0002; // Static Volume baesd on Balance
|
||||
input ENUM_STATIC_VOLUME_METHODS xEU5StaticVolumeMethod = X_STATIC_VOLUME_BASED_ON_BALANCE; // How to Calculate Static Volume
|
||||
input double xEU5VolumeMultiplier = 0; // Volume Increase Multiplier
|
||||
input double xEU5ApplyVolumeMultiplierFactor = 0; // Apply Volume Multiplier Rate based on Balance
|
||||
input double xEU5MaxSupportedVolumePerTradeFactor = 0; // Max Supported Volume Per Trade Factor based on Balance
|
||||
input double xEU5IncreasedMaxSupportedVolumeRate = 0; // Increase Max Supported Volume based on Balance
|
||||
//
|
||||
// Trade Profits ...
|
||||
input double xEU5MinRewardInPips = 15; // Minimum Reward Per Trade in Pips
|
||||
input double xEU5RiskFreeStepInPips = 6; // Make Trades Risk Free Steps in Pips
|
||||
input double xEU5RiskFreeRate = 0.6; // Volume Multiplier for Risk Free Trades
|
||||
//
|
||||
// Guard Riskable Money and Profits ...
|
||||
input double xEU5CriticalDrawDownFactor = 0.40; // Critical Allowed Drawdown Factor based on Balance
|
||||
input ENUM_X_GUARD_ACTIONS xEU5CriticalGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Guard Action on Critical Drawdown
|
||||
input double xEU5MaxAllowedDrawDownFactor = 0.45; // Max Allowed Drawdown Factor based on Balance
|
||||
input ENUM_X_GUARD_ACTIONS xEU5MaxAllowedGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_10; // Specify Guard Action on Max Allowed Drawdown
|
||||
input int xEU5GuardStopoutFiredAfterTouches = 5; // Guard Stopout all Trades if Max Allowed Drawdown touched
|
||||
|
||||
//
|
||||
// Account Conditions for Trading ...
|
||||
input double xEU5BalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
|
||||
input double xEU5FreeMarginFactorForOpenTrades = 0.8; // Minimum Free Margin for Open Trades
|
||||
|
||||
//
|
||||
// Validate Inputs before Initialization ...
|
||||
bool XEU5ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Implement Other Verifications ...
|
||||
|
||||
//
|
||||
// Check Trading Availability ...
|
||||
bool isTradeAvailable = xEU5AllowLongTrades || xEU5AllowShortTrades;
|
||||
if (!isTradeAvailable)
|
||||
{
|
||||
LogMessage("XEU5 => Warning: Trading disabled ...");
|
||||
}
|
||||
|
||||
//
|
||||
// Chekc Number of reading items per tick ...
|
||||
result = xEU5NumberOfItemsPerTick >= 5;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 invalid Number of items Reading Per Tick ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Max Allowed Trades Count ...
|
||||
result = isTradeAvailable && xEU5MaxAllowedTrades >= 1;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 Number of Trades not valid ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Free Margin ...
|
||||
result =
|
||||
isTradeAvailable &&
|
||||
xEU5FreeMarginFactorForOpenTrades > 0 &&
|
||||
xEU5FreeMarginFactorForOpenTrades < 1;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 Invalid Free Margin ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check min Balance for Open Trades ...
|
||||
result =
|
||||
isTradeAvailable &&
|
||||
xEU5BalanceFactorForOpenTrades > 0 &&
|
||||
xEU5BalanceFactorForOpenTrades < 1;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 Invalid Min Balance for Open Trades ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Min Reward Per Trade ...
|
||||
result = xEU5MinRewardInPips > 0;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 Invalid Min Reward Per Trade ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Trades Volume ...
|
||||
result = xEU5StaticVolumeFactor > 0;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 Invalid Static Volume ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Volume Multiplier ...
|
||||
result = xEU5VolumeMultiplier >= 0;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 Invalid Volume Multiplier ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xEU5CriticalDrawDownFactor == 0 || (xEU5CriticalDrawDownFactor > 0 &&
|
||||
xEU5CriticalDrawDownFactor < 1);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 Invalid Critical DrawDown Factor ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xEU5MaxAllowedDrawDownFactor == 0 || (xEU5MaxAllowedDrawDownFactor > 0 &&
|
||||
xEU5MaxAllowedDrawDownFactor < 1);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 Invalid Max Allowed DrawDown Factor ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Guard Actions ...
|
||||
//
|
||||
result =
|
||||
xEU5CriticalDrawDownFactor > 0 &&
|
||||
xEU5CriticalDrawDownFactor < 1 &&
|
||||
xEU5MaxAllowedDrawDownFactor > 0 &&
|
||||
xEU5MaxAllowedDrawDownFactor < 1;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 For Critical Drawdown, you have to Specify Max Drawdown also ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = xEU5CriticalDrawDownFactor > 0 && xEU5CriticalDrawDownFactor < xEU5MaxAllowedDrawDownFactor;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XEU5 Critical Drawdown must Smaller than Max Drawdown ...");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (xEU5CriticalDrawDownFactor > 0 && xEU5CriticalGuardAction == X_GUARD_DO_NOTHING)
|
||||
{
|
||||
LogMessage("XEU5 IMPORTANT you Specified Critical Drawdown, but there is no any Guard Action ...");
|
||||
}
|
||||
|
||||
//
|
||||
if (xEU5MaxAllowedDrawDownFactor > 0 && xEU5MaxAllowedGuardAction == X_GUARD_DO_NOTHING)
|
||||
{
|
||||
LogMessage("XEU5 IMPORTANT you Specified Max Allowed Drawdown, but there is no any Guard Action ...");
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,258 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 NN Class Library
|
||||
// ----------------------------------------
|
||||
// Name: XNNClass
|
||||
// Description: provides all classes for implementing
|
||||
// Neural Network ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
class XCNNBase
|
||||
{
|
||||
//
|
||||
// Public Definitions ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCNNBase(
|
||||
int nodes = 10, // Number of Input Nodes
|
||||
double starterWeight = 0.5, // start weight for each input
|
||||
double coEfficient = 0.1, // COEfficient Multiplier
|
||||
double upperRange = 1, // Upper Normal Range Value
|
||||
double lowerRange = -1, // Lower Normal Range Value
|
||||
double learningRates = 0.1 // Back Propagation Learning Rate
|
||||
) {
|
||||
//
|
||||
mNodes = nodes;
|
||||
mUpperRange = upperRange;
|
||||
mLowerRange = lowerRange;
|
||||
mCoEfficient = coEfficient;
|
||||
mLearningRates = learningRates;
|
||||
mStarterWeight = starterWeight;
|
||||
|
||||
//
|
||||
ReConstructWeights();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCNNBase() {}
|
||||
|
||||
//
|
||||
// Protected Definitions ...
|
||||
void NormalizeInputs(double &inputs[], double &result[])
|
||||
{
|
||||
//
|
||||
ArrayFree(result);
|
||||
ArrayResize(result, 1);
|
||||
|
||||
//
|
||||
// Validate inputs ...
|
||||
if (ArraySize(inputs) != mNodes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Result ...
|
||||
ArrayResize(result, mNodes);
|
||||
|
||||
//
|
||||
// Calculating min and max range value ...
|
||||
double minRangeValue = inputs[ArrayMinimum(inputs)];
|
||||
double maxRangeValue = inputs[ArrayMaximum(inputs)];
|
||||
|
||||
//
|
||||
// Loop through Inputs nd Normalize them ...
|
||||
for (int i = 0; i < mNodes; i++)
|
||||
{
|
||||
//
|
||||
double normalValue = (((inputs[i] - minRangeValue) * (mUpperRange - mLowerRange)) / (maxRangeValue - minRangeValue)) + mLowerRange;
|
||||
result[i] = normalValue;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Hyperbolic Tangent Activation Function ...
|
||||
double TanHActivationFunction(double weightedInputs)
|
||||
{
|
||||
//
|
||||
double result = (exp(weightedInputs) - exp(-weightedInputs)) / (exp(weightedInputs) + exp(-weightedInputs));
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Weighted Inputs ...
|
||||
double CalculateWeightedInputs(
|
||||
double &inputs[],
|
||||
bool applyCOEfficient = true)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes)
|
||||
{
|
||||
//
|
||||
result = -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < mNodes; i++)
|
||||
{
|
||||
result += inputs[i] * mWeights[i];
|
||||
}
|
||||
|
||||
//
|
||||
// Multiply if required ...
|
||||
if (applyCOEfficient)
|
||||
{
|
||||
result *= mCoEfficient;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Hidden Layers ...
|
||||
virtual double CalculateHiddenLayer(double &inputs[])
|
||||
{
|
||||
//
|
||||
// this is Default Activation Function which used ...
|
||||
// you can override this by writing your own ...
|
||||
double totalWeightedInputs = CalculateWeightedInputs(inputs);
|
||||
double result = TanHActivationFunction(totalWeightedInputs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Output Layers ...
|
||||
double CalculateOutputLayer(double &inputs[])
|
||||
{
|
||||
//
|
||||
double result = -1;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double normalizedInputs[];
|
||||
NormalizeInputs(inputs, normalizedInputs);
|
||||
if (ArraySize(normalizedInputs) != mNodes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double hiddenLayerResult = CalculateHiddenLayer(normalizedInputs);
|
||||
|
||||
//
|
||||
result = 1 * hiddenLayerResult;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Basck Propaggation Learning ...
|
||||
void BackPropagation(
|
||||
double &inputs[],
|
||||
double &outputs,
|
||||
double targetOutput
|
||||
) {
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double normalizedInputs[];
|
||||
NormalizeInputs(inputs, normalizedInputs);
|
||||
if (ArraySize(normalizedInputs) != mNodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double error = targetOutput - outputs;
|
||||
double derivative = 1 - MathPow(outputs, 2);
|
||||
|
||||
//
|
||||
for (int i = 0; i < mNodes; i++) {
|
||||
//
|
||||
double gradient = error * derivative * inputs[i];
|
||||
mWeights[i] = mLearningRates * gradient;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
//
|
||||
// Private Definitions ...
|
||||
private:
|
||||
//
|
||||
// Number of Input Nodes ...
|
||||
int mNodes;
|
||||
|
||||
//
|
||||
// Specify Upper range of Normal Values ...
|
||||
double mUpperRange;
|
||||
|
||||
//
|
||||
// Specify Lower range of Normal Values ...
|
||||
double mLowerRange;
|
||||
|
||||
//
|
||||
// Starter Weight for each input node ...
|
||||
double mStarterWeight;
|
||||
|
||||
//
|
||||
// double Input Node Weights ...
|
||||
double mWeights[];
|
||||
|
||||
//
|
||||
// CoEfficient is a multiplyer for weighted inputs ...
|
||||
double mCoEfficient;
|
||||
|
||||
//
|
||||
// Back Propagation Learning Rates ...
|
||||
double mLearningRates;
|
||||
|
||||
//
|
||||
// ReConstruct Weights ...
|
||||
void ReConstructWeights() {
|
||||
//
|
||||
ArrayFree(mWeights);
|
||||
ArrayResize(mWeights, mNodes);
|
||||
|
||||
//
|
||||
for (int i = 0; i< mNodes; i++) {
|
||||
mWeights[i] = mStarterWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
#gets the File To Compile as an external parameter... Defaults to a Test file...
|
||||
Param( $FileToCompile = "C:\Users\saherelm\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\x-saherelm.ea.mq5")
|
||||
|
||||
#cleans the terminal screen and sets the log file name...
|
||||
Clear-Host
|
||||
$LogFile = $FileToCompile + ".log"
|
||||
|
||||
#before continue check if the Compile File has any spaces in it...
|
||||
if ($FileToCompile.Contains(" ")) {
|
||||
""; "";
|
||||
Write-Host "ERROR! Impossible to Compile! Your Filename or Path contains SPACES!" -ForegroundColor Red;
|
||||
"";
|
||||
Write-Host $FileToCompile -ForegroundColor Red;
|
||||
""; "";
|
||||
return;
|
||||
}
|
||||
|
||||
#first of all, kill MT Terminal (if running)... otherwise it will not see the new compiled version of the code...
|
||||
Get-Process -Name terminal64 -ErrorAction SilentlyContinue | Where-Object { $_.Id -gt 0 } | Stop-Process
|
||||
|
||||
#fires up the Metaeditor compiler...
|
||||
& "C:\Program Files\MetaTrader 5\MetaEditor64.exe" /compile:"$FileToCompile" /log:"$LogFile" /inc:"C:\Users\saherelm\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5" | Out-Null
|
||||
|
||||
#get some clean real state and tells the user what is being compiled (just the file name, no path)...
|
||||
""; ""; ""; ""; ""
|
||||
$JustTheFileName = Split-Path $FileToCompile -Leaf
|
||||
Write-Host "Compiling........: $JustTheFileName"
|
||||
""
|
||||
|
||||
#reads the log file. Eliminates the blank lines. Skip the first line because it is useless.
|
||||
$Log = Get-Content -Path $LogFile | Where-Object { $_ -ne "" } | Select-Object -Skip 1
|
||||
|
||||
#Green color for successful Compilation. Otherwise (error/warning), Red!
|
||||
$WhichColor = "Red"
|
||||
$Log | ForEach-Object { if ($_.Contains("0 error(s), 0 warning(s)")) { $WhichColor = "Green" } }
|
||||
|
||||
#runs through all the log lines...
|
||||
$Log | ForEach-Object {
|
||||
#ignores the ": information: error generating code" line when ME was successful
|
||||
if (-Not $_.Contains("information:")) {
|
||||
#common log line... just print it...
|
||||
Write-Host $_ -ForegroundColor $WhichColor
|
||||
}
|
||||
}
|
||||
|
||||
#get the MT Terminal back if all went well...
|
||||
if ( $WhichColor -eq "Green") { & "C:\\Program Files\\MetaTrader 5\\MetaEditor64.exe" }
|
||||
@@ -0,0 +1,946 @@
|
||||
# Market Conditions
|
||||
|
||||
we study market and retrieve it's sense in an specific time by Capturing Market Conditions, which it is a Data Model based on Combination of Oscillators and Indicators in our Provider.
|
||||
|
||||
## Market Condition Model
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Represent Market Conditions ...
|
||||
struct XEU5MarketConditions
|
||||
{
|
||||
//
|
||||
// XTM ...
|
||||
bool isXTMPeak;
|
||||
bool isXTMVale;
|
||||
bool isXTMBullish;
|
||||
bool isXTMBearish;
|
||||
bool isXTMNeutural;
|
||||
bool isXTMEndBullish;
|
||||
bool isXTMEndBearish;
|
||||
bool isXTMStartBullish;
|
||||
bool isXTMStartBearish;
|
||||
bool isXTMEndBullishByNeutural;
|
||||
bool isXTMEndBearishByNeutural;
|
||||
bool isXTMStartBullishAfterNeutural;
|
||||
bool isXTMStartBearishAfterNeutural;
|
||||
|
||||
//
|
||||
// XAMA ...
|
||||
bool isXAMAPeak;
|
||||
bool isXAMAVale;
|
||||
bool isXAMABullish;
|
||||
bool isXAMABearish;
|
||||
bool isXAMANeutural;
|
||||
bool isXAMAEndBullish;
|
||||
bool isXAMAEndBearish;
|
||||
bool isXAMAStartBullish;
|
||||
bool isXAMAStartBearish;
|
||||
bool isXAMAEndBullishByNeutural;
|
||||
bool isXAMAEndBearishByNeutural;
|
||||
bool isXAMAStartBullishAfterNeutural;
|
||||
bool isXAMAStartBearishAfterNeutural;
|
||||
|
||||
//
|
||||
// XLH ...
|
||||
bool isXLHHHIncreased;
|
||||
bool isXLHHHDecreased;
|
||||
bool isXLHLLIncreased;
|
||||
bool isXLHLLDecreased;
|
||||
bool isXLHLowAttachedLL;
|
||||
bool isXLHHighAttachedHH;
|
||||
bool isXLHHHSameInLength;
|
||||
bool isXLHLLSameInLength;
|
||||
bool isXLHPriceOverSignal;
|
||||
bool isXLHPriceUnderSignal;
|
||||
bool isXLHPriceInSignalRange;
|
||||
bool isXLHPriceCrossedOverSignal;
|
||||
bool isXLHPriceCrossedUnderSignal;
|
||||
|
||||
//
|
||||
// XTD ...
|
||||
bool isXTDSignalPeak;
|
||||
bool isXTDSignalVale;
|
||||
bool isXTDBullishPeak;
|
||||
bool isXTDBullishVale;
|
||||
bool isXTDBearishPeak;
|
||||
bool isXTDBearishVale;
|
||||
bool isXTDBullOverBear;
|
||||
bool isXTDBullUnderBear;
|
||||
bool isXTDSignalOverBear;
|
||||
bool isXTDSignalUnderBear;
|
||||
bool isXTDBullCrossedOverBear;
|
||||
bool isXTDBullCrossedUnderBear;
|
||||
bool isXTDSignalCrossedOverBear;
|
||||
bool isXTDSignalCrossedUnderBear;
|
||||
|
||||
//
|
||||
// XFI ...
|
||||
bool isXFIPeak;
|
||||
bool isXFIVale;
|
||||
bool isXFICrossedOverZero;
|
||||
bool isXFIOverZero;
|
||||
bool isXFICrossedUnderZero;
|
||||
bool isXFIUnderZero;
|
||||
|
||||
//
|
||||
// XTS ...
|
||||
bool isXTSAllSame;
|
||||
bool isXTSCurrentMin;
|
||||
bool isXTSCurrentMax;
|
||||
bool isXTSCurrentOverFarest;
|
||||
bool isXTSCurrentOverNearest;
|
||||
bool isXTSCurrentOverMediest;
|
||||
bool isXTSCurrentUnderFarest;
|
||||
bool isXTSCurrentUnderNearest;
|
||||
bool isXTSCurrentUnderMediest;
|
||||
bool isXTSCurrentCrossedOverFarest;
|
||||
bool isXTSCurrentCrossedOverNearest;
|
||||
bool isXTSCurrentCrossedOverMediest;
|
||||
bool isXTSCurrentCrossedUnderFarest;
|
||||
bool isXTSCurrentCrossedUnderNearest;
|
||||
bool isXTSCurrentCrossedUnderMediest;
|
||||
|
||||
//
|
||||
// XRSI ...
|
||||
bool isXRSIPeak;
|
||||
bool isXRSIVale;
|
||||
bool isXRSICrossedOverLongExit;
|
||||
bool isXRSICrossedOverLongEntry;
|
||||
bool isXRSICrossedUnderShortExit;
|
||||
bool isXRSICrossedUnderShortEntry;
|
||||
|
||||
//
|
||||
// XOBD ...
|
||||
bool isXOBDSwingLow;
|
||||
bool isXOBDSwingHigh;
|
||||
|
||||
//
|
||||
// XCHLH ...
|
||||
//
|
||||
bool isXCHLHSameHHs;
|
||||
bool isXCHLHSameLLs;
|
||||
//
|
||||
bool isXCHLHSCMCHHSame;
|
||||
bool isXCHLHSCMCLLSame;
|
||||
//
|
||||
bool isXCHLHSCLCHHSame;
|
||||
bool isXCHLHSCLCLLSame;
|
||||
//
|
||||
bool isXCHLHMCLCHHSame;
|
||||
bool isXCHLHMCLCLLSame;
|
||||
//
|
||||
bool isXCHLHMCOnTopOfLC;
|
||||
bool isXCHLHMCInBottomOfLC;
|
||||
|
||||
//
|
||||
// XCHMA ...
|
||||
//
|
||||
bool isXCHMASCOverMax;
|
||||
bool isXCHMASCOverMin;
|
||||
bool isXCHMASCUnderMax;
|
||||
bool isXCHMASCUnderMin;
|
||||
//
|
||||
bool isXCHMASCCrossedOverMax;
|
||||
bool isXCHMASCCrossedUnderMax;
|
||||
bool isXCHMASCCrossedOverMin;
|
||||
bool isXCHMASCCrossedUnderMin;
|
||||
//
|
||||
bool isXCHMASCPeak;
|
||||
bool isXCHMASCVale;
|
||||
bool isXCHMASCTrendsUp;
|
||||
bool isXCHMASCTrendsDown;
|
||||
bool isXCHMASCFastOverSlow;
|
||||
bool isXCHMASCFastUnderSlow;
|
||||
bool isXCHMASCFastCrossedOverSlow;
|
||||
bool isXCHMASCFastCrossedUnderSlow;
|
||||
//
|
||||
bool isXCHMAMCPeak;
|
||||
bool isXCHMAMCVale;
|
||||
bool isXCHMAMCTrendsUp;
|
||||
bool isXCHMAMCTrendsDown;
|
||||
bool isXCHMAMCFastOverSlow;
|
||||
bool isXCHMAMCFastUnderSlow;
|
||||
bool isXCHMAMCFastCrossedOverSlow;
|
||||
bool isXCHMAMCFastCrossedUnderSlow;
|
||||
//
|
||||
bool isXCHMALCPeak;
|
||||
bool isXCHMALCVale;
|
||||
bool isXCHMALCTrendsUp;
|
||||
bool isXCHMALCTrendsDown;
|
||||
bool isXCHMALCFastOverSlow;
|
||||
bool isXCHMALCFastUnderSlow;
|
||||
bool isXCHMALCFastCrossedOverSlow;
|
||||
bool isXCHMALCFastCrossedUnderSlow;
|
||||
};
|
||||
```
|
||||
|
||||
## Used Cases
|
||||
|
||||
for each Strategy we have some sort of Conditions, which i try to describe it here
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Define a Function based on Strategy and Signal Type ...
|
||||
bool XStrategyHasLongSignal() {
|
||||
//
|
||||
// Define a result Variable to determines there is a Signal
|
||||
// on Specific Time or not ...
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Start Analysing Market based On Conditions ...
|
||||
result =
|
||||
//
|
||||
// Base Condition:
|
||||
// each Strategy must has a Base Conditions, which they are usually common combinations
|
||||
// of Market Properties that must be happens to lookup for signals ...
|
||||
(
|
||||
//
|
||||
false
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Next Step is combine sorts of Conditions which make our choice
|
||||
// so Exact in Market ...
|
||||
(
|
||||
//
|
||||
false
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Exceptions:
|
||||
// there some commonly Exceptions which makes our choice incorrect,
|
||||
// here we are combined knownly Exceptions ...
|
||||
!(
|
||||
//
|
||||
// for Exception we used XLH Conditions as follow ...
|
||||
//
|
||||
// Check Conditions if Price In Signal Range ...
|
||||
(xAU5Conditions.isXLHPriceInSignalRange &&
|
||||
//
|
||||
(
|
||||
//
|
||||
// Next Step is to Check LL and HH Same Style ...
|
||||
//
|
||||
// Check if Both LL and HH Same In Length ...
|
||||
((xAU5Conditions.isXLHLLSameInLength &&
|
||||
xAU5Conditions.isXLHHHSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check If LL Same In Length ...
|
||||
((xAU5Conditions.isXLHLLSameInLength &&
|
||||
!xAU5Conditions.isXLHHHSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check If HH is Same In Length ...
|
||||
((xAU5Conditions.isXLHHHSameInLength &&
|
||||
!xAU5Conditions.isXLHLLSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Not Same LL or HH in Lenght ...
|
||||
((!xAU5Conditions.isXLHHHSameInLength &&
|
||||
!xAU5Conditions.isXLHLLSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check Conditions if Price is Under Signal ...
|
||||
(
|
||||
//
|
||||
((xAU5Conditions.isXLHPriceUnderSignal ||
|
||||
xAU5Conditions.isXLHPriceCrossedUnderSignal) &&
|
||||
(
|
||||
//
|
||||
// Next Step is to Check LL and HH Same Style ...
|
||||
//
|
||||
// Check if Both LL and HH Same In Length ...
|
||||
((xAU5Conditions.isXLHLLSameInLength &&
|
||||
xAU5Conditions.isXLHHHSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check If LL Same In Length ...
|
||||
((xAU5Conditions.isXLHLLSameInLength &&
|
||||
!xAU5Conditions.isXLHHHSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check If HH is Same In Length ...
|
||||
((xAU5Conditions.isXLHHHSameInLength &&
|
||||
!xAU5Conditions.isXLHLLSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Not Same LL or HH in Lenght ...
|
||||
((!xAU5Conditions.isXLHHHSameInLength &&
|
||||
!xAU5Conditions.isXLHLLSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check Conditions if Price is Over Signal ...
|
||||
(
|
||||
//
|
||||
((xAU5Conditions.isXLHPriceOverSignal ||
|
||||
xAU5Conditions.isXLHPriceCrossedOverSignal) &&
|
||||
(
|
||||
//
|
||||
// Next Step is to Check LL and HH Same Style ...
|
||||
//
|
||||
// Check if Both LL and HH Same In Length ...
|
||||
((xAU5Conditions.isXLHLLSameInLength &&
|
||||
xAU5Conditions.isXLHHHSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check If LL Same In Length ...
|
||||
((xAU5Conditions.isXLHLLSameInLength &&
|
||||
!xAU5Conditions.isXLHHHSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check If HH is Same In Length ...
|
||||
((xAU5Conditions.isXLHHHSameInLength &&
|
||||
!xAU5Conditions.isXLHLLSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Not Same LL or HH in Lenght ...
|
||||
((!xAU5Conditions.isXLHHHSameInLength &&
|
||||
!xAU5Conditions.isXLHLLSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check Conditions if Price is not has clear state ...
|
||||
(
|
||||
//
|
||||
((!xAU5Conditions.isXLHPriceOverSignal &&
|
||||
!xAU5Conditions.isXLHPriceUnderSignal &&
|
||||
!xAU5Conditions.isXLHPriceInSignalRange &&
|
||||
!xAU5Conditions.isXLHPriceCrossedOverSignal &&
|
||||
!xAU5Conditions.isXLHPriceCrossedUnderSignal) &&
|
||||
(
|
||||
//
|
||||
// Next Step is to Check LL and HH Same Style ...
|
||||
//
|
||||
// Check if Both LL and HH Same In Length ...
|
||||
((xAU5Conditions.isXLHLLSameInLength &&
|
||||
xAU5Conditions.isXLHHHSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check If LL Same In Length ...
|
||||
((xAU5Conditions.isXLHLLSameInLength &&
|
||||
!xAU5Conditions.isXLHHHSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Check If HH is Same In Length ...
|
||||
((xAU5Conditions.isXLHHHSameInLength &&
|
||||
!xAU5Conditions.isXLHLLSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Not Same LL or HH in Lenght ...
|
||||
((!xAU5Conditions.isXLHHHSameInLength &&
|
||||
!xAU5Conditions.isXLHLLSameInLength) &&
|
||||
//
|
||||
(
|
||||
false)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// return the result ...
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
## Common Cases
|
||||
|
||||
there are many conditions which contains a combination of one or more condition and they are most commonly used.
|
||||
|
||||
here i described them and document them for prevent time spending to write them in each used case ...
|
||||
|
||||
### Resolve Stop Outs
|
||||
|
||||
in this step just focused on Peaks and Vales;
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Peaks ...
|
||||
// Use Trends Down ...
|
||||
|
||||
//
|
||||
(mConditions.isXCHMASCPeak &&
|
||||
(mConditions.isXCHMASCFastOverSlow ||
|
||||
mConditions.isXCHMASCFastCrossedOverSlow))
|
||||
//
|
||||
|
||||
//
|
||||
(mConditions.isXCHMAMCPeak &&
|
||||
(mConditions.isXCHMAMCFastOverSlow ||
|
||||
mConditions.isXCHMAMCFastCrossedOverSlow))
|
||||
//
|
||||
|
||||
//
|
||||
(mConditions.isXCHMALCPeak &&
|
||||
(mConditions.isXCHMALCFastOverSlow ||
|
||||
mConditions.isXCHMALCFastCrossedOverSlow))
|
||||
|
||||
|
||||
//
|
||||
// Vales ...
|
||||
// Use Trends Up ...
|
||||
|
||||
//
|
||||
(mConditions.isXCHMASCVale &&
|
||||
(mConditions.isXCHMASCFastUnderSlow ||
|
||||
mConditions.isXCHMASCFastCrossedUnderSlow))
|
||||
//
|
||||
|
||||
//
|
||||
(mConditions.isXCHMAMCVale &&
|
||||
(mConditions.isXCHMAMCFastUnderSlow ||
|
||||
mConditions.isXCHMAMCFastCrossedUnderSlow))
|
||||
//
|
||||
|
||||
//
|
||||
(mConditions.isXCHMALCVale &&
|
||||
(mConditions.isXCHMALCFastUnderSlow ||
|
||||
mConditions.isXCHMALCFastCrossedUnderSlow))
|
||||
```
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Unders ...
|
||||
|
||||
//
|
||||
((mConditions.isXCHMASCFastUnderSlow ||
|
||||
mConditions.isXCHMASCFastCrossedUnderSlow) &&
|
||||
(
|
||||
//
|
||||
()
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
|
||||
//
|
||||
((mConditions.isXCHMAMCFastUnderSlow ||
|
||||
mConditions.isXCHMAMCFastCrossedUnderSlow) &&
|
||||
(
|
||||
//
|
||||
()
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
|
||||
//
|
||||
((mConditions.isXCHMALCFastUnderSlow ||
|
||||
mConditions.isXCHMALCFastCrossedUnderSlow) &&
|
||||
(
|
||||
//
|
||||
()
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Overs ...
|
||||
|
||||
//
|
||||
((mConditions.isXCHMASCFastOverSlow ||
|
||||
mConditions.isXCHMASCFastCrossedOverSlow) &&
|
||||
(
|
||||
//
|
||||
()
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
|
||||
//
|
||||
((mConditions.isXCHMAMCFastOverSlow ||
|
||||
mConditions.isXCHMAMCFastCrossedOverSlow) &&
|
||||
(
|
||||
//
|
||||
()
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
|
||||
//
|
||||
((mConditions.isXCHMALCFastOverSlow ||
|
||||
mConditions.isXCHMALCFastCrossedOverSlow) &&
|
||||
(
|
||||
//
|
||||
()
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
```
|
||||
|
||||
### Resolve Old Guard Attacks
|
||||
|
||||
in this step complete conditions;
|
||||
|
||||
### Resolve DrawDown Guard Attacks
|
||||
|
||||
in this step complete conditions;
|
||||
|
||||
### XCHMA Max Min Exceptions
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Exception Cases for XCHMA Min or Max ...
|
||||
(
|
||||
//
|
||||
// XCHMA MAX ...
|
||||
(
|
||||
//
|
||||
(mConditions.isXCHMASCOverMax ||
|
||||
mConditions.isXCHMASCCrossedOverMax) &&
|
||||
(mConditions.isXCHMASCUnderMax ||
|
||||
mConditions.isXCHMASCCrossedUnderMax)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// XCHMA MIN ...
|
||||
(
|
||||
//
|
||||
(mConditions.isXCHMASCOverMin ||
|
||||
mConditions.isXCHMASCCrossedOverMin) &&
|
||||
(mConditions.isXCHMASCUnderMin ||
|
||||
mConditions.isXCHMASCCrossedUnderMin)
|
||||
//
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
### XCHMA Cycles State
|
||||
|
||||
#### Short Cycle
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Check Bullish ...
|
||||
bool isXCHMASCBullish =
|
||||
//
|
||||
(mConditions.isXCHMASCFastOverSlow ||
|
||||
mConditions.isXCHMASCFastCrossedOverSlow)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Check Full Bullish ...
|
||||
bool isXCHMASCFullBullish =
|
||||
//
|
||||
(isXCHMASCBullish &&
|
||||
!isXCHMASCTrendsDown)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Check Bearish ...
|
||||
bool isXCHMASCBearish =
|
||||
//
|
||||
(mConditions.isXCHMASCFastUnderSlow ||
|
||||
mConditions.isXCHMASCFastCrossedUnderSlow)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Check Full Bearish ...
|
||||
bool isXCHMASCFullBearish =
|
||||
//
|
||||
(isXCHMASCBearish &&
|
||||
!isXCHMASCTrendsDown)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Check Not Vale and Peak ...
|
||||
bool isXCHMASCNormal =
|
||||
//
|
||||
(!mConditions.isXCHMASCPeak &&
|
||||
!mConditions.isXCHMASCVale)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
#### Medium Cycle
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Check Bullish ...
|
||||
bool isXCHMAMCBullish =
|
||||
//
|
||||
(mConditions.isXCHMAMCFastOverSlow ||
|
||||
mConditions.isXCHMAMCFastCrossedOverSlow)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Check Full Bullish ...
|
||||
bool isXCHMAMCFullBullish =
|
||||
//
|
||||
(isXCHMAMCBullish &&
|
||||
!isXCHMAMCTrendsDown)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Check Bearish ...
|
||||
bool isXCHMAMCBearish =
|
||||
//
|
||||
(mConditions.isXCHMAMCFastUnderSlow ||
|
||||
mConditions.isXCHMAMCFastCrossedUnderSlow)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Check Full Bearish ...
|
||||
bool isXCHMAMCFullBearish =
|
||||
//
|
||||
(isXCHMAMCBearish &&
|
||||
!isXCHMAMCTrendsDown)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Check Not Vale and Peak ...
|
||||
bool isXCHMAMCNormal =
|
||||
//
|
||||
(!mConditions.isXCHMAMCPeak &&
|
||||
!mConditions.isXCHMAMCVale)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
#### Long Cycle
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Check Bullish ...
|
||||
bool isXCHMALCBullish =
|
||||
//
|
||||
(mConditions.isXCHMALCFastOverSlow ||
|
||||
mConditions.isXCHMALCFastCrossedOverSlow)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Check Full Bullish ...
|
||||
bool isXCHMALCFullBullish =
|
||||
//
|
||||
(isXCHMALCBullish &&
|
||||
!isXCHMALCTrendsDown)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Check Bearish ...
|
||||
bool isXCHMALCBearish =
|
||||
//
|
||||
(mConditions.isXCHMALCFastUnderSlow ||
|
||||
mConditions.isXCHMALCFastCrossedUnderSlow)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Check Full Bearish ...
|
||||
bool isXCHMALCFullBearish =
|
||||
//
|
||||
(isXCHMALCBearish &&
|
||||
!isXCHMALCTrendsDown)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// Check Not Vale and Peak ...
|
||||
bool isXCHMALCNormal =
|
||||
//
|
||||
(!mConditions.isXCHMALCPeak &&
|
||||
!mConditions.isXCHMALCVale)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
### XCHMA Bullish Trend
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// XCHMA Bullish Trend ...
|
||||
bool isXCHMABullish =
|
||||
//
|
||||
(
|
||||
//
|
||||
// All of Cycles Bullish ...
|
||||
(isXCHMASCBullish &&
|
||||
isXCHMAMCBullish &&
|
||||
isXCHMALCBullish)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Two of Cycles Bullish ...
|
||||
(
|
||||
//
|
||||
(isXCHMASCBullish &&
|
||||
isXCHMAMCBullish)
|
||||
//
|
||||
||
|
||||
//
|
||||
(isXCHMASCBullish &&
|
||||
isXCHMALCBullish)
|
||||
//
|
||||
||
|
||||
//
|
||||
(isXCHMAMCBullish &&
|
||||
isXCHMALCBullish)
|
||||
//
|
||||
)
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// XCHMA Full Bullish Trend ...
|
||||
bool isXCHMAFullBullish =
|
||||
//
|
||||
(
|
||||
//
|
||||
// All of Cycles Fully Bullish ...
|
||||
(isXCHMASCFullBullish &&
|
||||
isXCHMAMCFullBullish &&
|
||||
isXCHMALCFullBullish)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Two Of Cycles Fully Bullish ...
|
||||
(
|
||||
//
|
||||
(isXCHMASCFullBullish &&
|
||||
isXCHMAMCFullBullish)
|
||||
//
|
||||
||
|
||||
//
|
||||
(isXCHMASCFullBullish &&
|
||||
isXCHMALCFullBullish)
|
||||
//
|
||||
||
|
||||
//
|
||||
(isXCHMAMCFullBullish &&
|
||||
isXCHMALCFullBullish)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
```
|
||||
|
||||
### XCHMA Bearish Trend
|
||||
|
||||
```MQ5
|
||||
//
|
||||
// XCHMA Bearish Trend ...
|
||||
bool isXCHMABearish =
|
||||
//
|
||||
(
|
||||
//
|
||||
// All of Cycles Bearish ...
|
||||
(isXCHMASCBearish &&
|
||||
isXCHMAMCBearish &&
|
||||
isXCHMALCBearish)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Two of Cycles Bearish ...
|
||||
(
|
||||
//
|
||||
(isXCHMASCBearish &&
|
||||
isXCHMAMCBearish)
|
||||
//
|
||||
||
|
||||
//
|
||||
(isXCHMASCBearish &&
|
||||
isXCHMALCBearish)
|
||||
//
|
||||
||
|
||||
//
|
||||
(isXCHMAMCBearish &&
|
||||
isXCHMALCBearish)
|
||||
//
|
||||
)
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// XCHMA Full Bearish Trend ...
|
||||
bool isXCHMAFullBearish =
|
||||
//
|
||||
(
|
||||
//
|
||||
// All of Cycles Fully Bearish ...
|
||||
(isXCHMASCFullBearish &&
|
||||
isXCHMAMCFullBearish &&
|
||||
isXCHMALCFullBearish)
|
||||
//
|
||||
||
|
||||
//
|
||||
// Two Of Cycles Fully Bearish ...
|
||||
(
|
||||
//
|
||||
(isXCHMASCFullBearish &&
|
||||
isXCHMAMCFullBearish)
|
||||
//
|
||||
||
|
||||
//
|
||||
(isXCHMASCFullBearish &&
|
||||
isXCHMALCFullBearish)
|
||||
//
|
||||
||
|
||||
//
|
||||
(isXCHMAMCFullBearish &&
|
||||
isXCHMALCFullBearish)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
```
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,171 @@
|
||||
|
||||
//
|
||||
// Enable Signaller ...
|
||||
bool EnableSXSIGNALLERNAMEignaller() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (mXSIGNALLERNAMEEnableSignaller) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
mXSIGNALLERNAMEEnableSignaller = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Disable Signaller ...
|
||||
bool DisbaleXSIGNALLERNAMESignaller() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!mXSIGNALLERNAMEEnableSignaller) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
mXSIGNALLERNAMEEnableSignaller = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Allow Sginaller to Issue Long Signals ...
|
||||
bool EnableXSIGNALLERNAMELongs() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!mXSIGNALLERNAMEEnableSignaller ||
|
||||
mXSIGNALLERNAMEAllowLongSignals
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
mXSIGNALLERNAMEAllowLongSignals = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Disallow Signaller to Issue Long Signals ...
|
||||
bool DisbaleXSIGNALLERNAMELongs() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!mXSIGNALLERNAMEEnableSignaller ||
|
||||
!mXSIGNALLERNAMEAllowLongSignals
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
mXSIGNALLERNAMEAllowLongSignals = false;
|
||||
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Allow Signaller to Issue Short Sginals ...
|
||||
bool EnableXSIGNALLERNAMEShorts() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!mXSIGNALLERNAMEEnableSignaller ||
|
||||
mXSIGNALLERNAMEAllowShortSignals
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
mXSIGNALLERNAMEAllowShortSignals = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Disallow Signaller to Issue Short Signals ...
|
||||
bool DisableXSIGNALLERNAMEShorts() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!mXSIGNALLERNAMEEnableSignaller ||
|
||||
!mXSIGNALLERNAMEAllowShortSignals
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
mXSIGNALLERNAMEAllowShortSignals = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Market Base Conditions for Long Signals ...
|
||||
bool XSIGNALLERNAMEHasLongConditions() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!mXSIGNALLERNAMEEnableSignaller ||
|
||||
!mXSIGNALLERNAMEAllowLongSignals
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Market Base Conditions for Short Signals ...
|
||||
bool XSIGNALLERNAMEHasShortConditions() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!mXSIGNALLERNAMEEnableSignaller ||
|
||||
!mXSIGNALLERNAMEAllowShortSignals
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,347 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// ----------------------------------------
|
||||
// Name: XAUUSD
|
||||
// Description: this is an expert controller
|
||||
// advisors which provides a mechanism for use them ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XEU5 EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "Commons";
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Logger Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Alert Library ...
|
||||
#include "../Libraries/x-saherelm.alert.lib.mq5"
|
||||
|
||||
//
|
||||
// Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// XEU5 Signal Provider ...
|
||||
#include "../Providers/x-saherelm.xeu5.provider.lib.mq5"
|
||||
|
||||
//
|
||||
// END Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
bool isXEU5NewHour;
|
||||
bool isXEU5NewDay;
|
||||
bool isXEU5NewWeek;
|
||||
bool isXEU5NewMonth;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
logTag = "XEU5EA";
|
||||
drawPrefix = logTag;
|
||||
alertPrefix = logTag;
|
||||
|
||||
//
|
||||
// Apply default Chart Style for EA ...
|
||||
ApplyChartStyle();
|
||||
|
||||
//
|
||||
// Reset Timings ...
|
||||
ResetTiming();
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize XEU5 Provider ...
|
||||
if (!XEU5InitSignalProviderLibrary())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
// De Initialize XEU5 Provider ...
|
||||
XEU5DeinitSignalProviderLibrary(reason);
|
||||
|
||||
//
|
||||
// De Init XDraw Library ...
|
||||
// OnDeinitDrawLibrary();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// Handle Monthly Alert ...
|
||||
bool isFirstMonth = xMonth == -1;
|
||||
isXEU5NewMonth = IsNewMonth();
|
||||
bool canMonthlyAlert =
|
||||
isXEU5NewMonth &&
|
||||
xEU5EnableAlerts &&
|
||||
xEU5EnableMonthlyAlerts;
|
||||
bool canMonthlyReport =
|
||||
!isFirstMonth &&
|
||||
canMonthlyAlert &&
|
||||
xEU5EnableMonthlyReports;
|
||||
if (canMonthlyAlert)
|
||||
{
|
||||
//
|
||||
string message = "New Month ...";
|
||||
|
||||
//
|
||||
// Prepare Monthly Report ...
|
||||
if (canMonthlyReport)
|
||||
{
|
||||
//
|
||||
string report = xEU5Reporter.GenerateReportString(XREPORT_MONTHLY);
|
||||
|
||||
//
|
||||
message = "Last Month Report:\n" + report;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset Report ...
|
||||
xEU5Reporter.Reset(XREPORT_MONTHLY);
|
||||
|
||||
//
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Weekly Alert ...
|
||||
bool isFirstWeek = xDayOfWeek == -1;
|
||||
isXEU5NewWeek = IsNewWeek();
|
||||
bool canWeeklyAlert =
|
||||
isXEU5NewWeek &&
|
||||
xEU5EnableAlerts &&
|
||||
xEU5EnableWeeklyAlerts;
|
||||
bool canWeeklyReport =
|
||||
!isFirstWeek &&
|
||||
canWeeklyAlert &&
|
||||
xEU5EnableWeeklyReports;
|
||||
if (canWeeklyAlert)
|
||||
{
|
||||
//
|
||||
string message = "New Week ...";
|
||||
|
||||
//
|
||||
// Prepare Weekly Report ...
|
||||
if (canWeeklyReport)
|
||||
{
|
||||
//
|
||||
string report = xEU5Reporter.GenerateReportString(XREPORT_WEEKLY);
|
||||
|
||||
//
|
||||
message = "Last Week Report:\n" + report;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset Report ...
|
||||
xEU5Reporter.Reset(XREPORT_WEEKLY);
|
||||
|
||||
//
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Daily Alert ...
|
||||
bool isFirstDay = xDay == -1;
|
||||
isXEU5NewDay = IsNewDay();
|
||||
bool canDailyAlert =
|
||||
isXEU5NewDay &&
|
||||
xEU5EnableAlerts &&
|
||||
xEU5EnableDailyAlerts;
|
||||
bool canDailyReport =
|
||||
!isFirstDay &&
|
||||
canDailyAlert &&
|
||||
xEU5EnableDailyReports;
|
||||
if (canDailyAlert)
|
||||
{
|
||||
//
|
||||
string message = "New Day ...";
|
||||
|
||||
//
|
||||
// Prepare Daily Report ...
|
||||
if (canDailyReport)
|
||||
{
|
||||
//
|
||||
string report = xEU5Reporter.GenerateReportString(XREPORT_DAILY);
|
||||
|
||||
//
|
||||
message = "Last Week Report:\n" + report;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset Report ...
|
||||
xEU5Reporter.Reset(XREPORT_DAILY);
|
||||
|
||||
//
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Hourly Alert ...
|
||||
bool isFirstHour = xHour == -1;
|
||||
isXEU5NewHour = IsNewHour();
|
||||
bool canHourlyAlert =
|
||||
isXEU5NewHour &&
|
||||
xEU5EnableAlerts &&
|
||||
xEU5EnableHourlyAlerts;
|
||||
if (canHourlyAlert)
|
||||
{
|
||||
//
|
||||
string message = "New Hour ...";
|
||||
|
||||
//
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xEU5EnableProvider)
|
||||
{
|
||||
//
|
||||
// Handle Processing on XEU5 Signal Provider ...
|
||||
XEU5SignalProviderDoControlState();
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsNewCandle())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xEU5EnableProvider)
|
||||
{
|
||||
//
|
||||
// Handle Processing on XEU5 Signal Provider ...
|
||||
XEU5SignalProviderHandleTick();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Trade Events ...
|
||||
void OnTrade()
|
||||
{
|
||||
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xEU5EnableProvider)
|
||||
{
|
||||
//
|
||||
// Handle Processing Trades on XEU5 Signal Provider ...
|
||||
XEU5SignalProviderHandleTrade();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
|
||||
//
|
||||
// Validate XEU5 Provider Inputs ...
|
||||
result = XEU5ValidateInputs();
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging State ...
|
||||
string message = "Validation of (" + logTag + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,607 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XAMA Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XAMA Indicator States ...
|
||||
enum ENUM_X_XAMA_STATES
|
||||
{
|
||||
X_XAMA_BULLISH = 1,
|
||||
X_XAMA_BEARISH = -1,
|
||||
X_XAMA_NEUTURAL = 0,
|
||||
};
|
||||
|
||||
//
|
||||
// XAMA Indicator Buffer Lines ...
|
||||
enum ENUM_X_XAMA_BUFFER_LINES
|
||||
{
|
||||
X_XAMA_MA_LINE = 0,
|
||||
X_XAMA_MC_COLOR_LINE = 1,
|
||||
X_XAMA_STATE_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XAMA Indicator";
|
||||
|
||||
//
|
||||
// input int xAMALength = 18; // Market Length
|
||||
// input int xAMAFastEMA = 2; // Fast EMA Period
|
||||
// input int xAMASlowEMA = 30; // Slow EMA Period
|
||||
// input int xAMAShift = 0; // Shift
|
||||
// input ENUM_APPLIED_PRICE xAMAAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xAMALength = 18; // Market Length
|
||||
int xAMAFastEMA = 2; // Fast EMA Period
|
||||
int xAMASlowEMA = 30; // Slow EMA Period
|
||||
int xAMAShift = 0; // Shift
|
||||
ENUM_APPLIED_PRICE xAMAAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xAMAHandler = INVALID_HANDLE;
|
||||
double xAMAMaBuffer[];
|
||||
double xAMAStateBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XAMAValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
xAMALength > 2 &&
|
||||
xAMAFastEMA < xAMALength &&
|
||||
xAMAFastEMA < xAMASlowEMA &&
|
||||
xAMAShift >= 0;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XAMA Indicator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XAMAInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Indicator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XAMA Handler ...
|
||||
ArraySetAsSeries(xAMAMaBuffer, true);
|
||||
ArraySetAsSeries(xAMAStateBuffer, true);
|
||||
xAMAHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xama.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xAMALength,
|
||||
xAMAFastEMA,
|
||||
xAMASlowEMA,
|
||||
xAMAShift,
|
||||
xAMAAppliedTo
|
||||
//
|
||||
);
|
||||
if (xAMAHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XAMA Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XAMAReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xAMAHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XAMAReadBuffers(
|
||||
int xAMAItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XAMA Ma Buffer ...
|
||||
CopyBuffer(
|
||||
xAMAHandler,
|
||||
X_XAMA_MA_LINE,
|
||||
0,
|
||||
xAMAItemsPerTick,
|
||||
xAMAMaBuffer);
|
||||
|
||||
//
|
||||
// XAMA State Buffer ...
|
||||
CopyBuffer(
|
||||
xAMAHandler,
|
||||
X_XAMA_STATE_LINE,
|
||||
0,
|
||||
xAMAItemsPerTick,
|
||||
xAMAStateBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XAMA Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check SC is Peak ...
|
||||
bool XAMAIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xAMAMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check SC is Vale ...
|
||||
bool XAMAIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xAMAMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up ...
|
||||
bool XAMAIsStartBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BULLISH &&
|
||||
xAMAStateBuffer[bar_index + 1] != X_XAMA_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up After Neutural State ...
|
||||
bool XAMAIsStartBullishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BULLISH &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Up State ...
|
||||
bool XAMAIsBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State ...
|
||||
bool XAMAIsEndBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] != X_XAMA_BULLISH &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State By Neutural ...
|
||||
bool XAMAIsEndBullishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_NEUTURAL &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down ...
|
||||
bool XAMAIsStartBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BEARISH &&
|
||||
xAMAStateBuffer[bar_index + 1] != X_XAMA_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down After Neutural State ...
|
||||
bool XAMAIsStartBearishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BEARISH &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Down State ...
|
||||
bool XAMAIsBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State ...
|
||||
bool XAMAIsEndBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] != X_XAMA_BEARISH &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State By Neutural ...
|
||||
bool XAMAIsEndBearishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_NEUTURAL &&
|
||||
xAMAStateBuffer[bar_index + 1] == X_XAMA_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Neutural State ...
|
||||
bool XAMAIsNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XAMAIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xAMAStateBuffer[bar_index] == X_XAMA_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XAMAIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xAMAMaBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XAMA Custom Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,358 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XFI Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XFI Oscillator";
|
||||
|
||||
// //
|
||||
// input int xFILength = 18; // Market Length
|
||||
// input ENUM_MA_METHOD xFIMethod = MODE_SMA; // MA Method
|
||||
// input ENUM_APPLIED_VOLUME xFIAppliedTo = VOLUME_TICK; // Applied To
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xFILength = 18; // Market Length
|
||||
ENUM_MA_METHOD xFIMethod = MODE_SMA; // MA Method
|
||||
ENUM_APPLIED_VOLUME xFIAppliedTo = VOLUME_TICK; // Applied To
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xFIHandler = INVALID_HANDLE;
|
||||
double xFIBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XFIValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xFILength > 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XFI Oscillator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XFIInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XFI Handler ...
|
||||
ArraySetAsSeries(xFIBuffer, true);
|
||||
xFIHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xfi.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
xFILength,
|
||||
xFIMethod,
|
||||
xFIAppliedTo
|
||||
//
|
||||
);
|
||||
if (xFIHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XFI Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XFIReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xFIHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XFIReadBuffers(
|
||||
int xFIItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XFI Signal ...
|
||||
CopyBuffer(
|
||||
xFIHandler,
|
||||
0,
|
||||
0,
|
||||
xFIItemsPerTick,
|
||||
xFIBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XFI Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check SC is Peak ...
|
||||
bool XFIIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xFIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check SC is Vale ...
|
||||
bool XFIIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xFIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect XFI Crossed Over Zero ...
|
||||
bool XFIIsCrossedOverZero(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xFIBuffer[bar_index] > 0 &&
|
||||
xFIBuffer[bar_index + 1] <= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect XFI Over Zero ...
|
||||
bool XFIIsOverZero(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xFIBuffer[bar_index] > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect XFI Crossed Under Zero ...
|
||||
bool XFIIsCrossedUnderZero(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xFIBuffer[bar_index] < 0 &&
|
||||
xFIBuffer[bar_index + 1] >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect XFI Under Zero ...
|
||||
bool XFIIsUnderZero(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XFIIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xFIBuffer[bar_index] < 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XFIIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xFIBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XFI Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,668 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XLH Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XLH Indicator Buffer Lines ...
|
||||
enum ENUM_X_XLH_BUFFER_LINES
|
||||
{
|
||||
X_XLH_HH_LINE = 0,
|
||||
X_XLH_LL_LINE = 1,
|
||||
X_XLH_SIGNAL_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XLH Indicator";
|
||||
|
||||
// input int xLHLength = 72; // Length
|
||||
// input ENUM_SERIESMODE xLHHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
// input ENUM_SERIESMODE xLHLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xLHLength = 72; // Length
|
||||
ENUM_SERIESMODE xLHHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
ENUM_SERIESMODE xLHLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
int xLHHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
double xLHHHBuffer[];
|
||||
double xLHLLBuffer[];
|
||||
double xLHSignalBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XLHValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xLHLength >= 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XLH Indicator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XLHInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XLH Handler ...
|
||||
ArraySetAsSeries(xLHHHBuffer, true);
|
||||
ArraySetAsSeries(xLHLLBuffer, true);
|
||||
ArraySetAsSeries(xLHSignalBuffer, true);
|
||||
|
||||
//
|
||||
xLHHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xlh.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xLHLength,
|
||||
xLHHHMode,
|
||||
xLHLLMode
|
||||
//
|
||||
);
|
||||
if (xLHHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XLH Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XLHReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xLHHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XLHReadBuffers(
|
||||
int xLHItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// HH Buffer ...
|
||||
CopyBuffer(
|
||||
xLHHandler,
|
||||
X_XLH_HH_LINE,
|
||||
0,
|
||||
xLHItemsPerTick,
|
||||
xLHHHBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// LL Buffer ...
|
||||
CopyBuffer(
|
||||
xLHHandler,
|
||||
X_XLH_LL_LINE,
|
||||
0,
|
||||
xLHItemsPerTick,
|
||||
xLHLLBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
CopyBuffer(
|
||||
xLHHandler,
|
||||
X_XLH_SIGNAL_LINE,
|
||||
0,
|
||||
xLHItemsPerTick,
|
||||
xLHSignalBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XLH Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TODO: What we have to Implement ...
|
||||
// - []
|
||||
|
||||
//
|
||||
// Check Candle High is HH ...
|
||||
bool XLHIsHighAttachedHH(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle.high == xLHHHBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Candle Low is LL ...
|
||||
bool XLHIsLowAttachedLL(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle.low == xLHLLBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Jumping Up Signal ...
|
||||
bool XLHIsPriceCrossedOverSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
XOHCL candle2 = GetCandle(bar_index + 1);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.low > xLHSignalBuffer[bar_index] &&
|
||||
candle2.low < xLHSignalBuffer[bar_index + 1]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Over Signal ...
|
||||
bool XLHIsPriceOverSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.low > xLHSignalBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Jumping Down Signal ...
|
||||
bool XLHIsPriceCrossedUnderSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
XOHCL candle2 = GetCandle(bar_index + 1);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.high < xLHSignalBuffer[bar_index] &&
|
||||
candle2.high > xLHSignalBuffer[bar_index + 1]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Down Signal ...
|
||||
bool XLHIsPriceUnderSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.high < xLHSignalBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Ranging Signal ...
|
||||
bool XLHIsPriceInSignalRange(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.high > xLHSignalBuffer[bar_index] &&
|
||||
candle1.low < xLHSignalBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check HH Increased ...
|
||||
bool XLHIsHHIncreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHHHBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check HH Decreased ...
|
||||
bool XLHIsHHDecreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHHHBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LL Increased ...
|
||||
bool XLHIsLLIncreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHLLBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LL Decreased ...
|
||||
bool XLHIsLLDecreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHLLBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check HH Same in Length ...
|
||||
bool XLHIsHHSameInLength(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 5 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double value1 = xLHHHBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Loop ...
|
||||
result = true;
|
||||
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
||||
{
|
||||
//
|
||||
double iValue = xLHHHBuffer[i];
|
||||
if (iValue != value1)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LL Same in Length ...
|
||||
bool XLHIsLLSameInLength(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 5 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double value1 = xLHLLBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Loop ...
|
||||
result = true;
|
||||
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
||||
{
|
||||
//
|
||||
double iValue = xLHLLBuffer[i];
|
||||
if (iValue != value1)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XLHIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xLHHHBuffer) < size ||
|
||||
ArraySize(xLHLLBuffer) < size ||
|
||||
ArraySize(xLHSignalBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XLH Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,249 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XOBD Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XOBD Indicator";
|
||||
|
||||
// input int xOBDLength = 5; // Swing Length
|
||||
// input uchar xOBDSwingHighArrowCode = 108; // Swing High Arrow Code
|
||||
// input color xOBDSwingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
||||
// input uchar xOBDSwingLowArrowCode = 108; // Swing Low Arrow Code
|
||||
// input color xOBDSwingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xOBDLength = 5; // Swing Length
|
||||
uchar xOBDSwingHighArrowCode = 108; // Swing High Arrow Code
|
||||
color xOBDSwingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
||||
uchar xOBDSwingLowArrowCode = 108; // Swing Low Arrow Code
|
||||
color xOBDSwingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
int xOBDHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
double xOBDBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XOBDValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xOBDLength >= 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XOBD Indicator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XOBDInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XOBD Handler ...
|
||||
ArraySetAsSeries(xOBDBuffer, true);
|
||||
|
||||
//
|
||||
xOBDHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xobd.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xOBDLength,
|
||||
xOBDSwingHighArrowCode,
|
||||
xOBDSwingHighArrowColor,
|
||||
xOBDSwingLowArrowCode,
|
||||
xOBDSwingLowArrowColor
|
||||
//
|
||||
);
|
||||
if (xOBDHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XOBD Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XOBDReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xOBDHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XOBDReadBuffers(
|
||||
int xOBDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// OBD Buffer ...
|
||||
CopyBuffer(
|
||||
xOBDHandler,
|
||||
0,
|
||||
0,
|
||||
xOBDItemsPerTick,
|
||||
xOBDBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XOBD Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check is Swing Low Occured or not ...
|
||||
bool XOBDIsSwingLow(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XOBDIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = xOBDBuffer[bar_index] == X_SWING_LOW;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check is Swing High Occured or not ...
|
||||
bool XOBDIsSwingHigh(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XOBDIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = xOBDBuffer[bar_index] == X_SWING_HIGH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XOBDIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xOBDBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XOBD Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,433 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XRSI Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XRSI Oscillator Buffer Lines ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XRSI Oscillator";
|
||||
|
||||
// //
|
||||
// input group "XRSI Market";
|
||||
// input int xRSILength = 18; // Market Length
|
||||
// input ENUM_APPLIED_PRICE xRSIAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
// //
|
||||
// input group "XRSI Short Entry";
|
||||
// input double xRSIShortEntryValue = 70; // Short Entry Level
|
||||
// input color xRSIShortEntryColor = clrRed; // Short Entry Level Color
|
||||
// input ENUM_LINE_STYLE xRSIShortEntryLineStyle = STYLE_SOLID; // Short Entry Style
|
||||
|
||||
// //
|
||||
// input group "XRSI Short Exit";
|
||||
// input double xRSIShortExitValue = 40; // Short Exit Level
|
||||
// input color xRSIShortExitColor = clrRed; // Short Exit Level Color
|
||||
// input ENUM_LINE_STYLE xRSIShortExitLineStyle = STYLE_DOT; // Short Exit Style
|
||||
|
||||
// //
|
||||
// input group "XRSI Long Entry";
|
||||
// input double xRSILongEntryValue = 30; // Long Entry Level
|
||||
// input color xRSILongEntryColor = clrRed; // Long Entry Level Color
|
||||
// input ENUM_LINE_STYLE xRSILongEntryLineStyle = STYLE_SOLID; // Long Entry Style
|
||||
|
||||
// //
|
||||
// input group "XRSI Long Exit";
|
||||
// input double xRSILongExitValue = 60; // Long Exit Level
|
||||
// input color xRSILongExitColor = clrRed; // Long Exit Level Color
|
||||
// input ENUM_LINE_STYLE xRSILongExitLineStyle = STYLE_DOT; // Long Exit Style
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xRSILength = 18; // Market Length
|
||||
ENUM_APPLIED_PRICE xRSIAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
//
|
||||
double xRSIShortEntryValue = 70; // Short Entry Level
|
||||
color xRSIShortEntryColor = clrRed; // Short Entry Level Color
|
||||
ENUM_LINE_STYLE xRSIShortEntryLineStyle = STYLE_SOLID; // Short Entry Style
|
||||
|
||||
//
|
||||
double xRSIShortExitValue = 40; // Short Exit Level
|
||||
color xRSIShortExitColor = clrRed; // Short Exit Level Color
|
||||
ENUM_LINE_STYLE xRSIShortExitLineStyle = STYLE_DOT; // Short Exit Style
|
||||
|
||||
//
|
||||
double xRSILongEntryValue = 30; // Long Entry Level
|
||||
color xRSILongEntryColor = clrRed; // Long Entry Level Color
|
||||
ENUM_LINE_STYLE xRSILongEntryLineStyle = STYLE_SOLID; // Long Entry Style
|
||||
|
||||
//
|
||||
double xRSILongExitValue = 60; // Long Exit Level
|
||||
color xRSILongExitColor = clrRed; // Long Exit Level Color
|
||||
ENUM_LINE_STYLE xRSILongExitLineStyle = STYLE_DOT; // Long Exit Style
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xRSIHandler = INVALID_HANDLE;
|
||||
double xRSIBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XRSIValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
xRSILongEntryValue < xRSILongExitValue &&
|
||||
xRSIShortEntryValue > xRSIShortExitValue &&
|
||||
xRSIShortEntryValue > xRSILongExitValue &&
|
||||
xRSIShortExitValue < xRSILongExitValue;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XRSI Oscillator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XRSIInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XRSI Handler ...
|
||||
ArraySetAsSeries(xRSIBuffer, true);
|
||||
xRSIHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xrsi.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
xRSILength,
|
||||
xRSIAppliedTo,
|
||||
//
|
||||
// Short Entry ...
|
||||
"",
|
||||
xRSIShortEntryValue,
|
||||
xRSIShortEntryColor,
|
||||
xRSIShortEntryLineStyle,
|
||||
//
|
||||
// Short Exit ...
|
||||
"",
|
||||
xRSIShortExitValue,
|
||||
xRSIShortExitColor,
|
||||
xRSIShortExitLineStyle,
|
||||
//
|
||||
// Long Entry ...
|
||||
"",
|
||||
xRSILongEntryValue,
|
||||
xRSILongEntryColor,
|
||||
xRSILongEntryLineStyle,
|
||||
//
|
||||
// Long Exit ...
|
||||
"",
|
||||
xRSILongExitValue,
|
||||
xRSILongExitColor,
|
||||
xRSILongExitLineStyle
|
||||
//
|
||||
);
|
||||
if (xRSIHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XRSI Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XRSIReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xRSIHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XRSIReadBuffers(
|
||||
int xRSIItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XRSI Signal ...
|
||||
CopyBuffer(
|
||||
xRSIHandler,
|
||||
0,
|
||||
0,
|
||||
xRSIItemsPerTick,
|
||||
xRSIBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XRSI Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check SC is Peak ...
|
||||
bool XRSIIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xRSIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check SC is Vale ...
|
||||
bool XRSIIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xRSIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value GO Up from Long Entry ...
|
||||
bool XRSIIsCrossedOverLongEntry(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] > xRSILongEntryValue &&
|
||||
xRSIBuffer[bar_index + 2] <= xRSILongEntryValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value GO Up from Long Exit ...
|
||||
bool XRSIIsCrossedOverLongExit(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] > xRSILongExitValue &&
|
||||
xRSIBuffer[bar_index + 2] <= xRSILongExitValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value Go Down Short Entry ...
|
||||
bool XRSIIsCrossedUnderShortEntry(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] < xRSIShortEntryValue &&
|
||||
xRSIBuffer[bar_index + 2] >= xRSIShortEntryValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value Go Down Short Exit ...
|
||||
bool XRSIIsCrossedUnderShortExit(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] < xRSIShortExitValue &&
|
||||
xRSIBuffer[bar_index + 2] >= xRSIShortExitValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XRSIIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xRSIBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XRSI Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,931 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTD Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XTD Oscillator States ...
|
||||
enum ENUM_X_XTD_STATES
|
||||
{
|
||||
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
|
||||
X_XTD_BULLISH_OVER_BEARISH = 1,
|
||||
X_XTD_NEUTURAL = 0,
|
||||
X_XTD_BULLISH_UNDER_BEARISH = -1,
|
||||
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
|
||||
};
|
||||
|
||||
//
|
||||
// XTD Oscillator Buffer Lines ...
|
||||
enum ENUM_X_XTD_BUFFER_LINES
|
||||
{
|
||||
X_XTD_BULLISH_POWER_LINE = 0,
|
||||
X_XTD_BEARISH_POWER_LINE = 1,
|
||||
X_XTD_SIGNAL_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XTD Oscillator";
|
||||
|
||||
// input int xTDLength = 18; // Market Length
|
||||
// input bool xTDDrawCrosses = false; // Draw Cross Arrows
|
||||
// input uchar xTDBullishArrowCode = 228; // Cross Over Arrow Code
|
||||
// input color xTDBullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||
// input uchar xTDBearishArrowCode = 230; // Cross Under Arrow Code
|
||||
// input color xTDBearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xTDLength = 18; // Market Length
|
||||
bool xTDDrawCrosses = false; // Draw Cross Arrows
|
||||
uchar xTDBullishArrowCode = 228; // Cross Over Arrow Code
|
||||
color xTDBullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||
uchar xTDBearishArrowCode = 230; // Cross Under Arrow Code
|
||||
color xTDBearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xTDHandler = INVALID_HANDLE;
|
||||
double xTDBullishBuffer[];
|
||||
double xTDBearishBuffer[];
|
||||
double xTDSignalBuffer[];
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XTDValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xTDLength >= 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XTD Oscillator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XTDInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XTD Handler ...
|
||||
ArraySetAsSeries(xTDBullishBuffer, true);
|
||||
ArraySetAsSeries(xTDBearishBuffer, true);
|
||||
ArraySetAsSeries(xTDSignalBuffer, true);
|
||||
xTDHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xtd.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
xTDLength,
|
||||
xTDDrawCrosses,
|
||||
xTDBullishArrowCode,
|
||||
xTDBullishArrowColor,
|
||||
xTDBearishArrowCode,
|
||||
xTDBearishArrowColor);
|
||||
if (xTDHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XTD Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XTDReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xTDHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XTDReadBuffers(
|
||||
int xTDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XTD Bullish Buffer ...
|
||||
CopyBuffer(
|
||||
xTDHandler,
|
||||
X_XTD_BULLISH_POWER_LINE,
|
||||
0,
|
||||
xTDItemsPerTick,
|
||||
xTDBullishBuffer);
|
||||
|
||||
//
|
||||
// XTD Bullish Buffer ...
|
||||
CopyBuffer(
|
||||
xTDHandler,
|
||||
X_XTD_BEARISH_POWER_LINE,
|
||||
0,
|
||||
xTDItemsPerTick,
|
||||
xTDBearishBuffer);
|
||||
|
||||
//
|
||||
// XTD Signal Buffer ...
|
||||
CopyBuffer(
|
||||
xTDHandler,
|
||||
X_XTD_SIGNAL_LINE,
|
||||
0,
|
||||
xTDItemsPerTick,
|
||||
xTDSignalBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XTD Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check Signal Vale ...
|
||||
bool XTDIsSignalVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDSignalBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
bool XTDIsSignalPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDSignalBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Vale ...
|
||||
bool XTDIsBullishVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBullishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
bool XTDIsBullishPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBullishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Vale ...
|
||||
bool XTDIsBearishVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBearishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
bool XTDIsBearishPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBearishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
|
||||
//
|
||||
// Check Bullish Crossed Over Bearish ...
|
||||
bool XTDIsBullCrossedOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossOver(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bullish Over Bearish ...
|
||||
bool XTDIsBullOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsOver(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bullish Crossed Under Bearish ...
|
||||
bool XTDIsBullCrossedUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossUnder(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bullish Under Bearish ...
|
||||
bool XTDIsBullUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsUnder(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Crossed Over Bearish ...
|
||||
bool XTDIsSignalCrossedOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossOver(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Over Bearish ...
|
||||
bool XTDIsSignalOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsOver(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Crossed Under Bearish ...
|
||||
bool XTDIsSignalCrossedUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossUnder(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Under Bearish ...
|
||||
bool XTDIsSignalUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsUnder(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XTDIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
ArraySize(xTDBullishBuffer) < size ||
|
||||
ArraySize(xTDBullishBuffer) < size ||
|
||||
ArraySize(xTDSignalBuffer) < size)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Signal Crossed Over Bear ...
|
||||
int XTDCountSignalCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Signal Crossed Under Bear ...
|
||||
int XTDCountSignalCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Bull Crossed Over Bear ...
|
||||
int XTDCountBullCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Bull Crossed Under Bear ...
|
||||
int XTDCountBullCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Signal Crossed Over Bear ...
|
||||
int XTDFindLastSignalCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Signal Crossed Onder Bear ...
|
||||
int XTDFindLastSignalCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Bull Crossed Over Bear ...
|
||||
int XTDFindLastBullCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Bull Crossed Under Bear ...
|
||||
int XTDFindLastBullCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XTD Custom Functions ...
|
||||
//
|
||||
@@ -0,0 +1,598 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTM Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XTM Indicator States ...
|
||||
enum ENUM_X_XTM_STATES
|
||||
{
|
||||
X_XTM_BULLISH = 1,
|
||||
X_XTM_BEARISH = -1,
|
||||
X_XTM_NEUTURAL = 0,
|
||||
};
|
||||
|
||||
//
|
||||
// XTM Indicator Buffer Lines ...
|
||||
enum ENUM_X_XTM_BUFFER_LINES
|
||||
{
|
||||
X_XTM_MA_LINE = 0,
|
||||
X_XTM_MC_COLOR_LINE = 1,
|
||||
X_XTM_STATE_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
// input group "XTM Indicator";
|
||||
|
||||
// input int xTMMaPeriod = 18; // Period
|
||||
// input int xTMMaShift = 0; // Shift
|
||||
// input ENUM_MA_METHOD xTMMaMethod = MODE_EMA; // Method
|
||||
// input ENUM_APPLIED_PRICE xTMMaAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
int xTMMaPeriod = 18; // Period
|
||||
int xTMMaShift = 0; // Shift
|
||||
ENUM_MA_METHOD xTMMaMethod = MODE_EMA; // Method
|
||||
ENUM_APPLIED_PRICE xTMMaAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xTMHandler = INVALID_HANDLE;
|
||||
double xTMMaBuffer[];
|
||||
double xTMStateBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool XTMValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = xTMMaPeriod >= 2;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
LogMessage("XTM Indicator Inputs Validation Failed ...");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XTMInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XTM Handler ...
|
||||
ArraySetAsSeries(xTMMaBuffer, true);
|
||||
ArraySetAsSeries(xTMStateBuffer, true);
|
||||
xTMHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xtm.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xTMMaPeriod,
|
||||
xTMMaShift,
|
||||
xTMMaMethod,
|
||||
xTMMaAppliedTo);
|
||||
if (xTMHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XTM Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XTMReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xTMHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XTMReadBuffers(
|
||||
int xTMItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// Ma Buffer ...
|
||||
CopyBuffer(
|
||||
xTMHandler,
|
||||
X_XTM_MA_LINE,
|
||||
0,
|
||||
xTMItemsPerTick,
|
||||
xTMMaBuffer);
|
||||
|
||||
//
|
||||
// State Buffer ...
|
||||
CopyBuffer(
|
||||
xTMHandler,
|
||||
X_XTM_STATE_LINE,
|
||||
0,
|
||||
xTMItemsPerTick,
|
||||
xTMStateBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XTM Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Find Peak based On this Indicator ...
|
||||
bool XTMIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTMMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Vale based On this Indicator ...
|
||||
bool XTMIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTMMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up ...
|
||||
bool XTMIsStartBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BULLISH &&
|
||||
xTMStateBuffer[bar_index + 1] != X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up After Neutural State ...
|
||||
bool XTMIsStartBullishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BULLISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Up State ...
|
||||
bool XTMIsBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State ...
|
||||
bool XTMIsEndBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] != X_XTM_BULLISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State By Neutural ...
|
||||
bool XTMIsEndBullishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down ...
|
||||
bool XTMIsStartBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BEARISH &&
|
||||
xTMStateBuffer[bar_index + 1] != X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down After Neutural State ...
|
||||
bool XTMIsStartBearishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BEARISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Down State ...
|
||||
bool XTMIsBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State ...
|
||||
bool XTMIsEndBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] != X_XTM_BEARISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State By Neutural ...
|
||||
bool XTMIsEndBearishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Neutural State ...
|
||||
bool XTMIsNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XTMIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xTMMaBuffer) < size ||
|
||||
ArraySize(xTMStateBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XTM Custom Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,353 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XAMA Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XAMA
|
||||
// Description: Trend Magic Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XAMA"
|
||||
|
||||
//
|
||||
// XAMA Indicator States ...
|
||||
enum ENUM_X_XAMA_STATES
|
||||
{
|
||||
X_XAMA_BULLISH = 1,
|
||||
X_XAMA_BEARISH = -1,
|
||||
X_XAMA_NEUTURAL = 0,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 18; // Period
|
||||
input int fastEMA = 2; // Fast EMA Period
|
||||
input int slowEMA = 30; // Slow EMA Period
|
||||
input int maShift = 0; // Shift
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
#define maColorBufferIndex 1
|
||||
#define stateBufferIndex 2
|
||||
|
||||
double maBuffer[];
|
||||
double maColorBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
#property indicator_label1 "XAMA"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
int maHandler = INVALID_HANDLE;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// Initializing MA Handler ...
|
||||
maHandler = iAMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
fastEMA,
|
||||
slowEMA,
|
||||
maShift,
|
||||
appliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Ma Handler ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(maHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(fastEMA, slowEMA);
|
||||
maxLength = MathMax(maxLength, length);
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
string maBufferLabel = "XAMA " + "(" + (string)length + ")";
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// State Buffer ...
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "(", length, ")");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Define State Value ...
|
||||
// lineColorIndex == 0 => Bullish => 1;
|
||||
// lineColorIndex == 1 => Neutural => 0;
|
||||
// lineColorIndex == 2 => Bearish => -1;
|
||||
double stateValue =
|
||||
lineColorIndex == 0 ? X_XAMA_BULLISH : lineColorIndex == 2 ? X_XAMA_BEARISH
|
||||
: X_XAMA_NEUTURAL;
|
||||
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = lineColorIndex;
|
||||
|
||||
//
|
||||
// Set State Buffer Value ...
|
||||
stateBuffer[bar_index] = stateValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,753 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Cycle Channel LH Oscillator
|
||||
// ---------------------------------------------------
|
||||
// Name: XCHLH
|
||||
// Description: detecting HH and LL based on cycles ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XCHLH Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XCHLH"
|
||||
|
||||
//
|
||||
// XCHLH Hot States ...
|
||||
enum ENUM_X_XCHLH_HOT_STATES
|
||||
{
|
||||
X_XCHLH_HOT_HH = 1,
|
||||
X_XCHLH_NEUTURAL = 0,
|
||||
X_XCHLH_HOT_LL = -1,
|
||||
};
|
||||
|
||||
//
|
||||
// Including Models Library ...
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Common ...
|
||||
input group "Hot Areas";
|
||||
input bool drawHotAreas = true; // Draw Hot Areas Symbol
|
||||
input uchar hotHHArrowCode = 234; // Hot HH Arrow Code
|
||||
input color hotHHArrowColor = clrAqua; // Hot HH Arrow Color
|
||||
input uchar hotLLArrowCode = 233; // Hot LL Arrow Code
|
||||
input color hotLLArrowColor = clrFuchsia; // Hot LL Arrow Color
|
||||
|
||||
//
|
||||
// LC Inputs ...
|
||||
input group "Long Cycle";
|
||||
input group "LC Market";
|
||||
input int lcLength = 28; // Length
|
||||
input double lcThresholdInPips = 0.3; // Threshold In Pips
|
||||
input ENUM_SERIESMODE lcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE lcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input group "LC Style";
|
||||
input int lcDrawWidth = 1; // Draw Width
|
||||
input ENUM_DRAW_TYPE lcDrawType = DRAW_LINE; // Draw Type
|
||||
input ENUM_LINE_STYLE lcDrawStyle = STYLE_DOT; // Draw Style
|
||||
input color lcHHColor = clrAqua; // Highest High Color
|
||||
input color lcLLColor = clrFuchsia; // Lowest Low Color
|
||||
input group "LC Drawings";
|
||||
input bool lcDrawHH = true; // Draw Highest High
|
||||
input bool lcDrawLL = true; // Draw Lowest Low
|
||||
|
||||
//
|
||||
// MC Inputs ...
|
||||
input group "Medium Cycle";
|
||||
input group "MC Market";
|
||||
input int mcLength = 14; // Length
|
||||
input double mcThresholdInPips = 0.3; // Threshold In Pips
|
||||
input ENUM_SERIESMODE mcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE mcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input group "MC Style";
|
||||
input int mcDrawWidth = 1; // Draw Width
|
||||
input ENUM_DRAW_TYPE mcDrawType = DRAW_LINE; // Draw Type
|
||||
input ENUM_LINE_STYLE mcDrawStyle = STYLE_DOT; // Draw Style
|
||||
input color mcHHColor = clrLime; // Highest High Color
|
||||
input color mcLLColor = clrRed; // Lowest Low Color
|
||||
input group "MC Drawings";
|
||||
input bool mcDrawHH = true; // Draw Highest High
|
||||
input bool mcDrawLL = true; // Draw Lowest Low
|
||||
|
||||
//
|
||||
// SC Inputs ...
|
||||
input group "Short Cycle";
|
||||
input group "SC Market";
|
||||
input int scLength = 7; // Length
|
||||
input double scThresholdInPips = 0.3; // Threshold In Pips
|
||||
input ENUM_SERIESMODE scHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE scLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input group "SC Style";
|
||||
input int scDrawWidth = 1; // Draw Width
|
||||
input ENUM_DRAW_TYPE scDrawType = DRAW_LINE; // Draw Type
|
||||
input ENUM_LINE_STYLE scDrawStyle = STYLE_DOT; // Draw Style
|
||||
input color scHHColor = clrLightBlue; // Highest High Color
|
||||
input color scLLColor = clrLightSalmon; // Lowest Low Color
|
||||
input group "SC Drawings";
|
||||
input bool scDrawHH = true; // Draw Highest High
|
||||
input bool scDrawLL = true; // Draw Lowest Low
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// LC ...
|
||||
#define lcHHBufferIndex 0
|
||||
#define lcLLBufferIndex 1
|
||||
|
||||
//
|
||||
double lcHHBuffer[];
|
||||
double lcLLBuffer[];
|
||||
|
||||
//
|
||||
// MC ...
|
||||
#define mcHHBufferIndex 2
|
||||
#define mcLLBufferIndex 3
|
||||
|
||||
//
|
||||
double mcHHBuffer[];
|
||||
double mcLLBuffer[];
|
||||
|
||||
//
|
||||
// SC ...
|
||||
#define scHHBufferIndex 4
|
||||
#define scLLBufferIndex 5
|
||||
|
||||
//
|
||||
double scHHBuffer[];
|
||||
double scLLBuffer[];
|
||||
|
||||
//
|
||||
// Hot State ...
|
||||
//
|
||||
#define hotStateBufferIndex 6
|
||||
|
||||
//
|
||||
double hotStateBuffer[];
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
// ReDraw Chart ...
|
||||
ChartRedraw();
|
||||
|
||||
//
|
||||
// De Init Draw Library ...
|
||||
OnDeinitDrawLibrary();
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(lcLength, mcLength);
|
||||
maxLength = MathMax(maxLength, scLength);
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
bool isLCInputsValid =
|
||||
lcLength >= 4 &&
|
||||
lcLength > mcLength &&
|
||||
lcLength > scLength;
|
||||
bool isMCInputsValid =
|
||||
mcLength >= 4 &&
|
||||
mcLength > scLength &&
|
||||
mcLength < lcLength;
|
||||
bool isSCInputsValid =
|
||||
scLength >= 4 &&
|
||||
scLength < mcLength &&
|
||||
scLength < lcLength;
|
||||
if (
|
||||
isLCInputsValid &&
|
||||
isMCInputsValid &&
|
||||
isSCInputsValid)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// LC ...
|
||||
LCDefineBuffers();
|
||||
|
||||
//
|
||||
// MC ...
|
||||
MCDefineBuffers();
|
||||
|
||||
//
|
||||
// SC ...
|
||||
SCDefineBuffers();
|
||||
|
||||
//
|
||||
// Hot State Buffer ...
|
||||
HotStateDefineBuffers();
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, "");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// LC ...
|
||||
LCCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// MC ...
|
||||
MCCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// SC ...
|
||||
SCCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// SIGNAL ...
|
||||
SignalCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// HOT State Buffer ...
|
||||
HotStateCalculateBuffers(bar_index);
|
||||
|
||||
//
|
||||
// After all Calculations we are ready to Draw what we want ...
|
||||
DrawBuffers(bar_index);
|
||||
}
|
||||
|
||||
//
|
||||
// LC Buffers Definitions ...
|
||||
void LCDefineBuffers()
|
||||
{
|
||||
//
|
||||
// LC HH Buffer ...
|
||||
string lcHHBufferLabel = ShortName + " LC HH (" + (string)lcLength + ")";
|
||||
ENUM_DRAW_TYPE lcHHDrawType = lcDrawHH ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(lcHHBuffer, true);
|
||||
SetIndexBuffer(lcHHBufferIndex, lcHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_DRAW_BEGIN, lcLength);
|
||||
PlotIndexSetString(lcHHBufferIndex, PLOT_LABEL, lcHHBufferLabel);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_LINE_COLOR, lcHHColor);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_LINE_STYLE, lcDrawStyle);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_LINE_WIDTH, lcDrawWidth);
|
||||
PlotIndexSetInteger(lcHHBufferIndex, PLOT_DRAW_TYPE, lcHHDrawType);
|
||||
|
||||
//
|
||||
// LC LL Buffer ...
|
||||
string lcLLBufferLabel = ShortName + " LC LL (" + (string)lcLength + ")";
|
||||
ENUM_DRAW_TYPE lcLLDrawType = lcDrawLL ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(lcLLBuffer, true);
|
||||
SetIndexBuffer(lcLLBufferIndex, lcLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_DRAW_BEGIN, lcLength);
|
||||
PlotIndexSetString(lcLLBufferIndex, PLOT_LABEL, lcLLBufferLabel);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_LINE_COLOR, lcLLColor);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_LINE_STYLE, lcDrawStyle);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_LINE_WIDTH, lcDrawWidth);
|
||||
PlotIndexSetInteger(lcLLBufferIndex, PLOT_DRAW_TYPE, lcLLDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// MC Buffers Definitions ...
|
||||
void MCDefineBuffers()
|
||||
{
|
||||
//
|
||||
// MC HH Buffer ...
|
||||
string mcHHBufferLabel = ShortName + " MC HH (" + (string)mcLength + ")";
|
||||
ENUM_DRAW_TYPE mcHHDrawType = mcDrawHH ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(mcHHBuffer, true);
|
||||
SetIndexBuffer(mcHHBufferIndex, mcHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_DRAW_BEGIN, mcLength);
|
||||
PlotIndexSetString(mcHHBufferIndex, PLOT_LABEL, mcHHBufferLabel);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_LINE_COLOR, mcHHColor);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_LINE_STYLE, mcDrawStyle);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_LINE_WIDTH, mcDrawWidth);
|
||||
PlotIndexSetInteger(mcHHBufferIndex, PLOT_DRAW_TYPE, mcHHDrawType);
|
||||
|
||||
//
|
||||
// MC LL Buffer ...
|
||||
string mcLLBufferLabel = ShortName + " MC LL (" + (string)mcLength + ")";
|
||||
ENUM_DRAW_TYPE mcLLDrawType = mcDrawLL ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(mcLLBuffer, true);
|
||||
SetIndexBuffer(mcLLBufferIndex, mcLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_DRAW_BEGIN, mcLength);
|
||||
PlotIndexSetString(mcLLBufferIndex, PLOT_LABEL, mcLLBufferLabel);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_LINE_COLOR, mcLLColor);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_LINE_STYLE, mcDrawStyle);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_LINE_WIDTH, mcDrawWidth);
|
||||
PlotIndexSetInteger(mcLLBufferIndex, PLOT_DRAW_TYPE, mcLLDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// SC Buffers Definitions ...
|
||||
void SCDefineBuffers()
|
||||
{
|
||||
//
|
||||
// SC HH Buffer ...
|
||||
string scHHBufferLabel = ShortName + " SC HH (" + (string)scLength + ")";
|
||||
ENUM_DRAW_TYPE scHHDrawType = scDrawHH ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(scHHBuffer, true);
|
||||
SetIndexBuffer(scHHBufferIndex, scHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_DRAW_BEGIN, scLength);
|
||||
PlotIndexSetString(scHHBufferIndex, PLOT_LABEL, scHHBufferLabel);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_LINE_COLOR, scHHColor);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_LINE_STYLE, scDrawStyle);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_LINE_WIDTH, scDrawWidth);
|
||||
PlotIndexSetInteger(scHHBufferIndex, PLOT_DRAW_TYPE, scHHDrawType);
|
||||
|
||||
//
|
||||
// SC LL Buffer ...
|
||||
string scLLBufferLabel = ShortName + " SC LL (" + (string)scLength + ")";
|
||||
ENUM_DRAW_TYPE scLLDrawType = scDrawLL ? lcDrawType : DRAW_NONE;
|
||||
ArraySetAsSeries(scLLBuffer, true);
|
||||
SetIndexBuffer(scLLBufferIndex, scLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_DRAW_BEGIN, scLength);
|
||||
PlotIndexSetString(scLLBufferIndex, PLOT_LABEL, scLLBufferLabel);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_LINE_COLOR, scLLColor);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_LINE_STYLE, scDrawStyle);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_LINE_WIDTH, scDrawWidth);
|
||||
PlotIndexSetInteger(scLLBufferIndex, PLOT_DRAW_TYPE, scLLDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Hot State Buffer ...
|
||||
void HotStateDefineBuffers()
|
||||
{
|
||||
//
|
||||
// Hot State Buffer ...
|
||||
ArraySetAsSeries(hotStateBuffer, true);
|
||||
SetIndexBuffer(hotStateBufferIndex, hotStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// LC Calculations ...
|
||||
void LCCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Detect Cycle HH and LL ...
|
||||
int length = lcLength;
|
||||
ENUM_SERIESMODE hhMode = lcHHMode;
|
||||
ENUM_SERIESMODE llMode = lcLLMode;
|
||||
double threshold = PipsToPrice(lcThresholdInPips);
|
||||
double hh = GetHighestHigh(
|
||||
length,
|
||||
bar_index,
|
||||
hhMode);
|
||||
double hhValue = hh + threshold;
|
||||
double ll = GetLowestLow(
|
||||
length,
|
||||
bar_index,
|
||||
llMode);
|
||||
double llValue = ll - threshold;
|
||||
|
||||
//
|
||||
lcHHBuffer[bar_index] = hhValue;
|
||||
lcLLBuffer[bar_index] = llValue;
|
||||
}
|
||||
|
||||
//
|
||||
// MC Calculations ...
|
||||
void MCCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Detect Cycle HH and LL ...
|
||||
int length = mcLength;
|
||||
ENUM_SERIESMODE hhMode = mcHHMode;
|
||||
ENUM_SERIESMODE llMode = mcLLMode;
|
||||
double threshold = PipsToPrice(mcThresholdInPips);
|
||||
double hh = GetHighestHigh(
|
||||
length,
|
||||
bar_index,
|
||||
hhMode);
|
||||
double hhValue = hh + threshold;
|
||||
double ll = GetLowestLow(
|
||||
length,
|
||||
bar_index,
|
||||
llMode);
|
||||
double llValue = ll - threshold;
|
||||
|
||||
//
|
||||
mcHHBuffer[bar_index] = hhValue;
|
||||
mcLLBuffer[bar_index] = llValue;
|
||||
}
|
||||
|
||||
//
|
||||
// SC Calculations ...
|
||||
void SCCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Detect Cycle HH and LL ...
|
||||
int length = scLength;
|
||||
ENUM_SERIESMODE hhMode = scHHMode;
|
||||
ENUM_SERIESMODE llMode = scLLMode;
|
||||
double threshold = PipsToPrice(scThresholdInPips);
|
||||
double hh = GetHighestHigh(
|
||||
length,
|
||||
bar_index,
|
||||
hhMode);
|
||||
double hhValue = hh + threshold;
|
||||
double ll = GetLowestLow(
|
||||
length,
|
||||
bar_index,
|
||||
llMode);
|
||||
double llValue = ll - threshold;
|
||||
|
||||
//
|
||||
scHHBuffer[bar_index] = hhValue;
|
||||
scLLBuffer[bar_index] = llValue;
|
||||
}
|
||||
|
||||
//
|
||||
// SIGNAL Calculations ...
|
||||
void SignalCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// LC Values ...
|
||||
double lcHH = lcHHBuffer[bar_index];
|
||||
double lcLL = lcLLBuffer[bar_index];
|
||||
double lcDelta = lcHH - lcLL;
|
||||
double lcAvg = lcDelta / 2;
|
||||
|
||||
//
|
||||
// MC Values ...
|
||||
double mcHH = mcHHBuffer[bar_index];
|
||||
double mcLL = mcLLBuffer[bar_index];
|
||||
double mcDelta = mcHH - mcLL;
|
||||
double mcAvg = mcDelta / 2;
|
||||
|
||||
//
|
||||
// SC Values ...
|
||||
double scHH = scHHBuffer[bar_index];
|
||||
double scLL = scLLBuffer[bar_index];
|
||||
double scDelta = scHH - scLL;
|
||||
double scAvg = scDelta / 2;
|
||||
|
||||
//
|
||||
// Min Value ...
|
||||
double minValue = MathMin(
|
||||
scLL, mcLL);
|
||||
minValue = MathMin(
|
||||
lcLL, minValue);
|
||||
|
||||
//
|
||||
// Max Value ...
|
||||
double maxValue = MathMin(
|
||||
scHH, mcHH);
|
||||
maxValue = MathMin(
|
||||
lcHH, maxValue);
|
||||
}
|
||||
|
||||
//
|
||||
// HOT State Calculate Buffers ...
|
||||
void HotStateCalculateBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// LC ...
|
||||
double lcHH = lcHHBuffer[bar_index];
|
||||
double lcLL = lcLLBuffer[bar_index];
|
||||
//
|
||||
double lcHH1 = lcHHBuffer[bar_index + 1];
|
||||
double lcLL1 = lcLLBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
// MC ...
|
||||
double mcHH = mcHHBuffer[bar_index];
|
||||
double mcLL = mcLLBuffer[bar_index];
|
||||
//
|
||||
double mcHH1 = mcHHBuffer[bar_index + 1];
|
||||
double mcLL1 = mcLLBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
// SC ...
|
||||
double scHH = scHHBuffer[bar_index];
|
||||
double scLL = scLLBuffer[bar_index];
|
||||
//
|
||||
double scHH1 = scHHBuffer[bar_index + 1];
|
||||
double scLL1 = scLLBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
bool isHotLLState = scLL == mcLL && mcLL == lcLL;
|
||||
bool isHotLLState1 = scLL1 == mcLL1 && mcLL1 == lcLL1;
|
||||
//
|
||||
bool isHotHHState = scHH == mcHH && mcHH == lcHH;
|
||||
bool isHotHHState1 = scHH1 == mcHH1 && mcHH1 == lcHH1;
|
||||
|
||||
//
|
||||
bool isHotLL = isHotLLState && !isHotLLState1;
|
||||
bool isHotHH = isHotHHState && !isHotHHState1;
|
||||
|
||||
//
|
||||
double hotStateValue = X_XCHLH_NEUTURAL;
|
||||
if (isHotHH)
|
||||
{
|
||||
hotStateValue = X_XCHLH_HOT_HH;
|
||||
}
|
||||
else if (isHotLL)
|
||||
{
|
||||
hotStateValue = X_XCHLH_HOT_LL;
|
||||
}
|
||||
|
||||
//
|
||||
hotStateBuffer[bar_index] = hotStateValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Buffers ...
|
||||
void DrawBuffers(
|
||||
int bar_index // Current Candle Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// General Requirements ...
|
||||
|
||||
//
|
||||
// Retrieve Candle Model ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
datetime time = iTime(_Symbol, _Period, bar_index);
|
||||
|
||||
//
|
||||
// Draw Arrow on Hot Areas ...
|
||||
if (drawHotAreas)
|
||||
{
|
||||
//
|
||||
double hotStateValue = hotStateBuffer[bar_index];
|
||||
bool isHotHHArea = hotStateValue == 1;
|
||||
bool isHotLLArea = hotStateValue == -1;
|
||||
if (isHotHHArea || isHotLLArea)
|
||||
{
|
||||
//
|
||||
bool isHH = isHotHHArea;
|
||||
|
||||
//
|
||||
double price = isHH ? candle.high : candle.low;
|
||||
ENUM_ARROW_ANCHOR anchor = isHH ? ANCHOR_BOTTOM : ANCHOR_TOP;
|
||||
color clr = isHH ? hotHHArrowColor : hotLLArrowColor;
|
||||
uchar arrowCode = isHH ? hotHHArrowCode : hotLLArrowCode;
|
||||
string name = "HOT " + (isHH ? "HH" : "LL") + "_" + (string)price + "_" + (string)time;
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
0,
|
||||
name,
|
||||
0,
|
||||
time,
|
||||
price,
|
||||
arrowCode,
|
||||
anchor,
|
||||
clr,
|
||||
STYLE_SOLID,
|
||||
1);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,317 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XFI Oscillator
|
||||
// ---------------------------------------------
|
||||
// Name: XFI
|
||||
// Description: Price Momentum Power Detection
|
||||
// Market Analysor ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XFI Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XFI"
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 18; // Length
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // MA Method
|
||||
input ENUM_APPLIED_VOLUME appliedTo = VOLUME_TICK; // Applied To
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// FI Buffer ...
|
||||
#define fiBufferIndex 0
|
||||
#define fiColorBufferIndex 1
|
||||
|
||||
//
|
||||
double fiBuffer[];
|
||||
double fiColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XFI"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrAqua, clrGray, clrFuchsia
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
int fiHandler = INVALID_HANDLE;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
fiHandler = iForce(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
method,
|
||||
appliedTo);
|
||||
if (fiHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Handler ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(fiHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int fiCalculatedBars = BarsCalculated(fiHandler);
|
||||
if (fiCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedFis = CopyBuffer(fiHandler, 0, 0, limit, fiBuffer);
|
||||
if (copiedFis <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = 0; i < limit && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
string fiBufferLabel = "XFI " + "(" + (string)length + ")";
|
||||
|
||||
//
|
||||
// FI Buffer ...
|
||||
ArraySetAsSeries(fiBuffer, true);
|
||||
SetIndexBuffer(fiBufferIndex, fiBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetString(fiBufferIndex, PLOT_LABEL, fiBufferLabel);
|
||||
|
||||
//
|
||||
// FI Color Buffer ...
|
||||
ArraySetAsSeries(fiColorBuffer, true);
|
||||
SetIndexBuffer(fiColorBufferIndex, fiColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, "");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
double iValue = fiBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iColorIndex =
|
||||
iValue > 0 ? 0 : iValue < 0 ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Set Buffer Color Index ...
|
||||
fiColorBuffer[bar_index] = iColorIndex;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,346 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XLH Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XLH
|
||||
// Description: Moving Average Indicator
|
||||
// Market Analysor ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XLH Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XLH"
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 14; // Length
|
||||
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// HH Buffer ...
|
||||
#define hhBufferIndex 0
|
||||
|
||||
//
|
||||
double hhBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XLH HH"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// LL Buffer ...
|
||||
#define llBufferIndex 1
|
||||
|
||||
//
|
||||
double llBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XLH LL"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrFuchsia
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
#define signalBufferIndex 2
|
||||
|
||||
//
|
||||
double signalBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XLH S"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrGold
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// HH Buffer ...
|
||||
string hhBufferLabel = ShortName + " HH " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(hhBuffer, true);
|
||||
SetIndexBuffer(hhBufferIndex, hhBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(hhBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(hhBufferIndex, PLOT_LABEL, hhBufferLabel);
|
||||
|
||||
//
|
||||
// LL Buffer ...
|
||||
string llBufferLabel = ShortName + " LL " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(llBuffer, true);
|
||||
SetIndexBuffer(llBufferIndex, llBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(llBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(llBufferIndex, PLOT_LABEL, llBufferLabel);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
string signalBufferLabel = ShortName + " S " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(signalBuffer, true);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, "");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate Threshold ...
|
||||
//
|
||||
// HH Buffer ...
|
||||
int hhIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
length,
|
||||
bar_index);
|
||||
double hhValue = GetAppliedPrice(
|
||||
hhIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
hhBuffer[bar_index] = hhValue;
|
||||
|
||||
//
|
||||
// LL Buffer ...
|
||||
int llIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
length,
|
||||
bar_index);
|
||||
double llValue = GetAppliedPrice(
|
||||
llIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
llBuffer[bar_index] = llValue;
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(bar_index);
|
||||
double lhDiff = hhValue - llValue;
|
||||
double signalValue = (lhDiff / 2);
|
||||
|
||||
//
|
||||
signalBuffer[bar_index] = (hhValue - signalValue);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,390 @@
|
||||
/////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 OrderBlock Detector Indicator
|
||||
// -----------------------------------------------------
|
||||
// Name: XOBD
|
||||
// Description: detect Order Blocks based on Swings ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XOBD Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XOBD"
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
input int length = 5; // Swing Length
|
||||
|
||||
//
|
||||
input uchar swingHighArrowCode = 108; // Swing High Arrow Code
|
||||
input color swingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
||||
|
||||
//
|
||||
input uchar swingLowArrowCode = 108; // Swing Low Arrow Code
|
||||
input color swingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Include Common and Models Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Include Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
#define swingBufferIndex 0
|
||||
double swingBuffer[];
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
OnDeinitDrawLibrary();
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length * 3);
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(swingBuffer, true);
|
||||
SetIndexBuffer(swingBufferIndex, swingBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// GetCandleSwing(bar_index);
|
||||
ENUM_X_SWING_TYPE type = X_NO_SWING;
|
||||
|
||||
//
|
||||
// Try To Detect Order Blocks ...
|
||||
bool isSwingLow = false;
|
||||
bool isSwingHigh = false;
|
||||
|
||||
//
|
||||
// Reading Candles Data ...
|
||||
XOHCL candles[];
|
||||
for (int i = bar_index; i < bar_index + ((length * 2) + 2); i++)
|
||||
{
|
||||
//
|
||||
XOHCL iCandle = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
i);
|
||||
|
||||
//
|
||||
Add(
|
||||
iCandle,
|
||||
candles);
|
||||
}
|
||||
|
||||
//
|
||||
// Swing Low ...
|
||||
isSwingLow =
|
||||
//
|
||||
candles[1].close > candles[2].close &&
|
||||
candles[2].close > candles[3].close &&
|
||||
//
|
||||
candles[3].close < candles[4].close &&
|
||||
//
|
||||
candles[5].close > candles[4].close &&
|
||||
candles[6].close > candles[5].close
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (isSwingLow)
|
||||
{
|
||||
type = X_SWING_LOW;
|
||||
}
|
||||
|
||||
//
|
||||
if (!isSwingLow)
|
||||
{
|
||||
//
|
||||
// Swing High ...
|
||||
isSwingHigh =
|
||||
//
|
||||
candles[1].close < candles[2].close &&
|
||||
candles[2].close < candles[3].close &&
|
||||
//
|
||||
candles[3].close > candles[4].close &&
|
||||
//
|
||||
candles[5].close < candles[4].close &&
|
||||
candles[6].close < candles[5].close
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (isSwingHigh)
|
||||
{
|
||||
type = X_SWING_HIGH;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
switch (type)
|
||||
{
|
||||
//
|
||||
// Swing High ...
|
||||
case X_SWING_HIGH:
|
||||
//
|
||||
swingBuffer[bar_index] = type;
|
||||
DrawSwingArrow(1, bar_index);
|
||||
break;
|
||||
|
||||
//
|
||||
// Swinmg Low ...
|
||||
case X_SWING_LOW:
|
||||
//
|
||||
swingBuffer[bar_index] = type;
|
||||
DrawSwingArrow(0, bar_index);
|
||||
break;
|
||||
|
||||
//
|
||||
// No Swing ...
|
||||
default:
|
||||
case X_NO_SWING:
|
||||
//
|
||||
swingBuffer[bar_index] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw a Swing Arrow Shape ...
|
||||
void DrawSwingArrow(
|
||||
int type, // Swing Type: 0 - Low / 1 - High ...
|
||||
int bar_index)
|
||||
{
|
||||
//
|
||||
bool isSwingHigh = type == 1;
|
||||
XOHCL candle = GetCandle(bar_index + 3);
|
||||
double arrowDistanceInPoint = 0;
|
||||
|
||||
//
|
||||
// Define Required Object Properties fro Draw an Arrow ...
|
||||
datetime time = iTime(_Symbol, _Period, bar_index + 3);
|
||||
double purePrice = isSwingHigh ? candle.high : candle.low;
|
||||
color clr = isSwingHigh ? swingHighArrowColor : swingLowArrowColor;
|
||||
ENUM_ARROW_ANCHOR anchor = isSwingHigh ? ANCHOR_BOTTOM : ANCHOR_TOP;
|
||||
uchar arrowCode = uchar(isSwingHigh ? swingHighArrowCode : swingLowArrowCode);
|
||||
double price = isSwingHigh ? purePrice + arrowDistanceInPoint : purePrice - arrowDistanceInPoint;
|
||||
string name = "Swing " + (isSwingHigh ? "High" : "Low") + "_" + (string)time + "_" + (string)purePrice;
|
||||
|
||||
//
|
||||
// Draw desired Arrow ...
|
||||
DrawArrow(
|
||||
0,
|
||||
name,
|
||||
0,
|
||||
time,
|
||||
price,
|
||||
arrowCode,
|
||||
anchor,
|
||||
clr);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,397 @@
|
||||
/////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 OrderBlock Detector Oscillator
|
||||
// ------------------------------------------------------
|
||||
// Name: XRSI
|
||||
// Description: detect market conditions based on RSI ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XRSI Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "XRSI"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 14; // Market Length
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Short Entry";
|
||||
input double shortEntryValue = 70; // Short Entry Level
|
||||
input color shortEntryColor = clrRed; // Short Entry Level Color
|
||||
input ENUM_LINE_STYLE shortEntryLineStyle = STYLE_DOT; // Short Entry Style
|
||||
|
||||
//
|
||||
input group "Short Exit";
|
||||
input double shortExitValue = 40; // Short Exit Level
|
||||
input color shortExitColor = clrRed; // Short Exit Level Color
|
||||
input ENUM_LINE_STYLE shortExitLineStyle = STYLE_DOT; // Short Exit Style
|
||||
|
||||
//
|
||||
input group "Long Entry";
|
||||
input double longEntryValue = 30; // Long Entry Level
|
||||
input color longEntryColor = clrRed; // Long Entry Level Color
|
||||
input ENUM_LINE_STYLE longEntryLineStyle = STYLE_DOT; // Long Entry Style
|
||||
|
||||
//
|
||||
input group "Long Exit";
|
||||
input double longExitValue = 60; // Long Exit Level
|
||||
input color longExitColor = clrRed; // Long Exit Level Color
|
||||
input ENUM_LINE_STYLE longExitLineStyle = STYLE_DOT; // Long Exit Style
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Include Common and Models Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
#define rsiBufferIndex 0
|
||||
#define rsiColorBufferIndex 1
|
||||
|
||||
//
|
||||
double rsiBuffer[];
|
||||
double rsiColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XRSI"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrAqua, clrGray, clrFuchsia
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
rsiHandler = iRSI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
appliedTo);
|
||||
if (rsiHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
IndicatorRelease(rsiHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
||||
if (rsiCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
int rsiCopiedItems = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
||||
if (rsiCopiedItems <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// RSI ...
|
||||
string rsiBufferLabel = ShortName + " (" + (string)length + ")";
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(rsiBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(rsiBufferIndex, PLOT_LABEL, rsiBufferLabel);
|
||||
|
||||
//
|
||||
// RSI Color Buffer ...
|
||||
ArraySetAsSeries(rsiColorBuffer, true);
|
||||
SetIndexBuffer(rsiColorBufferIndex, rsiColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Set Indicator Levels here ...
|
||||
// OB, ExitLong, ExitShort, OS ...
|
||||
IndicatorSetInteger(INDICATOR_LEVELS, 4);
|
||||
|
||||
//
|
||||
// SHORTENTRY ...
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, shortEntryValue);
|
||||
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 0, shortEntryColor);
|
||||
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 0, shortEntryLineStyle);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT, 0, "Short Entry");
|
||||
|
||||
//
|
||||
// LONGEXIT ...
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, longExitValue);
|
||||
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 1, longExitColor);
|
||||
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 1, shortExitLineStyle);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT, 1, "Long Exit");
|
||||
|
||||
//
|
||||
// SHORTEXIT ...
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 2, shortExitValue);
|
||||
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 2, shortExitColor);
|
||||
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 2, longEntryLineStyle);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT, 2, "Short Exit");
|
||||
|
||||
//
|
||||
// LONGENTRY ...
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE, 3, longEntryValue);
|
||||
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 3, longEntryColor);
|
||||
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 3, longExitLineStyle);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT, 3, "Long Entry");
|
||||
|
||||
//
|
||||
// Set Maximum and Minimum for subwindow
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
IndicatorSetDouble(INDICATOR_MINIMUM, 0);
|
||||
IndicatorSetDouble(INDICATOR_MAXIMUM, 100);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
double iValue = rsiBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iColorIndex = 0;
|
||||
|
||||
//
|
||||
if (
|
||||
iValue >= shortEntryValue ||
|
||||
iValue <= longEntryValue ||
|
||||
(iValue < longExitValue &&
|
||||
iValue > shortExitValue))
|
||||
{
|
||||
iColorIndex = 0;
|
||||
}
|
||||
else if (
|
||||
iValue <= shortEntryValue &&
|
||||
iValue >= longExitValue)
|
||||
{
|
||||
iColorIndex = 2;
|
||||
}
|
||||
else if (
|
||||
iValue < shortExitValue &&
|
||||
iValue > longEntryValue)
|
||||
{
|
||||
iColorIndex = 1;
|
||||
}
|
||||
|
||||
//
|
||||
rsiColorBuffer[bar_index] = iColorIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,465 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Trend Detector Oscillator
|
||||
// --------------------------------------------------
|
||||
// Name: XTD
|
||||
// Description: trend detecting in both sides ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTD Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XTD"
|
||||
|
||||
//
|
||||
// XTD Oscillator States ...
|
||||
enum ENUM_X_XTD_STATES
|
||||
{
|
||||
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
|
||||
X_XTD_BULLISH_OVER_BEARISH = 1,
|
||||
X_XTD_NEUTURAL = 0,
|
||||
X_XTD_BULLISH_UNDER_BEARISH = -1,
|
||||
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Include Models Library ...
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 14; // Market Length
|
||||
input bool drawCrosses = true; // Draw Cross Arrows
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
input uchar bullishArrowCode = 228; // Cross Over Arrow Code
|
||||
input color bullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
input uchar bearishArrowCode = 230; // Cross Under Arrow Code
|
||||
input color bearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
#define bullishBufferIndex 0
|
||||
#define bearishBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
|
||||
//
|
||||
double bullishBuffer[];
|
||||
double bearishBuffer[];
|
||||
double signalBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XBullPower"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#property indicator_label2 "XBearPower"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#property indicator_label3 "XSignal"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrGold
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
int xtdBullishCandleCount = 0;
|
||||
int xtdBearishCandleCount = 0;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
// De Init Draw Library ...
|
||||
OnDeinitDrawLibrary();
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i, close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 5)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Bullish Buffer ...
|
||||
string bullishBufferLabel = ShortName + "BullPow " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(bullishBuffer, true);
|
||||
SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(bullishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(bullishBufferIndex, PLOT_LABEL, bullishBufferLabel);
|
||||
|
||||
//
|
||||
// Bearish Buffer ...
|
||||
string bearishBufferLabel = ShortName + "BearPow " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(bearishBuffer, true);
|
||||
SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(bearishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(bearishBufferIndex, PLOT_LABEL, bearishBufferLabel);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
string signalBufferLabel = ShortName + "Signal " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(signalBuffer, true);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index,
|
||||
const double &close[])
|
||||
{
|
||||
//
|
||||
// Reset Global Counters ...
|
||||
xtdBullishCandleCount = 0;
|
||||
xtdBearishCandleCount = 0;
|
||||
|
||||
//
|
||||
// Loop through Closes ...
|
||||
for (int i = bar_index; i <= bar_index + length; i++)
|
||||
{
|
||||
for (int j = i + 1; j <= bar_index + length; j++)
|
||||
{
|
||||
//
|
||||
if (close[i] > close[j])
|
||||
{
|
||||
xtdBullishCandleCount++;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[i] < close[j])
|
||||
{
|
||||
xtdBearishCandleCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Power Buffer ...
|
||||
bullishBuffer[bar_index] = MathAbs(xtdBullishCandleCount);
|
||||
|
||||
//
|
||||
// Bearish Power Buffer ...
|
||||
bearishBuffer[bar_index] = MathAbs(xtdBearishCandleCount);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
signalBuffer[bar_index] = bullishBuffer[bar_index] - bearishBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Check and Draw Crosses if it's Specified ...
|
||||
if (drawCrosses)
|
||||
{
|
||||
DrawCrosses(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
double GetState(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Cross Points ...
|
||||
// bullishCrossedOverBearish = 2;
|
||||
// bullishOverBearish = 1;
|
||||
// bullishCrossedUnderBearish = -2;
|
||||
// bullishUnderBearish = -1;
|
||||
// OtherWise = 0;
|
||||
bool isBullishCrossedOverBearish = IsCrossOver(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishCrossedUnderBearish = IsCrossUnder(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishOverBearish = IsOver(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishUnderBearish = IsUnder(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double result = X_XTD_NEUTURAL;
|
||||
if (isBullishCrossedOverBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_CROSSED_OVER_BEARISH;
|
||||
}
|
||||
else if (isBullishCrossedUnderBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_CROSSED_UNDER_BEARISH;
|
||||
}
|
||||
else if (isBullishOverBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_OVER_BEARISH;
|
||||
}
|
||||
else if (isBullishUnderBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_UNDER_BEARISH;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = X_XTD_NEUTURAL;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Crosses ...
|
||||
void DrawCrosses(
|
||||
int bar_index // the bars which required to draw cross arrow on it ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double stateValue = GetState(bar_index);
|
||||
|
||||
//
|
||||
bool isOver = stateValue == 2;
|
||||
double low = iLow(_Symbol, _Period, bar_index);
|
||||
double high = iHigh(_Symbol, _Period, bar_index);
|
||||
|
||||
//
|
||||
double price = isOver ? low : high;
|
||||
datetime time = iTime(_Symbol, _Period, bar_index);
|
||||
ENUM_ARROW_ANCHOR anchor = isOver ? ANCHOR_TOP : ANCHOR_BOTTOM;
|
||||
uchar arrowCode = isOver ? bullishArrowCode : bearishArrowCode;
|
||||
color arrowColor = isOver ? bullishArrowColor : bearishArrowColor;
|
||||
string crossName = "Trend " + (isOver ? "Up" : "Down") + "_" + (string)time + "_" + (string)price;
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
0,
|
||||
crossName,
|
||||
0,
|
||||
time,
|
||||
price,
|
||||
arrowCode,
|
||||
anchor,
|
||||
arrowColor);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,349 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XTM
|
||||
// Description: Trend Magic Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTM Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XTM"
|
||||
|
||||
//
|
||||
// XTM Indicator States ...
|
||||
enum ENUM_X_XTM_STATES
|
||||
{
|
||||
X_XTM_BULLISH = 1,
|
||||
X_XTM_BEARISH = -1,
|
||||
X_XTM_NEUTURAL = 0,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int maPeriod = 14; // Period
|
||||
input int maShift = 0; // Shift
|
||||
input ENUM_MA_METHOD maMethod = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Applied To
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
#define maColorBufferIndex 1
|
||||
#define stateBufferIndex 2
|
||||
|
||||
double maBuffer[];
|
||||
double maColorBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
#property indicator_label1 "XTM"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
int maHandler = INVALID_HANDLE;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// Initializing MA Handler ...
|
||||
maHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
maPeriod,
|
||||
maShift,
|
||||
maMethod,
|
||||
maAppliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Ma Handler ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, maPeriod);
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (maPeriod >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
string maBufferLabel = "XTM " + "(" + (string)maPeriod + ")";
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// State Buffer ...
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "(", maPeriod, ")");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Define State Value ...
|
||||
// lineColorIndex == 0 => Bullish => 1;
|
||||
// lineColorIndex == 1 => Neutural => 0;
|
||||
// lineColorIndex == 2 => Bearish => -1;
|
||||
double stateValue =
|
||||
lineColorIndex == 0 ? X_XTM_BULLISH : lineColorIndex == 2 ? X_XTM_BEARISH
|
||||
: X_XTM_NEUTURAL;
|
||||
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = lineColorIndex;
|
||||
|
||||
//
|
||||
// Set State Buffer Value ...
|
||||
stateBuffer[bar_index] = stateValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,558 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTS Oscillator
|
||||
// ---------------------------------------------
|
||||
// Name: XTS
|
||||
// Description: Time Sections Oscillator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTS Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "XTS"
|
||||
|
||||
enum ENUM_X_PERIOD_METHOD
|
||||
{
|
||||
//
|
||||
X_PERIOD_NOTHING,
|
||||
//
|
||||
X_PERIOD_AUTO,
|
||||
//
|
||||
X_PERIOD_MANUALLY
|
||||
};
|
||||
|
||||
//
|
||||
// XTS Oscillator States ...
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Current Period";
|
||||
input ENUM_APPLIED_PRICE currentAppliedTo = PRICE_CLOSE; // Current Applied To
|
||||
//
|
||||
input group "Nearest Period";
|
||||
input ENUM_X_PERIOD_METHOD nearestMethod = X_PERIOD_AUTO; // How to Find Nearest Period
|
||||
input ENUM_TIMEFRAMES nearestPeriod = NULL; // Nearest Time Frame
|
||||
input ENUM_APPLIED_PRICE nearestAppliedTo = PRICE_CLOSE; // Nearest Applied To
|
||||
//
|
||||
input group "Mediest Period";
|
||||
input ENUM_X_PERIOD_METHOD mediestMethod = X_PERIOD_AUTO; // How to Find Mediest Period
|
||||
input ENUM_TIMEFRAMES mediestPeriod = NULL; // Mediest Time Frame
|
||||
input ENUM_APPLIED_PRICE mediestAppliedTo = PRICE_CLOSE; // Mediest Applied To
|
||||
//
|
||||
input group "Farest Period";
|
||||
input ENUM_X_PERIOD_METHOD farestMethod = X_PERIOD_AUTO; // How to Find Farest Period
|
||||
input ENUM_TIMEFRAMES farestPeriod = NULL; // Farest Time Frame
|
||||
input ENUM_APPLIED_PRICE farestAppliedTo = PRICE_CLOSE; // Farest Applied To
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// Current ...
|
||||
#define currentBufferIndex 0
|
||||
|
||||
double currentBuffer[];
|
||||
|
||||
#property indicator_label1 "XTS C"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
#define nearestBufferIndex 1
|
||||
|
||||
double nearestBuffer[];
|
||||
|
||||
#property indicator_label2 "XTS N"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrAqua
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
#define mediestBufferIndex 2
|
||||
|
||||
double mediestBuffer[];
|
||||
|
||||
#property indicator_label3 "XTS M"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrLime
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
#define farestBufferIndex 3
|
||||
|
||||
double farestBuffer[];
|
||||
|
||||
#property indicator_label4 "XTS F"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrLightBlue
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mNearestPeriod = NULL;
|
||||
ENUM_TIMEFRAMES mMediestPeriod = NULL;
|
||||
ENUM_TIMEFRAMES mFarestPeriod = NULL;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Oscillator ShortName ...
|
||||
SetOscillatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
OnDeinitDrawLibrary();
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = 30;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = 0; i < limit && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
int maxLength = 30;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
ArraySetAsSeries(currentBuffer, true);
|
||||
SetIndexBuffer(currentBufferIndex, currentBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(currentBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
ArraySetAsSeries(nearestBuffer, true);
|
||||
SetIndexBuffer(nearestBufferIndex, nearestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(nearestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
ArraySetAsSeries(mediestBuffer, true);
|
||||
SetIndexBuffer(mediestBufferIndex, mediestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mediestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
ArraySetAsSeries(farestBuffer, true);
|
||||
SetIndexBuffer(farestBufferIndex, farestBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(farestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Oscillator Short Name and also we can define Buffers Labels ...
|
||||
void SetOscillatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Current ...
|
||||
CalculateCurrent(bar_index);
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
CalculateNearest(bar_index);
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
CalculateMediest(bar_index);
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
CalculateFarest(bar_index);
|
||||
|
||||
//
|
||||
// Commenting ...
|
||||
string comment = GenerateDescriptionComment();
|
||||
Comment(comment);
|
||||
}
|
||||
|
||||
//
|
||||
// Current ...
|
||||
void CalculateCurrent(int bar_index)
|
||||
{
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
currentAppliedTo);
|
||||
|
||||
//
|
||||
currentBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Nearest ...
|
||||
void CalculateNearest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mNearestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (nearestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mNearestPeriod = GetNearestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mNearestPeriod = nearestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mNearestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
nearestAppliedTo);
|
||||
|
||||
//
|
||||
nearestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Mediest ...
|
||||
void CalculateMediest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mMediestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (mediestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mMediestPeriod = GetMediestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mMediestPeriod = mediestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mMediestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
mediestAppliedTo);
|
||||
|
||||
//
|
||||
mediestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Farest ...
|
||||
void CalculateFarest(int bar_index)
|
||||
{
|
||||
//
|
||||
if (mFarestPeriod == NULL)
|
||||
{
|
||||
//
|
||||
switch (farestMethod)
|
||||
{
|
||||
//
|
||||
case X_PERIOD_AUTO:
|
||||
mFarestPeriod = GetFarestTimeFrame(_Period);
|
||||
break;
|
||||
|
||||
//
|
||||
case X_PERIOD_NOTHING:
|
||||
case X_PERIOD_MANUALLY:
|
||||
mFarestPeriod = farestPeriod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
datetime startTime = GetPeriodStartTime(
|
||||
_Symbol,
|
||||
mFarestPeriod,
|
||||
barTime);
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime);
|
||||
|
||||
//
|
||||
XOHCL c = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startBarIndex);
|
||||
|
||||
//
|
||||
double value = GetAppliedPrice(
|
||||
c,
|
||||
farestAppliedTo);
|
||||
|
||||
//
|
||||
farestBuffer[bar_index] = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Comment ...
|
||||
string GenerateDescriptionComment()
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result += "Nearest : " + EnumToString(mNearestPeriod) + "\n";
|
||||
result += "Mediest : " + EnumToString(mMediestPeriod) + "\n";
|
||||
result += "Farest : " + EnumToString(mFarestPeriod) + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,200 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Alert Library
|
||||
// --------------------------------------
|
||||
// Name: XAlert
|
||||
// Description: provides Alerts abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Alerts";
|
||||
input bool enableAlerts = true; // Enable Alerts
|
||||
input bool logAlerts = true; // Log Alerts
|
||||
input bool terminalAlerts = false; // Terminal Alerts
|
||||
input bool mailAlerts = false; // Mail Alerts
|
||||
input bool pushAlerts = false; // Push Alerts
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
#include "x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string alertPrefix = "X-Alert";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitAlertLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitAlertLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Attach Alert Prefix to Message ...
|
||||
string PrepareAlertMessage(string message)
|
||||
{
|
||||
//
|
||||
StringReplace(message, "\n", " | ");
|
||||
|
||||
//
|
||||
StringConcatenate(message, alertPrefix, " > ", message);
|
||||
|
||||
//
|
||||
return message;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Alert ...
|
||||
void LogAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !logAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
LogMessage(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal Alert ...
|
||||
void TerminalAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !terminalAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
// Send Terminal Alert ...
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail Alert ...
|
||||
void MailAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !mailAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Mail Alert ...
|
||||
SendMail(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Send Push Notification ...
|
||||
void PushAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !pushAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
//
|
||||
// Send Push Notification Alert ...
|
||||
SendNotification(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Sending ...
|
||||
void SendAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Log ...
|
||||
if (logAlerts)
|
||||
{
|
||||
LogAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal ...
|
||||
if (terminalAlerts)
|
||||
{
|
||||
TerminalAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail ...
|
||||
if (mailAlerts)
|
||||
{
|
||||
MailAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Push ...
|
||||
if (pushAlerts)
|
||||
{
|
||||
PushAlert(message);
|
||||
}
|
||||
}
|
||||
void SendAlert(
|
||||
XSignal &signal, // the Signal Object which requred to Alert
|
||||
bool asExecuted = true // determines Alert Signal as Executed Signal or not
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Message ...
|
||||
string message = asExecuted ? ExecutedSignalToString(signal) : SignalToString(signal);
|
||||
|
||||
//
|
||||
// Do Alerting ...
|
||||
SendAlert(message);
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,177 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Http Library
|
||||
// ------------------------------------------
|
||||
// Name: XHttp
|
||||
// Description: provide http communication
|
||||
// abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Model Definition ...
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
//
|
||||
// END Model Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitHttpLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitHttpLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
) {
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
) {
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
@@ -0,0 +1,261 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Logger Library
|
||||
// ---------------------------------------
|
||||
// Name: XLogger
|
||||
// Description: provides Logging abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Logging";
|
||||
input bool enableLogging = true; // Enable Logging
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Including Models ...
|
||||
#include "x-saherelm.models.lib.mq5"
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string logTag = "X-Logger"; // LogTag
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Logging a Message ...
|
||||
void LogMessage(string message)
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, " > ", message);
|
||||
}
|
||||
void LogMessage(string tag, string message)
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(tag, " > ", message);
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Array ...
|
||||
void LogArray(int &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
void LogArray(double &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
void LogArray(string &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
|
||||
//
|
||||
// Convert a Signal to String Message ...
|
||||
string SignalToString(const XSignal &signal)
|
||||
{
|
||||
//
|
||||
string result = "\n";
|
||||
|
||||
//
|
||||
result += "Signal: " + "\n";
|
||||
result += "id: " + (string)signal.id + "\n";
|
||||
result += "symbol: " + signal.symbol + "\n";
|
||||
result += "type: " + EnumToString(signal.type) + "\n";
|
||||
result += "magicNumber: " + (string)signal.magicNumber + "\n";
|
||||
result += "ticket: " + (string)signal.ticket + "\n";
|
||||
result += "entry: " + (string)signal.entry + "\n";
|
||||
result += "tp: " + (string)signal.tp + "\n";
|
||||
result += "sl: " + (string)signal.sl + "\n";
|
||||
result += "riskFreeStep: " + (string)signal.riskFreeStep + "\n";
|
||||
result += "riskFreeRate: " + (string)signal.riskFreeRate + "\n";
|
||||
result += "profit: " + (string)signal.profit + "\n";
|
||||
result += "time: " + (string)signal.time + "\n";
|
||||
result += "volume: " + (string)signal.volume + "\n";
|
||||
result += "comment: " + signal.comment + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Convert an Executed Signal to String Message ...
|
||||
string ExecutedSignalToString(const XSignal &signal)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result += (signal.type == X_SIGNAL_LONG ? "Buy" : "Sell") + " Signal Executed provided on (" + signal.symbol + " _ " + EnumToString(_Period) + ") by this comment: " + signal.comment;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging Signal ...
|
||||
void LogSignal(const XSignal &signal)
|
||||
{
|
||||
//
|
||||
string message = SignalToString(signal);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Log Signal Execution ...
|
||||
void LogExecutedSignal(const XSignal &signal)
|
||||
{
|
||||
//
|
||||
string message = ExecutedSignalToString(signal);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Convert a Deal to String ...
|
||||
string DealToString(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
string result = "\n";
|
||||
|
||||
//
|
||||
result += "Deal:" + "\n";
|
||||
result += " " + "\n";
|
||||
result += "time: " + (string)deal.time + "\n";
|
||||
result += "ticket: " + (string)deal.ticket + "\n";
|
||||
result += "order: " + (string)deal.order + "\n";
|
||||
result += "positionId: " + (string)deal.positionId + "\n";
|
||||
result += "type: " + EnumToString(deal.type) + "\n";
|
||||
result += "entry: " + EnumToString(deal.entry) + "\n";
|
||||
result += "reason: " + EnumToString(deal.reason) + "\n";
|
||||
result += "symbol: " + deal.symbol + "\n";
|
||||
result += "price: " + (string)deal.price + "\n";
|
||||
result += "profit: " + (string)deal.profit + "\n";
|
||||
result += "swap: " + (string)deal.swap + "\n";
|
||||
result += "commission: " + (string)deal.commission + "\n";
|
||||
result += "volume: " + (string)deal.volume + "\n";
|
||||
result += "comment: " + deal.comment + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Log Specific Deal ...
|
||||
void LogDeal(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
string message = DealToString(deal);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Convert an Order to String ...
|
||||
string OrderToString(const XOrder &order)
|
||||
{
|
||||
//
|
||||
string result = "\n";
|
||||
|
||||
//
|
||||
result += "Order: " + "\n";
|
||||
result += "magic: " + (string)order.magic + "\n";
|
||||
result += "positionId: " + (string)order.positionId + "\n";
|
||||
result += "symbol: " + (string)order.symbol + "\n";
|
||||
result += "ticket: " + (string)order.ticket + "\n";
|
||||
result += "timeSetup: " + (string)order.timeSetup + "\n";
|
||||
result += "timeDone: " + (string)order.timeDone + "\n";
|
||||
result += "timeExpiration: " + (string)order.timeExpiration + "\n";
|
||||
result += "priceOpen: " + (string)order.priceOpen + "\n";
|
||||
result += "priceCurrent: " + (string)order.priceCurrent + "\n";
|
||||
result += "priceStopLimit: " + (string)order.priceStopLimit + "\n";
|
||||
result += "stopLoss: " + (string)order.stopLoss + "\n";
|
||||
result += "takeProfit: " + (string)order.takeProfit + "\n";
|
||||
result += "volumeInitial: " + (string)order.volumeInitial + "\n";
|
||||
result += "volumeCurrent: " + (string)order.volumeCurrent + "\n";
|
||||
result += "comment: " + order.comment + "\n";
|
||||
result += "type: " + EnumToString(order.type) + "\n";
|
||||
result += "state: " + EnumToString(order.state) + "\n";
|
||||
result += "typeFilling: " + EnumToString(order.typeFilling) + "\n";
|
||||
result += "typeTime: " + EnumToString(order.typeTime) + "\n";
|
||||
result += "reason: " + EnumToString(order.reason) + "\n";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Log Specific Order ...
|
||||
void LogOrder(const XOrder &order)
|
||||
{
|
||||
//
|
||||
string message = OrderToString(order);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
@@ -0,0 +1,438 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Models Library
|
||||
// ---------------------------------------
|
||||
// Name: XModels
|
||||
// Description: provides all required models ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// How To Calculate Static Volume ...
|
||||
enum ENUM_STATIC_VOLUME_METHODS
|
||||
{
|
||||
//
|
||||
// Based On Deposit ...
|
||||
X_STATIC_VOLUME_BASED_ON_DEPOSIT,
|
||||
//
|
||||
// Based On Balance ...
|
||||
X_STATIC_VOLUME_BASED_ON_BALANCE,
|
||||
};
|
||||
|
||||
//
|
||||
// START Model Definitions ...
|
||||
//
|
||||
//
|
||||
// OHCL Candel Model ...
|
||||
enum ENUM_X_PRICE
|
||||
{
|
||||
X_PRICE_HIGH,
|
||||
X_PRICE_OPEN,
|
||||
X_PRICE_CLOSE,
|
||||
X_PRICE_LOW
|
||||
};
|
||||
|
||||
//
|
||||
// Describe an Specific Candle ...
|
||||
struct XOHCL
|
||||
{
|
||||
double high;
|
||||
double open;
|
||||
double close;
|
||||
double low;
|
||||
};
|
||||
|
||||
//
|
||||
// Swing Types Enum ...
|
||||
enum ENUM_X_SWING_TYPE
|
||||
{
|
||||
X_NO_SWING = 0,
|
||||
X_SWING_HIGH = 1,
|
||||
X_SWING_LOW = -1,
|
||||
};
|
||||
|
||||
//
|
||||
// XTrader Execution Signal Result ...
|
||||
enum ENUM_EXECUTION_SIGNAL_RESULT
|
||||
{
|
||||
//
|
||||
X_TRADER_UNKNOWN_ERROR,
|
||||
X_TRADER_SUCCEED_EXECUTION,
|
||||
X_TRADER_INVALID_SIGNAL_ERROR,
|
||||
X_TRADER_NOT_ENOUGH_EQUITY_ERROR,
|
||||
X_TRADER_MAX_TRADES_REACHED_ERROR,
|
||||
X_TRADER_NOT_ENOUGH_BALANCE_ERROR,
|
||||
X_TRADER_NOT_ENOUGH_MARIGIN_ERROR
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Signal Types ...
|
||||
enum ENUM_X_SIGNAL_TYPE
|
||||
{
|
||||
X_SIGNAL_LONG,
|
||||
X_SIGNAL_SHORT,
|
||||
X_SIGNAL_UNKNOWN,
|
||||
};
|
||||
|
||||
//
|
||||
// Signal Structure ...
|
||||
struct XSignal
|
||||
{
|
||||
//
|
||||
// Identifier ...
|
||||
ulong id;
|
||||
|
||||
//
|
||||
// Which Symbol used for Signal ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Which Type of operations ...
|
||||
ENUM_X_SIGNAL_TYPE type;
|
||||
|
||||
//
|
||||
// Magic Number ...
|
||||
ulong magicNumber;
|
||||
|
||||
//
|
||||
// Ticket ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// Entry/Open Price ...
|
||||
double entry;
|
||||
|
||||
//
|
||||
// TP ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// SL ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// Make Risk Free Trade on this Value if provided ...
|
||||
double riskFreeStep;
|
||||
|
||||
//
|
||||
// a Multiplier for determines how much trade volume exit on risk free time ...
|
||||
double riskFreeRate;
|
||||
|
||||
//
|
||||
// Trade Profit ...
|
||||
double profit;
|
||||
|
||||
//
|
||||
// Time of Operation ...
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
double volume;
|
||||
|
||||
//
|
||||
// Comment ...
|
||||
string comment;
|
||||
};
|
||||
|
||||
//
|
||||
// Signal Additional Info ...
|
||||
struct XProvidedSignal
|
||||
{
|
||||
//
|
||||
// Suggested TP ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// Suggested SL ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// Signallers ...
|
||||
string signallers[];
|
||||
};
|
||||
|
||||
//
|
||||
// Model Specific Deal ...
|
||||
struct XDeal
|
||||
{
|
||||
//
|
||||
// the ID of the Expert Advisor, that executed the deal ...
|
||||
ulong magic;
|
||||
|
||||
//
|
||||
// the ID of position, in which the deal was involved ...
|
||||
ulong positionId;
|
||||
|
||||
//
|
||||
// Ticket ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// the name of the deal symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// order by which the deal is executed ...
|
||||
ulong order;
|
||||
|
||||
//
|
||||
// the time of deal execution ...
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Deal price ...
|
||||
double price;
|
||||
|
||||
//
|
||||
// the financial result of the deal (in deposit currency) ...
|
||||
double profit;
|
||||
|
||||
//
|
||||
// the amount of swap when position is closed ...
|
||||
double swap;
|
||||
|
||||
//
|
||||
// the amount of commission of the deal ...
|
||||
double commission;
|
||||
|
||||
//
|
||||
// the volume of deal ...
|
||||
double volume;
|
||||
|
||||
//
|
||||
// the deal comment ...
|
||||
string comment;
|
||||
|
||||
//
|
||||
// the deal type ...
|
||||
// ------------------------------------------------------------------
|
||||
// DEAL_TYPE_BUY => Buy ...
|
||||
// DEAL_TYPE_SELL => Sell ...
|
||||
// DEAL_TYPE_BUY_CANCELED => Canceled buy deal ...
|
||||
// There can be a situation when a previously executed buy deal is canceled. In this case,
|
||||
// the type of the previously executed deal (DEAL_TYPE_BUY) is changed to DEAL_TYPE_BUY_CANCELED,
|
||||
// and its profit/loss is zeroized. Previously obtained profit/loss is charged/withdrawn using a separated balance operation ...
|
||||
//
|
||||
// DEAL_TYPE_SELL_CANCELED => Canceled sell deal ...
|
||||
// There can be a situation when a previously executed sell deal is canceled. In this case,
|
||||
// the type of the previously executed deal (DEAL_TYPE_SELL) is changed to DEAL_TYPE_SELL_CANCELED,
|
||||
// and its profit/loss is zeroized. Previously obtained profit/loss is charged/withdrawn using a separated balance operation
|
||||
//
|
||||
// DEAL_TYPE_BALANCE => Balance ...
|
||||
// DEAL_TYPE_CREDIT => Credit ...
|
||||
// DEAL_TYPE_CHARGE => Additional charge ...
|
||||
// DEAL_TYPE_CORRECTION => Correction ...
|
||||
// DEAL_TAX => Tax charges ...
|
||||
// DEAL_TYPE_BONUS => Bonus ...
|
||||
// DEAL_TYPE_INTEREST => Interest rate ...
|
||||
// DEAL_DIVIDEND => Dividend operations...
|
||||
// DEAL_DIVIDEND_FRANKED => Franked (non-taxable) dividend operations ...
|
||||
// DEAL_TYPE_COMMISSION => Additional commission ...
|
||||
// DEAL_TYPE_COMMISSION_DAILY => Daily commission ...
|
||||
// DEAL_TYPE_COMMISSION_MONTHLY => Monthly commission ...
|
||||
// DEAL_TYPE_COMMISSION_AGENT_DAILY => Daily agent commission ...
|
||||
// DEAL_TYPE_COMMISSION_AGENT_MONTHLY => Monthly agent commission
|
||||
ENUM_DEAL_TYPE type;
|
||||
|
||||
//
|
||||
// the deal direction ...
|
||||
// ----------------------------------
|
||||
// DEAL_ENTRY_IN => Entry in ...
|
||||
// DEAL_ENTRY_OUT => Entry out ...
|
||||
// DEAL_ENTRY_INOUT => Reverse ...
|
||||
// DEAL_ENTRY_OUT_BY => Close a position by an opposite one ...
|
||||
ENUM_DEAL_ENTRY entry;
|
||||
|
||||
//
|
||||
// deal reson ...
|
||||
// ---------------------
|
||||
// DEAL_REASON_SL => The deal was executed as a result of Stop Loss activation ...
|
||||
// DEAL_REASON_TP => The deal was executed as a result of Take Profit activation ...
|
||||
// DEAL_REASON_SO => The deal was executed as a result of the Stop Out event ...
|
||||
// DEAL_REASON_WEB => The deal was executed as a result of activation of an order placed from the web platform ...
|
||||
// DEAL_REASON_SPLIT => The deal was executed after the split (price reduction) of an instrument, which had an open position during split announcement ...
|
||||
// DEAL_REASON_CLIENT => The deal was executed as a result of activation of an order placed from a desktop terminal ...
|
||||
// DEAL_REASON_MOBILE => The deal was executed as a result of activation of an order placed from a mobile application ...
|
||||
// DEAL_REASON_EXPERT => The deal was executed as a result of activation of an order placed from an MQL5 program, i.e. an Expert Advisor or a script ...
|
||||
// DEAL_REASON_VMARGIN => The deal was executed after charging the variation margin ...
|
||||
// DEAL_REASON_ROLLOVER => The deal was executed due to a rollover ...
|
||||
ENUM_DEAL_REASON reason;
|
||||
};
|
||||
|
||||
//
|
||||
// Model Specific Order ...
|
||||
struct XOrder
|
||||
{
|
||||
//
|
||||
// the ID of expert that placed the order ...
|
||||
ulong magic;
|
||||
|
||||
//
|
||||
// the ID of position ...
|
||||
ulong positionId;
|
||||
|
||||
//
|
||||
// the name of order symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// the ticket of an order, previously selected for access ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// the time of order placement ...
|
||||
datetime timeSetup;
|
||||
|
||||
//
|
||||
// the time of order execution or cancellation ...
|
||||
datetime timeDone;
|
||||
|
||||
//
|
||||
// the order expiration time ...
|
||||
datetime timeExpiration;
|
||||
|
||||
//
|
||||
// the order price ...
|
||||
double priceOpen;
|
||||
|
||||
//
|
||||
// the current price by order symbol ...
|
||||
double priceCurrent;
|
||||
|
||||
//
|
||||
// the price of a pending order ...
|
||||
double priceStopLimit;
|
||||
|
||||
//
|
||||
// the order's Stop Loss ...
|
||||
double stopLoss;
|
||||
|
||||
//
|
||||
// the order's Take Profit ...
|
||||
double takeProfit;
|
||||
|
||||
//
|
||||
// the initial volume of order ...
|
||||
double volumeInitial;
|
||||
|
||||
//
|
||||
// the unfilled volume of order ...
|
||||
double volumeCurrent;
|
||||
|
||||
//
|
||||
// the order comment ...
|
||||
string comment;
|
||||
|
||||
//
|
||||
// the order type ...
|
||||
// --------------------
|
||||
// ORDER_TYPE_BUY => Market Buy order ...
|
||||
// ORDER_TYPE_SELL => Market Sell order ...
|
||||
// ORDER_TYPE_BUY_LIMIT => Buy Limit pending order ...
|
||||
// ORDER_TYPE_SELL_LIMIT => Sell Limit pending order ...
|
||||
// ORDER_TYPE_BUY_STOP => Buy Stop pending order ...
|
||||
// ORDER_TYPE_SELL_STOP => Sell Stop pending order ...
|
||||
// ORDER_TYPE_BUY_STOP_LIMIT => Upon reaching the order price, a pending Buy Limit order is placed at the StopLimit price ...
|
||||
// ORDER_TYPE_SELL_STOP_LIMIT => Upon reaching the order price, a pending Sell Limit order is placed at the StopLimit price ...
|
||||
// ORDER_TYPE_CLOSE_BY => Order to close a position by an opposite one ...
|
||||
ENUM_ORDER_TYPE type;
|
||||
|
||||
//
|
||||
// the order state ...
|
||||
// --------------------------
|
||||
// ORDER_STATE_STARTED => Order checked, but not yet accepted by broker ...
|
||||
// ORDER_STATE_PLACED => Order accepted ...
|
||||
// ORDER_STATE_CANCELED => Order canceled by client ...
|
||||
// ORDER_STATE_PARTIAL => Order partially executed ...
|
||||
// ORDER_STATE_FILLED => Order fully executed ...
|
||||
// ORDER_STATE_REJECTED => Order rejected ...
|
||||
// ORDER_STATE_EXPIRED => Order expired ...
|
||||
// ORDER_STATE_REQUEST_ADD => Order is being registered (placing to the trading system)
|
||||
// ORDER_STATE_REQUEST_MODIFY => Order is being modified (changing its parameters) ...
|
||||
// ORDER_STATE_REQUEST_CANCEL => Order is being deleted (deleting from the trading system) ...
|
||||
ENUM_ORDER_STATE state;
|
||||
|
||||
//
|
||||
// the order filling type ...
|
||||
// ----------------------------
|
||||
// ORDER_FILLING_FOK => Fill or Kill
|
||||
// An order can be executed in the specified volume only.
|
||||
// If the necessary amount of a financial instrument is currently unavailable in the market,
|
||||
// the order will not be executed.
|
||||
// The desired volume can be made up of several available offers.
|
||||
// The possibility of using FOK orders is determined at the trade server.
|
||||
// ORDER_FILLING_IOC => Immediate or Cancel
|
||||
// A trader agrees to execute a deal with the volume maximally available in the market within that indicated in the order.
|
||||
// If the request cannot be filled completely, an order with the available volume will be executed,
|
||||
// and the remaining volume will be canceled.
|
||||
// The possibility of using IOC orders is determined at the trade server.
|
||||
// ORDER_FILLING_BOC => Passive (Book or Cancel)
|
||||
// The BoC order assumes that the order can only be placed in the Depth of Market and cannot be immediately executed.
|
||||
// If the order can be executed immediately when placed, then it is canceled.
|
||||
// In fact, the BOC policy guarantees that the price of the placed order will be worse than
|
||||
// the current market. BoC orders are used to implement passive trading,
|
||||
// so that the order is not executed immediately when placed and does not affect current liquidity.
|
||||
// Only limit and stop limit orders are supported (ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT, ORDER_TYPE_BUY_STOP_LIMIT, ORDER_TYPE_SELL_STOP_LIMIT).
|
||||
// ORDER_FILLING_RETURN => Return
|
||||
// In case of partial filling, an order with remaining volume is not canceled but processed further.
|
||||
// Return orders are not allowed in the Market Execution
|
||||
// mode (market execution — SYMBOL_TRADE_EXECUTION_MARKET).
|
||||
ENUM_ORDER_TYPE_FILLING typeFilling;
|
||||
|
||||
//
|
||||
// the type of order at the time of the expiration ...
|
||||
// --------------------------------------------------------
|
||||
// ORDER_TIME_GTC => Good till cancel order ...
|
||||
// ORDER_TIME_DAY => Good till current trade day order ...
|
||||
// ORDER_TIME_SPECIFIED => Good till expired order ...
|
||||
// ORDER_TIME_SPECIFIED_DAY => The order will be effective till 23:59:59 of the specified day.
|
||||
// If this time is outside a trading session, the order expires in the nearest trading time ...
|
||||
ENUM_ORDER_TYPE_TIME typeTime;
|
||||
|
||||
//
|
||||
// The reason for order placing ...
|
||||
// --------------------------------------
|
||||
// ORDER_REASON_SL => The order was placed as a result of Stop Loss activation ...
|
||||
// ORDER_REASON_TP => The order was placed as a result of Take Profit activation ...
|
||||
// ORDER_REASON_SO => The order was placed as a result of the Stop Out event ...
|
||||
// ORDER_REASON_WEB => The order was placed from a web platform ...
|
||||
// ORDER_REASON_CLIENT => The order was placed from a desktop terminal ...
|
||||
// ORDER_REASON_MOBILE => The order was placed from a mobile application ...
|
||||
// ORDER_REASON_EXPERT => The order was placed from an MQL5-program, i.e. by an Expert Advisor or a script ...
|
||||
ENUM_ORDER_REASON reason;
|
||||
};
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,258 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 NN Class Library
|
||||
// ----------------------------------------
|
||||
// Name: XNNClass
|
||||
// Description: provides all classes for implementing
|
||||
// Neural Network ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
class XCNNBase
|
||||
{
|
||||
//
|
||||
// Public Definitions ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCNNBase(
|
||||
int nodes = 10, // Number of Input Nodes
|
||||
double starterWeight = 0.5, // start weight for each input
|
||||
double coEfficient = 0.1, // COEfficient Multiplier
|
||||
double upperRange = 1, // Upper Normal Range Value
|
||||
double lowerRange = -1, // Lower Normal Range Value
|
||||
double learningRates = 0.1 // Back Propagation Learning Rate
|
||||
) {
|
||||
//
|
||||
mNodes = nodes;
|
||||
mUpperRange = upperRange;
|
||||
mLowerRange = lowerRange;
|
||||
mCoEfficient = coEfficient;
|
||||
mLearningRates = learningRates;
|
||||
mStarterWeight = starterWeight;
|
||||
|
||||
//
|
||||
ReConstructWeights();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCNNBase() {}
|
||||
|
||||
//
|
||||
// Protected Definitions ...
|
||||
void NormalizeInputs(double &inputs[], double &result[])
|
||||
{
|
||||
//
|
||||
ArrayFree(result);
|
||||
ArrayResize(result, 1);
|
||||
|
||||
//
|
||||
// Validate inputs ...
|
||||
if (ArraySize(inputs) != mNodes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Result ...
|
||||
ArrayResize(result, mNodes);
|
||||
|
||||
//
|
||||
// Calculating min and max range value ...
|
||||
double minRangeValue = inputs[ArrayMinimum(inputs)];
|
||||
double maxRangeValue = inputs[ArrayMaximum(inputs)];
|
||||
|
||||
//
|
||||
// Loop through Inputs nd Normalize them ...
|
||||
for (int i = 0; i < mNodes; i++)
|
||||
{
|
||||
//
|
||||
double normalValue = (((inputs[i] - minRangeValue) * (mUpperRange - mLowerRange)) / (maxRangeValue - minRangeValue)) + mLowerRange;
|
||||
result[i] = normalValue;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Hyperbolic Tangent Activation Function ...
|
||||
double TanHActivationFunction(double weightedInputs)
|
||||
{
|
||||
//
|
||||
double result = (exp(weightedInputs) - exp(-weightedInputs)) / (exp(weightedInputs) + exp(-weightedInputs));
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Weighted Inputs ...
|
||||
double CalculateWeightedInputs(
|
||||
double &inputs[],
|
||||
bool applyCOEfficient = true)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes)
|
||||
{
|
||||
//
|
||||
result = -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < mNodes; i++)
|
||||
{
|
||||
result += inputs[i] * mWeights[i];
|
||||
}
|
||||
|
||||
//
|
||||
// Multiply if required ...
|
||||
if (applyCOEfficient)
|
||||
{
|
||||
result *= mCoEfficient;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Hidden Layers ...
|
||||
virtual double CalculateHiddenLayer(double &inputs[])
|
||||
{
|
||||
//
|
||||
// this is Default Activation Function which used ...
|
||||
// you can override this by writing your own ...
|
||||
double totalWeightedInputs = CalculateWeightedInputs(inputs);
|
||||
double result = TanHActivationFunction(totalWeightedInputs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Output Layers ...
|
||||
double CalculateOutputLayer(double &inputs[])
|
||||
{
|
||||
//
|
||||
double result = -1;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double normalizedInputs[];
|
||||
NormalizeInputs(inputs, normalizedInputs);
|
||||
if (ArraySize(normalizedInputs) != mNodes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double hiddenLayerResult = CalculateHiddenLayer(normalizedInputs);
|
||||
|
||||
//
|
||||
result = 1 * hiddenLayerResult;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Basck Propaggation Learning ...
|
||||
void BackPropagation(
|
||||
double &inputs[],
|
||||
double &outputs,
|
||||
double targetOutput
|
||||
) {
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double normalizedInputs[];
|
||||
NormalizeInputs(inputs, normalizedInputs);
|
||||
if (ArraySize(normalizedInputs) != mNodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double error = targetOutput - outputs;
|
||||
double derivative = 1 - MathPow(outputs, 2);
|
||||
|
||||
//
|
||||
for (int i = 0; i < mNodes; i++) {
|
||||
//
|
||||
double gradient = error * derivative * inputs[i];
|
||||
mWeights[i] = mLearningRates * gradient;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
//
|
||||
// Private Definitions ...
|
||||
private:
|
||||
//
|
||||
// Number of Input Nodes ...
|
||||
int mNodes;
|
||||
|
||||
//
|
||||
// Specify Upper range of Normal Values ...
|
||||
double mUpperRange;
|
||||
|
||||
//
|
||||
// Specify Lower range of Normal Values ...
|
||||
double mLowerRange;
|
||||
|
||||
//
|
||||
// Starter Weight for each input node ...
|
||||
double mStarterWeight;
|
||||
|
||||
//
|
||||
// double Input Node Weights ...
|
||||
double mWeights[];
|
||||
|
||||
//
|
||||
// CoEfficient is a multiplyer for weighted inputs ...
|
||||
double mCoEfficient;
|
||||
|
||||
//
|
||||
// Back Propagation Learning Rates ...
|
||||
double mLearningRates;
|
||||
|
||||
//
|
||||
// ReConstruct Weights ...
|
||||
void ReConstructWeights() {
|
||||
//
|
||||
ArrayFree(mWeights);
|
||||
ArrayResize(mWeights, mNodes);
|
||||
|
||||
//
|
||||
for (int i = 0; i< mNodes; i++) {
|
||||
mWeights[i] = mStarterWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user