Arkadaşlar kolay gelsin. Elimde metastock kodu yazılmış bir indikatör var da ben idealin diline çevirmeye çalıştım 2 3 gün, fakat beceremedim. Çok zor gibi görünmüyor kod ama içinde döngülerin olması gerektiğini düşündüğüm yerleri bir türlü ayarlayamadım.
Yardımcı olacak arkadaşlar varsa onlara biraz zahmet olacak ama, eğer çeviren birisi olursa kullanışlı bir indikatör olduğunu düşünüyorum.
Kod burdan itibaren başlıyor:::
SL:=input("SLOW LIMIT",0,10,0.05);
FL:=input("FAST LIMIT",0,10,0.5);
price:=(H+L)/2;
Smooth:=(4*Price + 3*REF(Price,-1) + 2*REF(Price,-2) + REF(Price,-3)) / 10;
Detrender:= (.0962*Smooth + .5769*REF(Smooth,-2) - .5769*REF(Smooth,-4) - .0962*REF(Smooth,-6))*(.075*P+ .54);
Q1:= (.0962*Detrender + .5769*REF(Detrender,-2) - .5769*REF(Detrender,-4) - .0962*REF(Detrender,-6))*(.075*P + .54);
I1:= REF(Detrender,-3);
jI:= (.0962*I1 + .5769*REF(I1,-2) - .5769*REF(I1,-4) - .0962*REF(I1,-6))*(.075*P + .54);
jQ:= (.0962*Q1 + .5769*REF(Q1,-2) - .5769*REF(Q1,-4) - .0962*REF(Q1,-6))*(.075*P + .54);
I21:= I1 - jQ;
Q21:= Q1 + jI;
I2:= .2*I21 + .8*PREV;
Q2:= .2*Q21 + .8*PREV;
Re1:= I2*REF(I2,-1) + Q2*REF(Q2,-1);
Im1:= I2*REF(Q2,-1) - Q2*REF(I2,-1);
Re:= .2*Re1 + .8*PREV;
Im:= .2*Im1 + .8*PREV;
P1:=If(Im<>0 and Re<>0, 2*(4*atn(1))/ATN(Im/Re),PREV);
P2:=If(P1>1.5*REF(P1,-1), 1.5*REF(P1,-1),If(P1 < .67*REF(P1,-1),.67*REF(P1,-1),P1));
P3:=If(P2 < 6,6,If(P2 >50,50,P2));
P:= .2*P3 + .8*REF(P3,-1);
SmoothPeriod:= .33*P + .67*PREV;
PHASE:=If(I1<>0,180/(4*atn(1))*ATN(Q1 / I1),PREV);
DeltaPhase1:= REF(Phase,-1) - Phase;
DeltaPhase:=If(DeltaPhase1<1,1,DeltaPhase1);
alpha1:=FL/ DeltaPhase;
alpha:=If(alpha1< SL,SL,IF(FL<alpha1,FL,alpha1));
MAMA:= alpha*PRICE + (1 - alpha)*PREV;
FAMA:= .5*alpha*MAMA + (1 - .5*alpha)*PREV;
MAMA;
FAMA
Listeleri tanıttım, değişkenleri de ayarladım ama gerisi gelmedi :D
Bu kodu bi text editore kaydedip -ben şahsen notepad++ kullanıyorum- ismini uzantısıyla beraber lib.cs diye değiştirip ideal klasörüne atın. Daha sonra da sistem tanımlarından bunun içinde olan metodlar var onları şöyle yazıp sistem olarak kaydedin:
Lib.SistemiBaslat(Sistem);
Lib.BarNoktalariTest();
Lib.AnatrendleriCiz();
Lib.AraTerndleriCiz();
Lib.YataylariCiz();
Lib.SistemCizgileriniCiz();
Bilgisayar mühendisi samimi bir arkadaşımdan biraz destek aldım o da yapıverdi :D
Bendekini visual studiodan o biraz oynayıp derlemişti. Ben daha sonra uzantısını değiştirip kendim yukarda anlattığım gibi yaptım yine çalıştı. Ben çizgileri ve bazı bikaç şeyi kendime göre değiştirmiştim. Eğer çalışmazsa ben size kendi lib.cs dosyasını atarım bir şekilde artık.
Kolay gelsin![]()
kolay gelsin arkadaşlar ideale çevirebilecek var mı?
def c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def pricedata = hl2(period = agg);
DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));
input lengthCCI = 50;
input lengthATR = 5;
input AtrFactor = 0.7;
def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
then 0
else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
then Max(MT1[1], pricedata - ATRcci)
else Min(MT1[1], pricedata + ATRcci);
plot data = MT1;
data.AssignValueColor(if c < MT1 then Color.RED else Color.GREEN);
kolay gelsin
ideal da bi şart belirleyip oraya geldigi an bana otomatik mail atabilmesi için ne yapmam lazım mail ayarları için
Kolay gelsin herkese iyi haftasonlarınız olsun... Yukardaki kod metastock diliyle yazılmış mesa adaptive moving average kodu, ben az bi araştırmadan sonra bu kodun C# ile yazılmış halini de buldum. Onun üzerinde çalışmanın daha mantıklı olduğunu düşündüm ona biraz baktım fakat onu da bir türlü çalıştıramadım. Burda belki forumun ana konusu itibariyle metastocktan ziyade C# ta tecrübeli arkadaşlar varsa C# kodu onların daha da anlayacağı şekildedir diye onu da aşağıda paylaştım:
using System;
using cAlgo.API;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class Mama : Indicator
{
#region Input Parameters
[Parameter("FastLimit", DefaultValue = 0.5)]
public double FastLimit { get; set; }
[Parameter("SlowLimit", DefaultValue = 0.05)]
public double SlowLimit { get; set; }
#endregion
#region Output
[Output("MAMA", Color = Colors.Blue)]
public IndicatorDataSeries MamaResult { get; set; }
[Output("FAMA", Color = Colors.Red)]
public IndicatorDataSeries FamaResult { get; set; }
#endregion
#region private fields
private IndicatorDataSeries _alpha;
private IndicatorDataSeries _deltaPhase;
private IndicatorDataSeries _detrender;
private IndicatorDataSeries _i1;
private IndicatorDataSeries _i2;
private IndicatorDataSeries _im;
private IndicatorDataSeries _ji;
private IndicatorDataSeries _jq;
private IndicatorDataSeries _period;
private IndicatorDataSeries _period1;
private IndicatorDataSeries _period2;
private IndicatorDataSeries _phase;
private IndicatorDataSeries _price;
private IndicatorDataSeries _q1;
private IndicatorDataSeries _q2;
private IndicatorDataSeries _re;
private IndicatorDataSeries _smooth;
private IndicatorDataSeries _smoothPeriod;
#endregion
protected override void Initialize()
{
_price = CreateDataSeries();
_smooth = CreateDataSeries();
_detrender = CreateDataSeries();
_period = CreateDataSeries();
_period1 = CreateDataSeries();
_period2 = CreateDataSeries();
_smoothPeriod = CreateDataSeries();
_phase = CreateDataSeries();
_deltaPhase = CreateDataSeries();
_alpha = CreateDataSeries();
_q1 = CreateDataSeries();
_i1 = CreateDataSeries();
_ji = CreateDataSeries();
_jq = CreateDataSeries();
_i2 = CreateDataSeries();
_q2 = CreateDataSeries();
_re = CreateDataSeries();
_im = CreateDataSeries();
}
public override void Calculate(int index)
{
if (index <= 5)
{
MamaResult[index] = 0;
FamaResult[index] = 0;
_price[index] = (MarketSeries.High[index] + MarketSeries.Low[index]) / 2;
_smooth[index] = 0;
_detrender[index] = 0;
_period[index] = 0;
_smoothPeriod[index] = 0;
_phase[index] = 0;
_deltaPhase[index] = 0;
_alpha[index] = 0;
_q1[index] = 0;
_i1[index] = 0;
_ji[index] = 0;
_jq[index] = 0;
_i2[index] = 0;
_q2[index] = 0;
_re[index] = 0;
_im[index] = 0;
return;
}
_price[index] = (MarketSeries.High[index] + MarketSeries.Low[index])/2;
_smooth[index] = (4*_price[index] + 3*_price[index - 1] + 2*_price[index - 2] + _price[index - 3])/10;
_detrender[index] = (.0962*_smooth[index] + .5769*_smooth[index - 2] - .5769*_smooth[index - 4] - .0962*_smooth[index - 6])*(.075*_period[index - 1] + .54);
// Compute InPhase and Quadrature components
_q1[index] = (.0962*_detrender[index] + .5769*_detrender[index - 2] - .5769*_detrender[index - 4] - .0962*_detrender[index - 6])*(.075*_period[index - 1] + .54);
_i1[index] = _detrender[index - 3];
// Advance the phase of I1 and Q1 by 90 degrees
_ji[index] = (.0962*_i1[index] + .5769*_i1[index - 2] - .5769*_i1[index - 4] - .0962*_i1[index - 6])*(.075*_period[index - 1] + .54);
_jq[index] = (.0962*_q1[index] + .5769*_q1[index - 2] - .5769*_q1[index - 4] - .0962*_q1[index - 6])*(.075*_period[index - 1] + .54);
// Phasor addition for 3 bar averaging
_i2[index] = _i1[index] - _jq[index];
_q2[index] = _q1[index] + _ji[index];
// Smooth the I and Q components before applying the discriminator
_i2[index] = .2*_i2[index] + .8*_i2[index - 1];
_q2[index] = 0.2*_q2[index] + 0.8*_q2[index - 1];
// Homodyne Discriminator
_re[index] = _i2[index]*_i2[index - 1] + _q2[index]*_q2[index - 1];
_im[index] = _i2[index]*_q2[index - 1] - _q2[index]*_i2[index - 1];
_re[index] = 0.2*_re[index] + 0.8*_re[index - 1];
_im[index] = 0.2*_im[index] + 0.8*_im[index - 1];
double epsilon = Math.Pow(10, -10);
if (Math.Abs(_im[index] - 0.0) > epsilon && Math.Abs(_re[index] - 0.0) > epsilon)
if (Math.Abs(Math.Atan(_im[index] / _re[index]) - 0.0) > epsilon)
_period[index] = 360 / Math.Atan(_im[index] / _re[index]);
else
_period[index] = 0;
if (_period[index] > 1.5*_period[index - 1])
_period[index] = 1.5*_period[index - 1];
if (_period[index] < 0.67*_period[index - 1])
_period[index] = 0.67*_period[index - 1];
if (_period[index] < 6)
_period[index] = 6;
if (_period[index] > 50)
_period[index] = 50;
_period[index] = 0.2*_period[index] + 0.8*_period[index - 1];
_smoothPeriod[index] = .33*_period[index] + .67*_smoothPeriod[index - 1];
if (Math.Abs(_i1[index] - 0) > epsilon)
_phase[index] = Math.Atan(_q1[index]/_i1[index]);
if (Math.Abs(Math.Atan(_q1[index] / _i1[index]) - 0.0) > epsilon)
_phase[index] = Math.Atan(_q1[index] / _i1[index]);
else
_phase[index] = 0;
_deltaPhase[index] = _phase[index - 1] - _phase[index];
if (_deltaPhase[index] < 1)
_deltaPhase[index] = 1;
_alpha[index] = FastLimit/_deltaPhase[index];
if (_alpha[index] < SlowLimit)
_alpha[index] = SlowLimit;
MamaResult[index] = _alpha[index]*_price[index] + ((1 -_alpha[index])*MamaResult[index - 1]);
FamaResult[index] = .5 * _alpha[index] * MamaResult[index] + (1 - 0.5 * _alpha[index]) * FamaResult[index - 1];
}
}
}
Fakat ben bunu da idealin kendi diline çeviremedim. Matematiksel kısmın hemen hemen hepsi tamamen aynı fakat kod her nasılsa ilk _detrender kısmını hesaplarken döngüyü durduruyor(Eğer bütün hesaplamaları index'i saydıracak şekilde for döngüsünün içine koyduğumuzu varsayarsak ki mantıken öyle olması gerekmez mi?) Dolayısıyla hesaplamaların hepsi sıfır oluyor...
Çok fazla uzun olmaması için kendi kodumu bu iletiye yazmadım, ilgilenen arkadaşlar olursa hemen atıveririm orda listeler falan da yapılı...
Yardımcı olacak arkadaşlara teşekkür ederim şimdiden![]()
Yer İmleri