编码帮助......我如何让指标过滤而不是警报? - 页 6

 
elihayun:
到目前为止,我还没有看到任何问题(面向代码)。

但从逻辑上看,请看这个

if(isCrossed == 1 && Ask < upLevel)

你不是在检查它们是否接近,只是在检查价格是否低于该线

这就是我想要的......过滤......我想用这一行作为禁止交易的方式。那是我的意图。如果我可以改变线本身的宽度,我不需要做一个方法来查看它是否接近线,我可以直接使用线本身作为限制器。通过改变带子的宽度,它将和有另一个因素来检查它有多接近线一样。通过使之成为进入的条件,它可以过滤或应该阻止买单开仓,除非它们低于顶线,或者卖单开仓,如果它们高于底线

我很困惑,为什么这样做会使它产生订单错误?

 

看来这个错误是由于不恰当的批量大小与MM参数 有关......。

我正在改变我的重点......回到我最初的重点。

我已经得出结论,趋势带指标不会产生我想要的那种过滤效果。它就是不会。

最初我看的是 "ang_AutoCh_HL-v1 "通道指标。我看到它能给我带来我想要的过滤效果,但是它没有可以调用的缓冲区...所以.....。

我可以为对象1和对象2的线值制作缓冲区吗?这样我就可以在EA中使用它们作为支撑和阻力?

这是该指标...

#property copyright "ANG3110@latchess.com"

//----------------------------------

#property indicator_chart_window

//----------------------------------

extern int Hours=24;

extern color col=SkyBlue;

//------------------

double lr,lr0,lrp;

double sx,sy,sxy,sx2,aa,bb;

int p,sName,fs;

int f,f0,f1;

double dh,dl,dh_1,dl_1,dh_2,dl_2;

int ai_1,ai_2,bi_1,bi_2;

double hai,lai,dhi,dli,dhm,dlm,ha0,hap,la0,lap;

double price_p1,price_p0,price_p2,price_01,price_00,price_02;

int p1,p0,p2,fp;

//*****************************************

int init() {

p=Hours*60/Period();

if (fs==0) {sName=CurTime(); fs=1;}

return(0);}

//*******************************

int deinit() {

ObjectDelete("1"+sName);

ObjectDelete("0"+sName);

ObjectDelete("2"+sName); }

//*******************************

