|
My Own Indicator |
Posted by Andreas on Sep-30-2016 19:09 |
|
Hi
I have Problem to programm this easy indicator
Maybe you can help me
// -- parameters
//sensitivity = 150
//fastLength=20 //"FastEMA Length"
//slowLength=40 //"SlowEMA Length"
//channelLength=20 //"BB Channel Length"
//mult=2.0 //"BB Stdev Multiplier")
// indis
if barindex>slowLength then
calcMACD = MACD[fastLength,slowLength,9](close)
calcBBUpper = average[channelLength](close)+(mult*std[channelLength](close))
calcBBLower = average[channelLength](close)-(mult*std[channelLength](close))
t1 = (calcMACD-calcMACD[1])*sensitivity
e1 = calcBBUpper - calcBBLower
if t1>=0 then
trendUP = t1
trendDOWN = 0
else
trendUP = 0
trendDOWN = -1*t1
endif
endif |
Re: My Own Indicator |
Posted by Peter Kwan on Oct-01-2016 00:40 |
|
Hi Andreas,
Would you mind to clarify what is the issue in your case?
The "code" in your message appears to be in a special language. I probably have not seen this language before. I assume you understand what the "code" means or is trying to do.
My guess is that the calcMACD is some sort of MACD data series (an array of numbers), and calcBBUpper and calcBLower are the upper and lower bounds of the Bollinger band. You can use the ArrayMath utility to compute these series in ChartDirector. The ChartDirector FinanceChart supports MACD and Bollinger Band and the FinanceChart is released with source code. You can use the FinanceChart source code as a reference on how to compute these series with ArrayMath.
The "t1 = (calcMACD-calcMACD[1])*sensitivity" seems to be a difference (Array.delta) followed by a multiplication by a scalar (ArrayMath.mul).
The line "e1 = calcBBUpper - calcBBLower" seems to be array subtraction (use ArrayMath.sub).
The trendUp is the same as t1, except negative values are replaced with 0 (ArrayMath.selectGTZ). Similary, the trendDown is the same as -t1, except negative values are replaced with 0.
Regards
Peter Kwan |
Re: My Own Indicator |
Posted by Andreas on Oct-06-2016 21:39 |
|
Thanks that works now
But i have an other Indi where i have problem
It is one from MT4
the adx is from the lib
'pos/neg directional movement
Dim pos As ArrayMath = New ArrayMath(m_highData).delta().selectGTZ()
Dim neg As ArrayMath = New ArrayMath(m_lowData).delta().mul(-1).selectGTZ()
Dim delta As Double() = New ArrayMath(pos.result()).[sub](neg.result()).result()
pos.selectGTZ(delta)
neg.selectLTZ(delta)
'initial value
Dim posData As Double() = pos.result()
Dim negData As Double() = neg.result()
If (posData.Length > 1) AndAlso (posData(1) <> Chart.NoValue) AndAlso (negData(1) <> Chart.NoValue) Then
posData(1) = (posData(1) * 2 + negData(1)) / 3
negData(1) = (negData(1) + posData(1)) / 2
pos = New ArrayMath(posData)
neg = New ArrayMath(negData)
End If
'pos/neg directional index
Dim tr As Double() = computeTrueRange()
tr = New ArrayMath(tr).expAvg(1.0 / period).result()
pos.expAvg(1.0 / period).financeDiv(tr, 0).mul(100)
neg.expAvg(1.0 / period).financeDiv(tr, 0).mul(100)
'directional movement index ??? what happen if division by zero???
Dim totalDM As Double() = New ArrayMath(pos.result()).add(neg.result()).result()
Dim dx As ArrayMath = New ArrayMath(pos.result()).[sub](neg.result()).abs().financeDiv(totalDM, 0).mul(100).expAvg(1.0 / period)
-----------------------------------------------------------------------------------
then i do this
Dim countbars As Integer = m_highData.Length - 1
Dim tp, tn, alpha, beta As Double()
ReDim alpha(countbars)
ReDim beta(countbars)
Dim Gamma, delta1, zeta, epsilon As Double
For Theta As Integer = 1 To countbars
alpha(countbars - Theta) = 0.0
Next Theta
For Theta = 1 To countbars
beta(countbars - Theta) = 0.0
Next Theta
Dim Point = 0.0001
For Iota As Integer = countbars To 1 Step -1
tp = pos.result
tn = neg.result
Gamma = tp(Iota - 1)
delta1 = tp(Iota)
epsilon = tn(Iota - 1)
zeta = tn(Iota)
If Gamma > epsilon AndAlso delta1 < zeta Then
alpha(Iota) = m_lowData(Iota) - 5.0 * Point
End If
If Gamma < epsilon AndAlso delta1 > zeta Then
beta(Iota) = m_highData(Iota) + 5.0 * Point
End If
Next Iota
Dim tradeup As Boolean = False
Dim tradedown As Boolean = False
Dim tradep, traden As Double()
ReDim tradep(countbars)
ReDim traden(countbars)
For i = 0 To countbars
tradep(i) = 0.0
traden(i) = 0
Next i
For i As Integer = countbars To 0 Step -1
If alpha(0) <> 0 AndAlso tradeup Then
tradeup = False
tradep(i) = 1
End If
If Not tradeup AndAlso (alpha(0) = 0) Then
tradeup = True
End If
If beta(0) <> 0 AndAlso tradedown Then
tradedown = False
traden(i) = -1
End If
If Not tradedown AndAlso (beta(0) = 0) Then
tradedown = True
End If
Next
Dim c As XYChart = addIndicator(height)
Dim label1 As String = "ALPHA"
Dim label2 As String = "BETA"
addLineIndicator2(c, tradep, posColor, label1)
addLineIndicator2(c, traden, negColor, label2)
-------------------------------------------------------------------------------------------
but i have never a signal?????
here is the original Code mabe you can see what is wrong thanks
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
extern int ADXbars = 14;
extern int CountBars = 350;
extern string SoundFile="Alert.wav";
extern bool UseSound=true;
bool SoundBuy = False;
bool SoundSell = False;
double Alpha[];
double Beta[];
double Gamma;
double Delta;
double Epsilon;
double Zeta;
int init() {
string Kappa;
IndicatorBuffers(2);
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 233);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 234);
SetIndexBuffer(0, Alpha);
SetIndexBuffer(1, Beta);
return (0);
}
int start() {
if (CountBars >= Bars) CountBars = Bars;
SetIndexDrawBegin(0, Bars - CountBars);
SetIndexDrawBegin(1, Bars - CountBars);
int Eta = IndicatorCounted();
if (Eta < 0) return (-1);
if (Eta < 1) {
for (int Theta = 1; Theta <= CountBars; Theta++) Alpha[CountBars - Theta] = 0.0;
for (Theta = 1; Theta <= CountBars; Theta++) Beta[CountBars - Theta] = 0.0;
}
for (int Iota = CountBars; Iota >= 0; Iota--) {
Gamma = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_PLUSDI, Iota - 1);
Delta = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_PLUSDI, Iota);
Epsilon = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_MINUSDI, Iota - 1);
Zeta = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_MINUSDI, Iota);
if (Gamma > Epsilon && Delta < Zeta) Alpha[Iota] = Low[Iota] - 5.0 * Point;
if (Gamma < Epsilon && Delta > Zeta) Beta[Iota] = High[Iota] + 5.0 * Point;
}
//+------------------------------------------------------------------+
if (Alpha[1] != EMPTY_VALUE && Alpha[1] != 0 && SoundBuy)
{
SoundBuy = False;
tradeup=true;
}
if (!SoundBuy && (Alpha[1] == EMPTY_VALUE || Alpha[1] == 0)) SoundBuy = True;
if (Beta[1] != EMPTY_VALUE && Beta[1] != 0 && SoundSell)
{
SoundSell = False;
tradedown=true;
}
if (!SoundSell && (Beta[1] == EMPTY_VALUE || Beta[1] == 0)) SoundSell = True;
//+------------------------------------------------------------------+
return (0);
} |
Re: My Own Indicator |
Posted by Peter Kwan on Oct-07-2016 17:15 |
|
Hi Andreas,
If you have a working example, it should be easy to debug the code. You can just single step you code as well as the code of the working example. Then you can compare the variables for every step to see if they are different. They must eventually become different. In this way, you can catch where is the bug.
Just by reading your code, I can find the following two lines looking suspicious.
If alpha(0) <> 0 AndAlso tradeup Then
If beta(0) <> 0 AndAlso tradedown Then
They keep comparing the first element of alpha and beta to 0. I think the intention in your loop is to compare the element with index i with 0, not the element with index 0 with 0.
Regards
Peter Kwan |
|