How to create MQL5 Keltner Channel programmatically
How to create MQL5 Keltner Channel programmatically
Loading saved threads...
Geraldo Isaaks · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Geraldo Isaaks
Original post: https://stackoverflow.com/questions/78196888
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I'm trying to create/use Keltner Channel indicator in my MQL5 Expert Advisor but for some reason it is not working. I know that at the moment MQL5 doesn't have a built-in indicator, so I am trying to manually create one using the following code, can anyone please assist in fixing the problem:
In the OnInit() function:
int bars = iBars(NULL, TimeFrame);
ArrayResize(upperKeltner, bars);
ArrayResize(lowerKeltner, bars);
double atr = iATR(_Symbol, _Period, 14);
for(int i = 0; i < count; i++)
{
double typical_price = (iOpen(_Symbol, _Period, i) + iHigh(_Symbol, _Period, i) + iLow(_Symbol, _Period, i)) / 3.0;
upperKeltner[i] = typical_price + atr * 1.5;
lowerKeltner[i] = typical_price - atr * 1.5;
}
In the OnTick() function:
ArrayResize(upperKeltner, 1);
ArrayResize(lowerKeltner, 1);
CopyBuffer(handleKeltner, 0, 0, 1, upperKeltner);
CopyBuffer(handleKeltner, 1, 0, 1, lowerKeltner);
Quote
Report
joserogerio84 · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: joserogerio84
Original post: https://stackoverflow.com/a/78211234
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
To create a indicator, you has to place the code in the OnCalculate function.
What error is happening?
In the CodeBase already has the Indicator.
https://www.mql5.com/pt/code/16740
Quote
Report
Boyka Smith · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Boyka Smith
Original post: https://stackoverflow.com/a/78518031
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
In MQL5, indicator values are stored in buffer.So use CopyBuffer(...) function to get values. This function works well. I will give you the code I have ever experienced.
int handleKeltner;
double upperKeltner[], lowerKeltner[];
OnInit(){
handleKeltner = (declare Keltner indicator)
}
OnTimer(){
CopyBuffer(handleKeltner, 0, 0, 1, upperKeltner);
CopyBuffer(handleKeltner, 1, 0, 1, lowerKeltner);
double curUpperKeltner = upperKeltner[0], curUpperKeltner = lowerKeltner[0];
}
Following me leads to Success.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Geraldo Isaaks Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/78196888 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'm trying to create/use Keltner Channel indicator in my MQL5 Expert Advisor but for some reason it is not working. I know that at the moment MQL5 doesn't have a built-in indicator, so I am trying to manually create one using the following code, can anyone please assist in fixing the problem: In the OnInit() function: int bars = iBars(NULL, TimeFrame); ArrayResize(upperKeltner, bars); ArrayResize(lowerKeltner, bars); double atr = iATR(_Symbol, _Period, 14); for(int i = 0; i < count; i++) { double typical_price = (iOpen(_Symbol, _Period, i) + iHigh(_Symbol, _Period, i) + iLow(_Symbol, _Period, i)) / 3.0; upperKeltner[i] = typical_price + atr * 1.5; lowerKeltner[i] = typical_price - atr * 1.5; } In the OnTick() function: ArrayResize(upperKeltner, 1); ArrayResize(lowerKeltner, 1); CopyBuffer(handleKeltner, 0, 0, 1, upperKeltner); CopyBuffer(handleKeltner, 1, 0, 1, lowerKeltner);
Checking account access…