int start() {

int i,n;

//------------------------------------------------------------------------------

if (f==1) {

p1=iBarShift(Symbol(),Period(),ObjectGet("1"+sName,OBJPROP_TIME1));

p0=iBarShift(Symbol(),Period(),ObjectGet("0"+sName,OBJPROP_TIME1));

p2=iBarShift(Symbol(),Period(),ObjectGet("2"+sName,OBJPROP_TIME1));

if (fp==0 && p!=p1) {p=p1; fp=1;}

if (fp==0 && p!=p0) {p=p0; fp=1;}

if (fp==0 && p!=p2) {p=p2; fp=1;}

}

//====================================================

sx=0; sy=0; sxy=0; sx2=0;

for (n=0; n<=p; n++) {sx+=n; sy+=Close[n]; sxy+=n*Close[n]; sx2+=MathPow(n,2);}

aa=(sx*sy-(p+1)*sxy)/(MathPow(sx,2)-(p+1)*sx2); bb=(sy-aa*sx)/(p+1);

//----------------------------------------------------

for (i=0; i<=p; i++) {

lr=bb+aa*i;

dh=High-lr; dl=Low-lr;

//----------------------------------------------------

if (i<p/2) {if (i==0) {dh_1=0.0; dl_1=0.0; ai_1=i; bi_1=i;}

if (dh>=dh_1) {dh_1=dh; ai_1=i;}

if (dl<=dl_1) {dl_1=dl; bi_1=i;}}

//----------------------------------------------------

if (i>=p/2) {if (i==p/2) {dh_2=0.0; dl_2=0.0; ai_2=i; bi_2=i;}

if (dh>=dh_2) {dh_2=dh; ai_2=i;}

if (dl<=dl_2) {dl_2=dl; bi_2=i;}}}

//-------------------------------------

lr0=bb; lrp=bb+aa*(i+p);

//===================================================

if (MathAbs(ai_1-ai_2)>MathAbs(bi_1-bi_2)) f=1;

if (MathAbs(ai_1-ai_2)<MathAbs(bi_1-bi_2)) f=2;

if (MathAbs(ai_1-ai_2)==MathAbs(bi_1-bi_2)) {if (MathAbs(dh_1-dh_2)=MathAbs(dl_1-dl_2)) f=2;}

//=================================================

if (f==1) {

for (n=0; n<=20; n++) { f1=0;

for (i=0; i<=p; i++) {hai=High[ai_1]*(i-ai_2)/(ai_1-ai_2)+High[ai_2]*(i-ai_1)/(ai_2-ai_1);

if (i==0 || i==p/2) dhm=0.0;

if (High-hai>dhm && i<p/2) {ai_1=i; f1=1;}

if (High-hai>dhm && i>=p/2) {ai_2=i; f1=1;} }

if (f==0) break;}

//----------------------------

for (i=0; i<=p; i++) {hai=High[ai_1]*(i-ai_2)/(ai_1-ai_2)+High[ai_2]*(i-ai_1)/(ai_2-ai_1);

dli=Low-hai;

if (i==0) dlm=0.0; if (dli<dlm) dlm=dli;}

ha0=High[ai_1]*(0-ai_2)/(ai_1-ai_2)+High[ai_2]*(0-ai_1)/(ai_2-ai_1);

hap=High[ai_1]*(p-ai_2)/(ai_1-ai_2)+High[ai_2]*(p-ai_1)/(ai_2-ai_1);

//----------------------------

price_p1=hap;

price_p0=hap+dlm/2;

price_p2=hap+dlm;

price_01=ha0;

price_00=ha0+dlm/2;

price_02=ha0+dlm;

}

//=================================================

if (f==2) {

for (n=0; n<=20; n++) { f1=0;

for (i=0; i<=p; i++) {lai=Low*(i-bi_2)/(bi_1-bi_2)+Low*(i-bi_1)/(bi_2-bi_1);

if (i==0 || i==p/2) dlm=0.0;

if (Low-lai<dlm && i<p/2) {bi_1=i; f1=1;}

if (Low-lai=p/2) {bi_2=i; f1=1;}}

if (f==0) break;}

//----------------------------

for (i=0; i<=p; i++) {lai=Low*(i-bi_2)/(bi_1-bi_2)+Low*(i-bi_1)/(bi_2-bi_1);

dhi=High-lai;

if (i==0) dhm=0.0; if (dhi>dhm) dhm=dhi;}

la0=Low*(0-bi_2)/(bi_1-bi_2)+Low*(0-bi_1)/(bi_2-bi_1);

lap=Low*(p-bi_2)/(bi_1-bi_2)+Low*(p-bi_1)/(bi_2-bi_1);

//----------------------------------------------------------------

price_p1=lap;

price_p0=lap+dhm/2;

price_p2=lap+dhm;

price_01=la0;

price_00=la0+dhm/2;

price_02=la0+dhm;

}

//===================================================================================

ObjectCreate("1"+sName,2, 0,Time[p],price_p1,Time[0],price_01);

ObjectCreate("0"+sName,2, 0,Time[p],price_p0,Time[0],price_00);

ObjectCreate("2"+sName,2, 0,Time[p],price_p2,Time[0],price_02);

//-----------------------------------------------------------------

ObjectSet("1"+sName,OBJPROP_COLOR,col);

ObjectSet("0"+sName,OBJPROP_COLOR,col);

ObjectSet("0"+sName,OBJPROP_STYLE,STYLE_DOT);

ObjectSet("2"+sName,OBJPROP_COLOR,col);

//---------------------------------------------

ObjectSet("1"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("1"+sName,OBJPROP_PRICE1,price_p1);

ObjectSet("1"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("1"+sName,OBJPROP_PRICE2,price_01);

ObjectSet("0"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("0"+sName,OBJPROP_PRICE1,price_p0);

ObjectSet("0"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("0"+sName,OBJPROP_PRICE2,price_00);

ObjectSet("2"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("2"+sName,OBJPROP_PRICE1,price_p2);

ObjectSet("2"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("2"+sName,OBJPROP_PRICE2,price_02);

//==================================================================

f=1; p1=p; p0=p; p2=p; fp=0;

//*************************************************************************************

return(0);}

//=====================================================================================[/PHP]

here is what I'm trying to add a buffer so I can extract the values I need...

#property copyright "ANG3110@latchess.com"

//----------------------------------

#property indicator_chart_window

//----------------------------------

extern int Hours=24;

extern color col=SkyBlue;

//------------------

double ExtBufferResistance[];

double ExtBufferMiddle[];

double ExtBufferSupport[];

double lr,lr0,lrp;

double sx,sy,sxy,sx2,aa,bb;

int p,sName,fs;

int f,f0,f1;

double dh,dl,dh_1,dl_1,dh_2,dl_2;

int ai_1,ai_2,bi_1,bi_2;

double hai,lai,dhi,dli,dhm,dlm,ha0,hap,la0,lap;

double price_p1,price_p0,price_p2,price_01,price_00,price_02;

int p1,p0,p2,fp;

//*****************************************

int init() {

p=Hours*60/Period();

if (fs==0) {sName=CurTime(); fs=1;}

SetIndexBuffer (4, ExtBufferResistance); //--resistance line

SetIndexBuffer (5, ExtBufferMiddle); //--middle line

SetIndexBuffer (6, ExtBufferSupport); //--support line

return(0);}

//*******************************

//===================================================================================

ObjectCreate("1"+sName,2, 0,Time[p],price_p1,Time[0],price_01);

ObjectCreate("0"+sName,2, 0,Time[p],price_p0,Time[0],price_00);

ObjectCreate("2"+sName,2, 0,Time[p],price_p2,Time[0],price_02);

//------------------make indicator buffer for EA-------------------------------------

somehow get object 1 to put it's value into buffer 4

somehow get object 0 to put it's value into buffer 5

somehow get object 2 to put it's value into buffer 6

//------------------------draw chart-------------------------------------------------

[/php]

and then upgrade this EA....

[PHP]#property copyright "Copyright 2005, Chris Battles."

#property link "cbattles@neo.rr.com"

extern double TrailingStop = 5;

extern double TrailingStopTrigger = 19;

extern double StopLoss = 186;

extern double TakeProfit = 250;

extern double Lots = 0.4;

//---- ang_AutoCh_HL-v1 and Filter Parameters

extern int Hours=24;

extern color col=SkyBlue;

extern double TF = 30; //--which bar period for the custom indicator to use

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

int start(){

int cnt, ticket;

if(Bars<100){

Print("bars less than 100");

return(0);

}

double ema1a=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0);

double ema2a=iMA(NULL,0,144,0,MODE_EMA,PRICE_CLOSE,0);

double ema3a=iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0);

double ema1b=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,1);

double ema2b=iMA(NULL,0,144,0,MODE_EMA,PRICE_CLOSE,1);

double ema3b=iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,1);

//----------channel filter

double resistance = iCustom(NULL,TF, "ang_AutoCh_HL-v1", Hours, col, 4, 0);

double support = iCustom(NULL,TF, "ang_AutoCh_HL-v1", Hours, col, 6, 0);

//--- end channel filter

and then make the order logic have second condition for entry...

[PHP]if (ema3bema1a && Ask < resistance){

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point, NULL,16384,0,Green);

if(ticket>0){

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if (ema3b>ema1b && ema3a support){

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point, NULL,16384,0,Red);

if(ticket>0) {

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

我的症结在于如何将数值从指标中取出来,以便EA能够使用它们......我想如果你能告诉我如何将数值从指标中取出来输入EA,我可以处理其余的问题。

 

我真的不知道我在用缓冲区做什么。我把setbuffer这一行扔进去,我甚至不知道这是否有必要或什么

 
raff1410:
嗨...

带缓冲区的指示器。

你可以像下面这样调用res && sup。

double resistance = iCustom(NULL,TF, "Channel",24,col,0,0);

double support = iCustom(NULL,TF, "Channel",24,col,2,0);

拉夫

哦,伙计,看!!这就是我所说的....,我几乎等不及要试一试,看看它是否能工作。

现在我必须把这些东西放在EA的顶部吗?告诉指标使用什么设置?

//---- 通道和过滤器参数

extern int Hours=24;

extern color col=SkyBlue;

extern double TF = 30; //--自定义指标 要使用的条形周期

然后...

double resistance = iCustom(NULL,TF, "Channel",Hours,col,0,0)。

double support = iCustom(NULL,TF, "Channel",Hours,col,2,0)。

 

好吧,我又收到了这个错误130,这又是什么?

哦,是的,止损 太近了...好吧...

 

你好...

有缓冲区的Indycator。

channel.mq4

你可以像下面这样调用res && sup。

double resistance = iCustom(NULL,TF, "Channel",24,col,0,0)。

double support = iCustom(NULL,TF, "Channel",24,col,2,0);

拉夫

附加的文件:
channel.mq4  6 kb
 

新问题...

我有几个版本的止损操作......跌幅来自于追踪止损触发器的失败。当它不参与时,回落的 "股票止损 "是关闭头寸的原因,这就是伤害...。

我可以从许多小规模的下跌中看到,当追踪止损被触发时,它对账户的权益损害几乎没有那么大。它可以承受很多这样的损失,并把它们补回来,但它不能克服股票止损点关闭带来的较大损失。

so....

如果开盘后的条形图没有移动到足以使用追踪止损,有什么办法可以关闭头寸吗?

我已经开始研究这个问题了,现在从移动平均线 上调用当前的时期以及之前的三个时期。基本上我的想法是,信号和一个条形确认可以从当前之前的三个时期中产生,而当前的时期可以用来看它现在是否移动到足以触发追踪止损。我认为这个条件可以作为一个||或条件添加到关闭所有未平仓订单的股票止损中。

让我感到困惑的是,如何判断它是否移动到足以触发移动止损的程度,这取决于如果它是做多,它必须向上移动,但如果它是做空,它必须向下移动。因此,追踪止损触发检测必须注意它是一个多头还是一个空头头寸,以便知道以何种方式移动来触发。我不知道如何让它检测到这一点。

我可以想象,这份报告中的大跌幅看起来并不比小跌幅大,如果是这样的话,那么它就可以盈利了。

附加的文件:
whatever2.htm  292 kb
whatever2.gif  6 kb
 

需要再做一个调整...

这是在亏损头寸变大之前平仓......它也是在赢利头寸变大之前平仓

它需要做的是,只有在前十分钟没有移动到足以触发追踪止损的位置时才会平仓......我认为它只需要移动1个点就可以了......所以我对前十分钟的要求不高。真的,我只想确保它不会在开仓后立即掉头,并回到仓位上。这些都是失去....

所以....,如果可以让它检测到追踪止损是否被触发,如果是的话,就让它运行!!让追踪止损关闭它,而不是作为时间的函数 关闭。时间平仓参数并不意味着是主要的平仓策略,它只是为了处理平仓,直到移动止损接管。

附加的文件:
whatever3.htm  304 kb
whatever3.gif  6 kb
 

这不是我想做的事......我无法理解这些结果。

https://c.mql5.com/forextsd/forum/9/whatever3.htm

只是看了一下,大多数东西都只开了10分钟或更少(如果不符合标准,我设置它在10分钟内关闭),只有极少数例外,如52号订单开了19分钟,48号开了15分钟。

这一部分不工作...OrderType()==OP_BUY && Bid-Profit<OrderOpenPrice()

如果(OrderSymbol()==Symbol() && OrderType()==OP_SELL && Bid+Profit>OrderOpenPrice())

我们需要检查的是追踪止损是否已经触发。我不希望它根据价格来关闭。我希望它能在移动止损没有被触发的情况下关闭。我知道我原来说过,我们需要检查它是否上涨到足以触发移动止损......但我不完全理解移动止损的触发代码,也不知道那是多远的距离......我不知道这是否一直重复检查,甚至在指定的时间间隔之后,如果/当出价+利润的标准是订单打开价格时,会在15或19分钟关闭它?这是在使自己成为主要的平仓标准,而不是止损标准,直到触发追踪止损......这就是它看起来的情况。

//+------------------------------------------------------------------+

void CloseOrder()

{

double Profit=ThresholdMove*Point;

int total = OrdersTotal();

for (int cnt = 0 ; cnt < total ; cnt++)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if ((CurTime()-OrderOpenTime())>MonitorInMinutes*60*MinsMultiplier)

{

if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && Bid-Profit<OrderOpenPrice() )

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);

}

if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && Bid+Profit>OrderOpenPrice())

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);

}

}

}

}

