※追記(2011/10/16 3:30)
筆者の想定外のバグが、@ahaha_fxtraderさんから指摘されましたので追記します。
先週予告した通り自宅よりテストしていましたが、OSの自動更新で中断されてしまっていました。(自動更新切るの忘れてた。。orz)そこで、今回は、本大会に提出したEAのコードを添付します。(そこでの意味が解りませんが^^;)
このEAコードには、重大なバグ(エラーは出ませんが。。)が含まれています。
さて、どこに含まれているでしょうか?(わかった方は、コメントよろしくお願いします。)
ヒントは、恥ずかしくて言えません。。
筆者が見つけたバグ以外に出てきたら。。。。orz (そのほうが、うれしいかも^^;)
KAZUYA.mq5
#property copyright "Copyright 2010, bighope"
#property link "http://expertadviser-bighope.blogspot.com/"
#property version "1.00"
#include <CATCtrade_J.mqh>
input double maxrisk = 0.85;
double symblerate[9]={0.1,0.2,0.15,0.05,0.15,0.1,0.05,0.15,0.05};
CATCtrade *GBPUSD = new CATCtrade;
CATCtrade *EURUSD = new CATCtrade;
CATCtrade *USDJPY = new CATCtrade;
CATCtrade *USDCAD = new CATCtrade;
CATCtrade *AUDUSD = new CATCtrade;
CATCtrade *EURGBP = new CATCtrade;
CATCtrade *EURAUD = new CATCtrade;
CATCtrade *EURJPY = new CATCtrade;
CATCtrade *GBPJPY = new CATCtrade;
bool Set=false;
bool Set_ob(){
if(!GBPUSD.Inputdate("GBPUSD",5,PERIOD_M30,maxrisk,symblerate[0],2000,1500,30,0.0015,0.009,0.064,0.018))return(false);
if(!EURUSD.Inputdate("EURUSD",5,PERIOD_M6,maxrisk,symblerate[1],2800,1500,30,0.003,0.006,0.184,0.0195))return(false);
if(!USDJPY.Inputdate("USDJPY",3,PERIOD_M20,maxrisk,symblerate[2],1000,900,30,0.001,0.005,0.03,0.0165))return(false);
if(!USDCAD.Inputdate("USDCAD",5,PERIOD_M12,maxrisk,symblerate[3],600,1300,30,0.002,0.01,0.064,0.114))return(false);
if(!AUDUSD.Inputdate("AUDUSD",5,PERIOD_H1,maxrisk,symblerate[4],1400,1300,30,0.001,0.01,0.13,0.087))return(false);
if(!EURGBP.Inputdate("EURGBP",5,PERIOD_H1,maxrisk,symblerate[5],1400,900,30,0.001,0.009,0.12,0.0585))return(false);
if(!EURAUD.Inputdate("EURAUD",5,PERIOD_H1,maxrisk,symblerate[6],2000,1100,30,0.0005,0.001,0.072,0.105))return(false);
if(!EURJPY.Inputdate("EURJPY",3,PERIOD_M30,maxrisk,symblerate[7],3000,1500,30,0.0005,0.008,0.022,0.042))return(false);
if(!GBPJPY.Inputdate("GBPJPY",3,PERIOD_M30,maxrisk,symblerate[8],600,1100,30,0.003,0.01,0.02,0.0405))return(false);
return(true);
}
int OnInit()
{
Set=Set_ob();
return(0);
}
void OnDeinit(const int reason)
{
delete GBPUSD;
delete EURUSD;
delete USDJPY;
delete USDCAD;
delete AUDUSD;
delete EURGBP;
delete EURAUD;
delete EURJPY;
delete GBPJPY;
}
void OnTick()
{
if(!Set)Set_ob();
datetime opentime;
opentime = TimeCurrent();
if(!GBPUSD.Trade(opentime)){Print("Error GBPUSD Resetting");Set=false;}
if(!EURUSD.Trade(opentime)){Print("Error EURUSD Resetting");Set=false;}
if(!USDJPY.Trade(opentime)){Print("Error USDJPY Resetting");Set=false;}
if(!USDCAD.Trade(opentime)){Print("Error USDJPY Resetting");Set=false;}
if(!AUDUSD.Trade(opentime)){Print("Error AUDUSD Resetting");Set=false;}
if(!EURGBP.Trade(opentime)){Print("Error EURGBP Resetting");Set=false;}
if(!EURAUD.Trade(opentime)){Print("Error EURAUD Resetting");Set=false;}
if(!EURJPY.Trade(opentime)){Print("Error EURJPY Resetting");Set=false;}
if(!GBPJPY.Trade(opentime)){Print("Error GBPJPY Resetting");Set=false;}
}
void OnTrade()
{
}
CATCtrade_J.mqh
#property copyright "Copyright 2010, bighope"
#property link "http://expertadviser-bighope.blogspot.com/"
#include <Csignal_J.mqh>
class CATCtrade : public CSignal
{
protected:
MqlTradeRequest m_request; MqlTradeResult m_result; MqlTradeCheckResult m_check_result; MqlTick last_tick;
ulong magic;
ulong deviation;
double ptp;
double pptp;
double psl;
double maxrisk;
double symblerate;
double positionopen;
double closelevel;
double creatlot(void);
ENUM_ORDER_TYPE creattype(const int typec);
bool PositionOpen(int typep);
bool PositionClose(void);
bool PositionModify(const double tp,const double sl);
void ClearStructures();
int PositionCheck();
public:
void CATCtrade();
bool Inputdate(const string Csymbl
,const int Cdigit
,const ENUM_TIMEFRAMES Ctimeframs
,const double Cmaxrisk
,const double Csymblerate
,const double takeprofit
,const double stoploss
,const int CDperiod
,const double alfaML
,const double alfaM
,const double alfaS
,const double alfaL);
bool Trade(const datetime Cnow);
};
void CATCtrade::CATCtrade(void){
magic =5989;
deviation =10;
ptp =0;
psl =0;
maxrisk =0;
symblerate =0;
}
double CATCtrade::creatlot(void){
double price=0.0;
double margin=0.0;
double lot=0.0,stepvol=0.0,minvol=0.0,maxvol=0.0;
if(!SymbolInfoDouble(symbl,SYMBOL_ASK,price)) return(0.0);
if(!OrderCalcMargin(ORDER_TYPE_BUY,symbl,1.0,price,margin)) return(0.0);
if(margin<=0.0) return(0.0);
lot=AccountInfoDouble(ACCOUNT_FREEMARGIN)*maxrisk/margin;
lot=lot*symblerate;
stepvol=SymbolInfoDouble(symbl,SYMBOL_VOLUME_STEP);
lot=stepvol*NormalizeDouble(lot/stepvol,0);
minvol=SymbolInfoDouble(symbl,SYMBOL_VOLUME_MIN);
maxvol =stepvol*NormalizeDouble(15.0*symblerate/stepvol,0);
if(lot<minvol) lot=minvol;
if(lot>maxvol) lot=maxvol;
return(lot);
}
ENUM_ORDER_TYPE CATCtrade::creattype(const int typec){
switch(typec){
case 2: return(ORDER_TYPE_BUY);
case -2: return(ORDER_TYPE_SELL);
default: return(NULL);
}
}
void CATCtrade::ClearStructures(void){
ZeroMemory(m_request);
ZeroMemory(m_result);
ZeroMemory(m_check_result);
ZeroMemory(last_tick);
}
int CATCtrade::PositionCheck(void){
positionopen=0;
if(PositionSelect(symbl)){
if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){
positionopen = PositionGetDouble(POSITION_PRICE_OPEN);
return(1);
}
if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){
positionopen = PositionGetDouble(POSITION_PRICE_OPEN);
return(-1);
}
}
return(0);
}
bool CATCtrade::PositionOpen(int typep){
double Eprice=0,tp_price=0,sl_price=0;
if(IsStopped()) return(false);
ClearStructures();
ENUM_ORDER_TYPE Etype;
Etype=creattype(typep);
if(!SymbolInfoTick(symbl,last_tick)){Print("Copytick form form,no date"); return(false);}
switch(typep)
{
case 2:
Eprice = last_tick.ask;
tp_price = (ptp>0)?NormalizeDouble(last_tick.bid+ptp*MathPow(0.1,digit),digit):0;
sl_price = (psl>0)?NormalizeDouble(last_tick.bid-psl*MathPow(0.1,digit),digit):0;
break;
case-2:
Eprice = last_tick.bid;
tp_price = (ptp>0)?NormalizeDouble(last_tick.ask-ptp*MathPow(0.1,digit),digit):0;
sl_price = (psl>0)?NormalizeDouble(last_tick.ask+psl*MathPow(0.1,digit),digit):0;
break;
default: break;
}
m_request.action =TRADE_ACTION_DEAL;
m_request.symbol =symbl;
m_request.magic =magic;
m_request.volume =creatlot();
m_request.type =Etype;
m_request.price =Eprice;
m_request.sl =sl_price;
m_request.tp =tp_price;
m_request.deviation =deviation;
m_request.type_filling=ORDER_FILLING_AON;
m_request.comment ="";
string action,result;
if(!OrderCheck(m_request,m_check_result))return(false);
if(!OrderSend(m_request,m_result))return(false);
return(true);
}
bool CATCtrade::PositionClose(void){
bool partial_close=false;
int retry_count =10;
uint retcode =TRADE_RETCODE_REJECT;
if(IsStopped()) return(false);
string action,result;
ClearStructures();
do
{
if(PositionSelect(symbl))
{
if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
{
m_request.type =ORDER_TYPE_SELL;
m_request.price=SymbolInfoDouble(symbl,SYMBOL_BID);
}
else
{
m_request.type =ORDER_TYPE_BUY;
m_request.price=SymbolInfoDouble(symbl,SYMBOL_ASK);
}
}
else
{
m_result.retcode=retcode;
return(false);
}
m_request.action =TRADE_ACTION_DEAL;
m_request.symbol =symbl;
m_request.deviation =deviation;
m_request.type_filling=ORDER_FILLING_AON;
m_request.volume =PositionGetDouble(POSITION_VOLUME);
double max_volume=SymbolInfoDouble(symbl,SYMBOL_VOLUME_MAX);
if(m_request.volume>max_volume)
{
m_request.volume=max_volume;
partial_close=true;
}
else
partial_close=false;
if(!OrderCheck(m_request,m_check_result))return(false);
if(!OrderSend(m_request,m_result)){
if(--retry_count!=0) continue;
return(false);
}
retcode=TRADE_RETCODE_DONE_PARTIAL;
if(partial_close) Sleep(1000);
}
while(partial_close);
return(true);
}
bool CATCtrade::Inputdate(const string Csymbl
,const int Cdigit
,const ENUM_TIMEFRAMES Ctimeframs
,const double Cmaxrisk
,const double Csymblerate
,const double takeprofit
,const double stoploss
,const int CDperiod
,const double alfaML
,const double alfaM
,const double alfaS
,const double alfaL){
if(!Set_Base(Csymbl,Ctimeframs,Cdigit))return(false);
if(!Set_DeMarker(CDperiod))return(false);
if(!Set_Heiken())return(false);
if(!Parameters(alfaML,alfaM,alfaL,alfaS))return(false);
maxrisk = Cmaxrisk;
symblerate = Csymblerate ;
ptp =0;
pptp = takeprofit;
psl = stoploss;
if(psl!= stoploss){Print("Set StopLoss ERR"); return(false);}
if(maxrisk!=Cmaxrisk)return(false);
if(symblerate!=Csymblerate)return(false);
return(true);
}
bool CATCtrade::Trade(const datetime Cnow){
int Tradesignal=0;
int checkpos;
datetime opentime,min;
min = Cnow%(frametime(timeframes)*60);
opentime = Cnow - min;
Tradesignal = Signal(opentime);
checkpos = PositionCheck();
switch(Tradesignal)
{
case 3:
if(checkpos==1)return(true);
if(checkpos==-1){ if(PositionClose())return(true); else return(false);}
if(checkpos==0){ if(PositionOpen(2))return(true); else return(false);}
return(true);
case 1:
if(checkpos==1){if(PositionClose())return(true); else return(false);}
return(true);//指摘ヶ所
case 2:
if(checkpos>0){
if(!SymbolInfoTick(symbl,last_tick)){Print("Copytick form form,no date"); return(false);}
if((last_tick.bid - positionopen) > pptp*MathPow(0.1,digit)){ if(PositionClose())return(true); else return(false);}
}
return(true);
case 0:
return(true);
case -2:
if(checkpos<0){
if(!SymbolInfoTick(symbl,last_tick)){Print("Copytick form form,no date"); return(false);}
if((positionopen - last_tick.ask) > pptp*MathPow(0.1,digit)){ if(PositionClose())return(true); else return(false);}
}
return(true);
case -1:
if(checkpos==-1){if(PositionClose())return(true); else return(false);}
return(true);//指摘ヶ所
case -3:
if(checkpos==-1)return(true);
if(checkpos==1){ if(PositionClose())return(true); else return(false);}
if(checkpos==0){ if(PositionOpen(-2))return(true); else return(false);}
return(true);
default:
return(false);
}
return(false);
}
CSignal_J.mqh
#property copyright "Copyright 2010, bighope"
#property link "http://expertadviser-bighope.blogspot.com/"
#include <Cindibox_J.mqh>
class CSignal : public Cindibox_h
{
public:
void CSignal(void);
bool Parameters(
const double MLalfa
,const double Malfa
,const double Lalfa
,const double Salfa);
int Signal(datetime now);
};
void CSignal::CSignal(void){
}
bool CSignal::Parameters(
const double MLalfa
,const double Malfa
,const double Lalfa
,const double Salfa){
Set_Heiken();
Set_Ma(MLalfa,Malfa,Lalfa,Salfa);
Set_DeMarker(30);
return(true);
}
int CSignal::Signal(datetime now)
{
int sum=0,sigk=0;
int MGsig=0,MMsig=0,MLsig=0,Hsig=0,Gsig=0,Msig=0,Lsig=0,Ssig=0,HLsig=0,Dsig=0;
Custom_date Heiken1;
Custom_date Heiken2;
Custom_date Heiken3;
Custom_date Heiken4;
Custom_MA MAn;
Custom_MA MAb;
HL_date HL;
double DM;
int i=Run(now);
if(i==0)return(10);
Heiken1=Get_HeikenAshi(-1);
Heiken2=Get_HeikenAshi(-2);
Heiken3=Get_HeikenAshi(-3);
Heiken4=Get_HeikenAshi(-4);
MAn = Get_Ma(-1);
MAb = Get_Ma(-25);
DM = Get_DeMarker(-1).main;
HL =Get_HL();
Gsig = (MAn.megal > MAb.megal)?1:-1;
Msig = (MAn.mega > MAb.mega)?1:-1;
Lsig = (MAn.longrange > MAb.longrange)?1:-1;
Ssig = (MAn.shortrange > MAb.shortrange)?1:-1;
MGsig = (MAn.mega >MAn.megal )?1:-1;
MMsig = (MAn.longrange > MAn.mega)?1:-1;
MLsig = (MAn.shortrange > MAn.longrange)?1:-1;
HLsig = (MAn.longrange > HL.av)?1:-1;
if( (Heiken1.close>Heiken1.open)
&& (Heiken2.close>Heiken2.open)
&& (Heiken3.close>Heiken3.open)
&& (Heiken4.close>Heiken4.open))Hsig=1;
if( (Heiken1.close<Heiken1.open)
&& (Heiken2.close<Heiken2.open)
&& (Heiken3.close<Heiken3.open)
&& (Heiken4.close<Heiken4.open))Hsig=-1;
if(DM>=0.7)Dsig=2;
if(DM<0.7 && DM>0.5)Dsig=1;
if(DM<0.5 && DM>0.3)Dsig=-1;
if(DM <= 0.3)Dsig=-2;
sum = 2*(MGsig+MMsig+MLsig+Gsig+Msig+Lsig+HLsig+Dsig)+Hsig+Ssig;
if(sum >=4 && sum<=5) sigk=3;
if(sum >=19) sigk=2;
if(sum<=-4 && sum >=-5) sigk=-3;
if(sum<=-19) sigk=-2;
return(sigk);
}
Cindibox_h.mqh
#property copyright "Copyright 2010, bighope"
#property link "http://expertadviser-bighope.blogspot.com/"
struct Custom_date {
datetime time;
double open;
double close;
double hi;
double lw;
Custom_date() {time=0; open=0.0; close=0.0;hi=0.0;lw=0.0;}
};
struct HL_date{
double av;
double wid;
HL_date(){av=0.0;wid=0.0;}
};
struct Custom_Ddate {
datetime time;
double main;
double max;
double min;
double avmax;
double avmin;
Custom_Ddate() {time=0; max=0.0; min=0.0; avmax=0.0; avmin=0.0;}
};
struct Custom_MA {
double megal;
double mega;
double longrange;
double shortrange;
Custom_MA() {megal=0.0; mega=0.0;longrange=0.0;shortrange=0.0;}
};
class Cindibox_h
{
protected:
string symbl;
ENUM_TIMEFRAMES timeframes;
int range;
int Hrange;
int Drange;
int Prange;
int Mrange;
int HLrange;
int digit;
int DeMarker_Period;
MqlRates price[];
double phi[];
double plw[];
datetime bartimenow;
int bufindex;
bool ON_Heiken;
bool ON_DeMark;
bool ON_MA;
int prev_calculated[];
Custom_date Heiken[];
Custom_Ddate DeMarker[];
double MSalfa;
double MLalfa;
double MMalfa;
double MMLalfa;
Custom_MA MA[];
datetime frametime(ENUM_TIMEFRAMES timef);
datetime Shiftime(datetime time);
datetime Shiftimeon(datetime time);
int ZeroIndex(const int index,const int ranges);
int Run_HeikenAshi(const int index);
int Run_DeMarker(const int index);
int Run_Ma(const int index);
double Run_Sigmoid(const double alfa,const double pricec ,const double EMA);
public:
void Cindibox_h();
bool Set_Base(const string symb,const ENUM_TIMEFRAMES timeframe,const int digis);
bool Set_Heiken();
bool Set_DeMarker(const int periods);
int DeMarker_Period(const int index);
void Set_Ma(const double MLLalfa,const double Malfa,const double Lalfa,const double Salfa);
int Run(const datetime nowtime);
Custom_Ddate Get_DeMarker(const int index);
Custom_date Get_HeikenAshi(const int index);
MqlRates Get_price(const int index);
Custom_MA Get_Ma(const int index);
HL_date Get_HL();
};
void Cindibox_h::Cindibox_h(void){
range=10;
Hrange=6;
Drange=50;
Prange=10;
Mrange=30;
HLrange = 80;
ON_DeMark=false;
ON_Heiken=false;
ON_MA=false;
bartimenow = 0;
bufindex=0;
ZeroMemory(prev_calculated);
ArrayResize(prev_calculated,4);
prev_calculated[0]=0;
prev_calculated[1]=0;
prev_calculated[2]=0;
prev_calculated[3]=0;
ZeroMemory(price);
ArrayResize(price,range);
ArrayResize(phi,HLrange);
ArrayResize(plw,HLrange);
}
bool Cindibox_h::Set_Base(const string symb,const ENUM_TIMEFRAMES timeframe,const int digis){
symbl = symb;
timeframes = timeframe;
digit = digis;
if(symbl != symb || timeframes != timeframe || digit != digis)return(false);
return(true);
}
bool Cindibox_h::Set_Heiken(void){
ZeroMemory(Heiken);
ArrayResize(Heiken,Hrange);
ON_Heiken=true;
return(true);
}
bool Cindibox_h::Set_DeMarker(const int periods){
DeMarker_Period = periods;
ArrayResize(DeMarker,Drange);
ON_DeMark=true;
if(DeMarker_Period != periods)return(false);
return(true);
}
void Cindibox_h::Set_Ma(const double MLLalfa,const double Malfa,const double Lalfa,const double Salfa){
MMLalfa = MLLalfa;
MMalfa = Malfa;
MLalfa = Lalfa;
MSalfa = Salfa;
ON_MA=true;
ArrayResize(MA,Mrange);
}
datetime Cindibox_h::frametime(ENUM_TIMEFRAMES timef){
switch(timef){
case PERIOD_M1: return(1);
case PERIOD_M5: return(5);
case PERIOD_M10: return(10);
case PERIOD_M15: return(15);
case PERIOD_M30: return(30);
case PERIOD_H1: return(60);
case PERIOD_H4: return(240);
default : return(15);
}
}
datetime Cindibox_h::Shiftime(datetime time){
datetime startime;
int rates,i=0;
startime=time-frametime(timeframes)*60*(range-1);
datetime getbars[];
do{
do{
if(i>0)Sleep(500);
i++;
rates = CopyTime(symbl,timeframes,(datetime)startime,(datetime)time,getbars);
if(rates==range)break;
}while(i<5);
if(rates!=range){startime-=(datetime)frametime(timeframes)*60; i=1;}
}while(rates < range);
return(startime);
}
datetime Cindibox_h::Shiftimeon(datetime time){
datetime getbar[1];
datetime startime;
int rates,i=0;
startime=time-frametime(timeframes)*60;
do{
do{
if(i>0)Sleep(500);
i++;
rates = CopyTime(symbl,timeframes,(datetime)startime,(int)1,getbar);
if(rates>0)break;
}while(i<5);
if(rates<1){startime-=(datetime)frametime(timeframes)*60;i=1;}
}while(rates!=1);
return(startime);
}
int Cindibox_h::ZeroIndex(const int index,const int ranges){
int q=(index%ranges);
int i=ranges-1-(int)MathAbs(q);
return(i);
}
double Cindibox_h::Run_Sigmoid(const double alfa,const double pricec,const double EMA){
double away=0.0;
away=MathAbs(pricec - EMA)* MathPow(10,digit);
away = -7+away*alfa;
return((1/(1+MathExp(-away))));
}
int Cindibox_h::Run(const datetime nowtime){
MqlRates Sprice[1];
int zero=0,befo=0,hlzero=0;
int rates;
datetime startime=nowtime;
if(bufindex==0)startime=Shiftime(nowtime);
do{
rates = CopyRates(symbl,timeframes,(datetime)startime,(int)1,Sprice);
if(rates>0){
if(Sprice[0].time != bartimenow){
bartimenow = Sprice[0].time;
bufindex++;
}
zero=ZeroIndex(bufindex,range);
hlzero = ZeroIndex(bufindex,HLrange);
price[zero] = Sprice[0];
phi[hlzero] = price[zero].high;
plw[hlzero] = price[zero].low;
if(MLalfa>0 && MSalfa>0 && ON_MA==true)Run_Ma(bufindex);
if(ON_Heiken==true) Run_HeikenAshi(bufindex);
if(ON_DeMark==true) Run_DeMarker(bufindex);
startime=Shiftimeon(startime);
befo = ZeroIndex(bufindex+1,range);
}
} while(price[befo].tick_volume<=0);
return(bufindex);
}
int Cindibox_h::Run_HeikenAshi(const int index){
int i=ZeroIndex(index,Hrange);
int bef=ZeroIndex(index-(int)1,Hrange);
int pi = ZeroIndex(index,range);
if(prev_calculated[1]==0){
Heiken[i].open = price[pi].open;
Heiken[i].close = price[pi].close;
Heiken[i].hi = price[pi].high;
Heiken[i].close = price[pi].low;
} else {
Heiken[i].open = NormalizeDouble((Heiken[bef].open+Heiken[bef].close)/2,digit);
Heiken[i].close = NormalizeDouble((price[pi].open+price[pi].high+price[pi].low+price[pi].close)/4,digit);
Heiken[i].hi = NormalizeDouble(MathMax(price[pi].high,MathMax(Heiken[i].open,Heiken[i].close)),digit);
Heiken[i].lw = NormalizeDouble(MathMin(price[pi].low,MathMin(Heiken[i].open,Heiken[i].close)),digit);
}
Heiken[i].time=price[pi].time;
prev_calculated[1]++;
return(prev_calculated[1]);
}
int Cindibox_h::Run_Ma(const int index){
int i=ZeroIndex(index,Mrange);
int bef=ZeroIndex(index-(int)1,Mrange);
int pi = ZeroIndex(index,range);
double calfa=0;
double Median =0.0;
if(prev_calculated[0]==0){
double Eprice[];
double MLEMA=0,MEMA=0,LEMA=0,SEMA=0;
int count=0,cbar=1000;
do{
count = CopyClose(symbl,timeframes,price[pi].time,(int)cbar,Eprice);
if(count<1)Sleep(1000);
}while(count<1);
MLEMA=Eprice[0];
MEMA=Eprice[0];
LEMA=Eprice[0];
SEMA=Eprice[0];
for(int t=1;t<count;t++){
calfa= Run_Sigmoid(MMLalfa,Eprice[t],MLEMA);
MLEMA = calfa*Eprice[t]+(1-calfa)*MLEMA;
calfa= Run_Sigmoid(MMalfa,Eprice[t],MEMA);
MEMA = calfa*Eprice[t]+(1-calfa)*MEMA;
calfa= Run_Sigmoid(MLalfa,Eprice[t],LEMA);
LEMA = calfa*Eprice[t]+(1-calfa)*LEMA;
calfa= Run_Sigmoid(MSalfa,Eprice[t],SEMA);
SEMA = calfa*Eprice[t]+(1-calfa)*SEMA;
}
MA[i].megal = MLEMA;
MA[i].mega = MEMA;
MA[i].longrange = LEMA;
MA[i].shortrange = SEMA;
}else{
Median = (price[pi].open + price[pi].high + price[pi].low + price[pi].close)/4;
calfa= Run_Sigmoid(MMLalfa,Median,MA[bef].megal);
MA[i].megal= NormalizeDouble(calfa*Median+(1-calfa)*MA[bef].megal,digit);
calfa= Run_Sigmoid(MMalfa,Median,MA[bef].mega);
MA[i].mega= NormalizeDouble(calfa*Median+(1-calfa)*MA[bef].mega,digit);
calfa = Run_Sigmoid(MLalfa,Median,MA[bef].longrange);
MA[i].longrange= NormalizeDouble(calfa*Median+(1-calfa)*MA[bef].longrange,digit);
calfa = Run_Sigmoid(MSalfa,Median,MA[bef].shortrange);
MA[i].shortrange= NormalizeDouble(calfa*Median+(1-calfa)*MA[bef].shortrange,digit);
}
prev_calculated[0]++;
return(prev_calculated[0]);
}
int Cindibox_h::Run_DeMarker(const int index){
int i=ZeroIndex(index,Drange);
int bef=ZeroIndex(index-(int)1,Drange);
int pi = ZeroIndex(index,range);
int pbef=ZeroIndex(index-(int)1,range);
int k,z;
double maxsum=0.0,minsum=0.0,dNum=0.0;
if(prev_calculated[2]==0){
DeMarker[i].max=0.0;
DeMarker[i].min=0.0;
}else if(prev_calculated[2]>0 && prev_calculated[2]<DeMarker_Period){
if(price[pi].high>price[pbef].high)DeMarker[i].max=price[pi].high-price[pbef].high;
else DeMarker[i].max = 0.0;
if(price[pbef].low>price[pi].low)DeMarker[i].min=price[pbef].low-price[pi].low;
else DeMarker[i].min = 0.0;
}else{
if(price[pi].high>price[pbef].high)DeMarker[i].max=price[pi].high-price[pbef].high;
else DeMarker[i].max = 0.0;
if(price[pbef].low>price[pi].low)DeMarker[i].min=price[pbef].low-price[pi].low;
else DeMarker[i].min = 0.0;
for(k=0;k<DeMarker_Period;k++){
z=ZeroIndex(index-k,Drange);
maxsum+=DeMarker[z].max;
minsum+=DeMarker[z].min;
}
DeMarker[i].avmax=maxsum/DeMarker_Period;
DeMarker[i].avmin=minsum/DeMarker_Period;
dNum=DeMarker[i].avmax+DeMarker[i].avmin;
if(dNum!=0) DeMarker[i].main=NormalizeDouble(DeMarker[i].avmax/dNum,digit);
else DeMarker[i].main=0.0;
}
DeMarker[i].time=price[ZeroIndex(index,range)].time;
prev_calculated[2]++;
return(prev_calculated[2]);
}
MqlRates Cindibox_h::Get_price(const int index){
int i=ZeroIndex(bufindex+index,range);
return(price[i]);
}
Custom_Ddate Cindibox_h::Get_DeMarker(const int index){return(DeMarker[ZeroIndex(bufindex+index,Drange)]);}
Custom_date Cindibox_h::Get_HeikenAshi(const int index){return( Heiken[ZeroIndex(bufindex+index,Hrange)]);}
Custom_MA Cindibox_h::Get_Ma(const int index){return(MA[ZeroIndex(bufindex+index,Mrange)]);}
HL_date Cindibox_h::Get_HL(){
double hig,lwg;
HL_date q;
hig = phi[ArrayMaximum(phi)];
lwg = plw[ArrayMinimum(plw)];
q.av = (lwg+hig)/2;
q.wid = hig-lwg;
return(q);
}
こんな感じです。^^;
まとめ
さてさて、いくつバグがあるでしょうか?