void OpenBuyOrder( double StopLoss, double TakeProfit )
{
int Ticket;double SL,TP,SLP,TPP,OPP;
if(HideSL==false && StopLoss>0){SL=Ask-StopLoss*Point;}
else {SL=0;}
if(SL>0 && SL>(Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)){SL=Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;}
if(HideTP==false && TakeProfit>0){TP=Ask+TakeProfit*Point;}
else {TP=0;}
Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,EAName,Magic,0,Blue);//-- this stores the value for Ticket, but it never gets used..
//-- you can simply call OrderSend() without storing the result
return; //--- void means the function returns no argument.. thus, no parentheses for return
}
void OpenSellOrder( double StopLoss, double TakeProfit)
{
int Ticket;
double SL,TP,SLP,TPP,OPP;
if(HideSL==false && StopLoss>0){SL=Bid+StopLoss*Point;}
else {SL=0;}
if(SL>0 && SL<(Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)){SL=Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;}
if(HideTP==false && TakeProfit>0){TP=Bid-TakeProfit*Point;}
else {TP=0;/*TPP=0;*/}
Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,EAName,Magic,0,Red);
return;
}
void GetSignal(int MaxBuyOrders, double StopLoss, double TakeProfit) //--- Why make this function a bool??
{
int Op_Buy,Op_Sell,Op_BuyStop,Op_SellStop,Op_BuyLimit,Op_SellLimit;
int total = OrdersTotal();
for(int x=total-1; x>=0; x--)
{
OrderSelect(x, SELECT_BY_POS, MODE_TRADES);
int type = OrderType();
bool result = false; //-- not used anywhere??if (type==OP_BUY) Op_Buy++;
if (type==OP_SELL) Op_Sell++;
if (type==OP_BUYSTOP) Op_BuyStop++;
if (type==OP_SELLSTOP) Op_SellStop++;
}
int limit=1; //--- why define limit to 1
for(int i=1;i<=limit;i++) //--- your for-loop will always run once, in which case why even have a for-loop?
{
double MA1=iMA(NULL,0,100,0,1,0,0);
double MA2=iMA(NULL,0,100,0,1,0,1);
double MA3=iMA(NULL,0,40,0,1,0,0);
double MA4=iMA(NULL,0,40,0,1,0,1);
bool BUY=false; //-- as one guy mentioned better to go with booleans herebool SELL=false;
if(MA1 < MA3 && MA2 > MA4) BUY=true;
if(MA1 > MA3 && MA2 < MA4) SELL=true;
// missed out && total == 0 for nowbool SignalBUY=false;
bool SignalSELL=false;
if(BUY) //-- dont need to write == for bool's ..BUY is same as BUY==true, !BUY same as BUY==falseif(ReverseSystem) SignalSELL=true;
else SignalBUY=true;
if(SELL)
if(ReverseSystem) SignalBUY=true;
else SignalSELL=true;
if (SignalBUY && Op_Buy < MaxBuyOrders ) OpenBuyOrder(StopLoss,TakeProfit); //--- no need to return the return of OpenBuyOrder().. simply calling it will run the code
if (SignalSELL && Op_Sell < MaxSellOrders) OpenSellOrder(StopLoss,TakeProfit);//-- same
}
return;
}
OrderSelect()
if (Buyorder and stoploss < openrice) : we need to trail
if (Sellorder and stoploss > openprice): we need to trail
if (we need to trail):
Modify Stoploss to Currentprice (+ or -) original stoploss
在我去工作之前,有一件事很重要,有一些布尔变量可以是真或假。
我很难相信你是按照书上说的做的。
在我去工作之前,有一件事很重要,有一些布尔变量可以是真或假。
我很难相信你是按照书上说的做的。
我正在努力。我同时在学习交易+程序+MQL。
你只看书就能学会驾驶汽车吗?
但谢谢你
我得到的错误是OpenBuyOrder和OpenSellOrder函数没有返回结果。
我做错了什么?
你得到这个错误是因为OpenBuyOrder()和OpenSellOrder()函数 实际上不返回结果。你把它们定义为void, 意味着它们不返回任何参数,但你却试图返回一个整数(0)。
下面是带有一些评论的代码。
根据你的GetSignal函数,你似乎想用OpenBuy/SellOrder()来打开一个订单,而不是实际返回一些参数。 我用一些注释对你的GetSignal()函数进行了清理
你得到这个错误是因为OpenBuyOrder()和OpenSellOrder()函数实际上不返回结果。你把它们定义为void, 意味着它们不返回任何参数,但你却试图返回一个整数(0)。
下面是带有一些评论的代码。
根据你的GetSignal函数,你似乎想用OpenBuy/SellOrder()来打开一个订单,而不是实际返回一些参数。 我用一些注释对你的GetSignal()函数进行了一些清理
这说明了问题,非常感谢你,我现在正在尝试。
我自己的代码有点乱,因为我基本上是抄袭其他的EA,并试图使其发挥作用。
没问题......如果你遇到其他问题,请随时提问。
我收集了很多跟踪止损的例子,但我需要一个立即开始跟踪,通过-V值到0,然后像收支平衡一样停止。
因此,如果入市价格为100,止损 为100,如果价格移动到+25,跟踪止损移动到-75,然后一旦价格达到100,跟踪止损就停在0,不再移动。
谁能帮我解决这个问题?我已经花了一整天的时间试图让它工作,但我就是做不到。
我想我已经做到了,但我没有,我的追踪止损在0处。
伪装代码。
zzuegg:
如果(Buyorder and stoploss < openrice):我们需要跟踪。
止损 是否总是低于openprice,反之亦然?
我打算最终使用MaxLoss函数,所以我不会在OrderSend中设置止损。
如果Op_Buy
if bid <= OpenOrderPrice()+(Trailing stop value) : trail -- 一旦bid > TSV,就不应该继续移动?
和
如果Op_Sell
If ask >= OpenOrderPrice()-(Trailing stop value): trail ?
然后在高于追踪止损值时,平衡点可以完成工作 ?
zzuegg:
如果(Buyorder and stoploss < openrice):我们需要跟踪。
止损是否总是低于开盘价,反之亦然? 不,只有在盈亏平衡之前
我不认为你的代码有效,似乎你试图做相反的事情......
不,它正在完美地工作。让我检查一下,现在的情况和那个答复中的情况一样。
这是我能得到的最接近的妥协,即关闭移动交易背后的亏损缺口,但仍给它以呼吸空间。在这之前,交易必须达到60点才会发生BE,所以有很多最大止损的交易,这导致我的缩减很高。希望这能改变这种情况。