//+------------------------------------------------------------------+[/PHP]

Somewhere in this closing strategy there must be a way to detect if it's been triggered or not...

[PHP]//+------------------------------------------------------------------+

//| Variable End |

//+------------------------------------------------------------------+

//Check position

bool IsTrade = False;

for (int i = 0; i < Total; i ++) {

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {

IsTrade = True;

if(OrderType() == OP_BUY) {

//Close

//+------------------------------------------------------------------+

//| Signal Begin(Exit Buy) |

//+------------------------------------------------------------------+

if (CloseBuy1_1 == CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

//+------------------------------------------------------------------+

//| Signal End(Exit Buy) |

//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

continue;

}

//Trailing stop

if(TrailingStopMode && TrailingStop > 0) {

if(Bid - OrderOpenPrice() > Point * TrailingStop) {

if(OrderStopLoss() < Bid - Point * TrailingStop) {

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

} else {

//Close

//+------------------------------------------------------------------+

//| Signal Begin(Exit Sell) |

//+------------------------------------------------------------------+

if (CloseSell1_1 == CloseSell1_2) Order = SIGNAL_CLOSESELL;

//+------------------------------------------------------------------+

//| Signal End(Exit Sell) |

//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

continue;

}

//Trailing stop

if(TrailingStopMode && TrailingStop > 0) {

if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {

if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {

OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

}

}

}

底线是,除非可以修改参数以达到预期的效果,否则定时关闭参数过于激进。

 

对不起,我没有时间检查整个代码,但让我们只检查这个片段。

if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && Bid+Profit>OrderOpenPrice()

让我们说,OrderOpenPrice = 1.2100

而利润是0.0010

因此,如果买入价小于或等于1.2100-0.0010=1.2090,你想关闭空头交易。

让我们假设有一个向下的缺口,价格跳过了1.2090,现在的买入价格是1.2088。根据你的公式。

Bid + Profit = 1.2088 + 0.0010 = 1.2098。即使您的系统已经超过了利润阈值,它也不比OrderOpenPrice大。因此,订单将不会被关闭。在我看来,平仓条件的逻辑需要被重新评估和重新编写。另外,在处理空头交易时,你应该处理问价,因为你只能 在问价时平仓

还有一点建议。

for (int cnt = 0 ; cnt = 0; cnt--) 的计数循环或类似的东西。

祝您好运。