อ้างจาก: iRuler ที่ 25, มีนาคม 2018, 08:40:26 AM
ต้องมี source code .mq4 ครับถึงจะแก้ได้
อันนี้เปล่าครับ
----------------------------------------------------------------------------------------------------------------------------------------------------------
//+------------------------------------------------------------------+
//| SupDem_mq4 |
//| Copyright ฉ 2008, MetaQuotes Software Corp_ |
//| http://www_metaquotes_net |
//+------------------------------------------------------------------+
#property copyright "Copyright ฉ 2008, MetaQuotes Software Corp_"
#property link "http://www_metaquotes_net"
#property indicator_chart_window
#property indicator_buffers 2
extern int forced_tf = 0;
extern bool use_narrow_bands = true;
extern bool kill_retouch = true;
extern color TopColor = C'152,112,101';
extern color BotColor = C'109,105,143';
extern int Price_Width = 1;
extern bool DrawPriceLabels = false;
extern double Aaa =0;
double BuferUp[];
double BuferDn[];
double iPeriod=13;
int Dev=8;
int Step=5;
datetime t1,t2;
double p1,p2;
string pair;
double point;
int digits;
int tf;
string TAG;
double up_cur,dn_cur;
int init()
{
SetIndexBuffer(1,BuferUp);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(1,DRAW_NONE);
SetIndexBuffer(0,BuferDn);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(0,DRAW_NONE);
if(forced_tf != 0) tf = forced_tf;
else tf = Period();
point = Point;
digits = Digits;
if(digits == 3 || digits == 5) point*=10;
TAG = "II_SupDem"+tf;
return(0);
}
int deinit()
{
ObDeleteObjectsByPrefix(TAG);
Comment("");
return(0);
}
int start()
{
if(NewBar()==true)
{
CountZZ(BuferUp,BuferDn,iPeriod,Dev,Step);
GetValid();
Draw();
}
return(0);
}
void Draw()
{
int i;
string s;
ObDeleteObjectsByPrefix(TAG);
for(i=0;i<iBars(pair,tf);i++)
{
if(BuferDn
> 0.0)
{
t1 = iTime(pair,tf,i);
t2 = Time[0];
if(use_narrow_bands) p2 = MathMax(iClose(pair,tf,i),iOpen(pair,tf,i));
else p2 = MathMin(iClose(pair,tf,i),iOpen(pair,tf,i));
p2 = MathMax(p2,MathMax(iLow(pair,tf,i-1),iLow(pair,tf,i+1)));
if (DrawPriceLabels)
{
s = TAG+"UPAR"+tf+i;
ObjectCreate(s,OBJ_ARROW,0,0,0);
ObjectSet(s,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(s, OBJPROP_TIME1, t2);
ObjectSet(s, OBJPROP_PRICE1, p2);
ObjectSet(s,OBJPROP_COLOR,TopColor);
ObjectSet(s,OBJPROP_WIDTH,Price_Width);
}
s = TAG+"UPFILL"+tf+i;
ObjectCreate(s,OBJ_RECTANGLE,0,0,0,0,0);
ObjectSet(s,OBJPROP_TIME1,t1);
ObjectSet(s,OBJPROP_PRICE1,BuferDn);
ObjectSet(s,OBJPROP_TIME2,t2);
ObjectSet(s,OBJPROP_PRICE2,p2);
ObjectSet(s,OBJPROP_COLOR,TopColor);
}
if(BuferUp > 0.0)
{
t1 = iTime(pair,tf,i);
t2 = Time[0];
if(use_narrow_bands) p2 = MathMin(iClose(pair,tf,i),iOpen(pair,tf,i));
else p2 = MathMax(iClose(pair,tf,i),iOpen(pair,tf,i));
if(i>0) p2 = MathMin(p2,MathMin(iHigh(pair,tf,i+1),iHigh(pair,tf,i-1)));
if (DrawPriceLabels)
{
s = TAG+"DNAR"+tf+i;
ObjectCreate(s,OBJ_ARROW,0,0,0);
ObjectSet(s,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(s, OBJPROP_TIME1, t2);
ObjectSet(s, OBJPROP_PRICE1, p2);
ObjectSet(s,OBJPROP_COLOR,BotColor);
ObjectSet(s,OBJPROP_WIDTH,Price_Width);
}
s = TAG+"DNFILL"+tf+i;
ObjectCreate(s,OBJ_RECTANGLE,0,0,0,0,0);
ObjectSet(s,OBJPROP_TIME1,t1);
ObjectSet(s,OBJPROP_PRICE1,p2);
ObjectSet(s,OBJPROP_TIME2,t2);
ObjectSet(s,OBJPROP_PRICE2,BuferUp);
ObjectSet(s,OBJPROP_COLOR,BotColor);
}
}
}
bool NewBar() {
static datetime LastTime = 0;
if (iTime(pair,tf,0) != LastTime) {
LastTime = iTime(pair,tf,0);
return (true);
} else
return (false);
}
void ObDeleteObjectsByPrefix(string Prefix)
{
int L = StringLen(Prefix);
int i = 0;
while(i < ObjectsTotal())
{
string ObjName = ObjectName(i);
if(StringSubstr(ObjName, 0, L) != Prefix)
{
i++;
continue;
}
ObjectDelete(ObjName);
}
}
int CountZZ( double& ExtMapBuffer[], double& ExtMapBuffer2[], int ExtDepth, int ExtDeviation, int ExtBackstep )
{
int shift, back,lasthighpos,lastlowpos;
double val,res;
double curlow,curhigh,lasthigh,lastlow;
int count = iBars(pair,tf)-ExtDepth;
for(shift=count; shift>=0; shift--)
{
val = iLow(pair,tf,iLowest(pair,tf,MODE_LOW,ExtDepth,shift));
if(val==lastlow) val=0.0;
else
{
lastlow=val;
if((iLow(pair,tf,shift)-val)>(ExtDeviation*point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=ExtMapBuffer[shift+back];
if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0;
}
}
}
ExtMapBuffer[shift]=val;
//--- high
val=iHigh(pair,tf,iHighest(pair,tf,MODE_HIGH,ExtDepth,shift));
if(val==lasthigh) val=0.0;
else
{
lasthigh=val;
if((val-iHigh(pair,tf,shift))>(ExtDeviation*point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=ExtMapBuffer2[shift+back];
if((res!=0)&&(res<val)) ExtMapBuffer2[shift+back]=0.0;
}
}
}
ExtMapBuffer2[shift]=val;
}
// final cutting
lasthigh=-1; lasthighpos=-1;
lastlow=-1; lastlowpos=-1;
for(shift=count; shift>=0; shift--)
{
curlow=ExtMapBuffer[shift];
curhigh=ExtMapBuffer2[shift];
if((curlow==0)&&(curhigh==0)) continue;
//---
if(curhigh!=0)
{
if(lasthigh>0)
{
if(lasthigh<curhigh) ExtMapBuffer2[lasthighpos]=0;
else ExtMapBuffer2[shift]=0;
}
//---
if(lasthigh<curhigh || lasthigh<0)
{
lasthigh=curhigh;
lasthighpos=shift;
}
lastlow=-1;
}
//----
if(curlow!=0)
{
if(lastlow>0)
{
if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0;
else ExtMapBuffer[shift]=0;
}
//---
if((curlow<lastlow)||(lastlow<0))
{
lastlow=curlow;
lastlowpos=shift;
}
lasthigh=-1;
}
}
for(shift=iBars(pair,tf)-1; shift>=0; shift--)
{
if(shift>=count) ExtMapBuffer[shift]=0.0;
else
{
res=ExtMapBuffer2[shift];
if(res!=0.0) ExtMapBuffer2[shift]=res;
}
}
}
void GetValid()
{
up_cur = 0;
int upbar = 0;
dn_cur = 0;
int dnbar = 0;
double cur_hi = 0;
double cur_lo = 0;
double last_up = 0;
double last_dn = 0;
double low_dn = 0;
double hi_up = 0;
int i;
for(i=0;i<iBars(pair,tf);i++)
{
if(BuferUp > 0)
{
up_cur = BuferUp;
cur_lo = BuferUp;
last_up = cur_lo;
break;
}
}
for(i=0;i<iBars(pair,tf);i++)
{
if(BuferDn > 0)
{
dn_cur = BuferDn;
cur_hi = BuferDn;
last_dn = cur_hi;
break;
}
}
for(i=0;i<iBars(pair,tf);i++) // remove higher lows and lower highs
{
if(BuferDn >= last_dn)
{
last_dn = BuferDn;
dnbar = i;
}
else BuferDn = 0.0;
if(BuferDn <= dn_cur && BuferUp > 0.0) BuferDn = 0.0;
if(BuferUp <= last_up && BuferUp > 0)
{
last_up = BuferUp;
upbar = i;
}
else BuferUp = 0.0;
if(BuferUp > up_cur) BuferUp = 0.0;
}
if(kill_retouch)
{
if(use_narrow_bands)
{
low_dn = MathMax(iOpen(pair,tf,dnbar),iClose(pair,tf,dnbar));
hi_up = MathMin(iOpen(pair,tf,upbar),iClose(pair,tf,upbar));
}
else
{
low_dn = MathMin(iOpen(pair,tf,dnbar),iClose(pair,tf,dnbar));
hi_up = MathMax(iOpen(pair,tf,upbar),iClose(pair,tf,upbar));
}
for(i=MathMax(upbar,dnbar);i>=0;i--) // work back to zero and remove reentries into s/d
{
if(BuferDn > low_dn && BuferDn != last_dn) BuferDn = 0.0;
else if(use_narrow_bands && BuferDn > 0)
{
low_dn = MathMax(iOpen(pair,tf,i),iClose(pair,tf,i));
last_dn = BuferDn;
}
else if(BuferDn > 0)
{
low_dn = MathMin(iOpen(pair,tf,i),iClose(pair,tf,i));
last_dn = BuferDn;
}
if(BuferUp <= hi_up && BuferUp > 0 && BuferUp != last_up) BuferUp = 0.0;
else if(use_narrow_bands && BuferUp > 0)
{
hi_up = MathMin(iOpen(pair,tf,i),iClose(pair,tf,i));
last_up = BuferUp;
}
else if(BuferUp > 0)
{
hi_up = MathMax(iOpen(pair,tf,i),iClose(pair,tf,i));
last_up = BuferUp;
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
มันจะต้องไปแก้ไขตรงไหนได้บ้างครับ