如何编码? - 页 111

 
MrPip:
当使用OrderComment()来识别交易时要小心。有时经纪人会在评论中添加字符。

最好的办法是使用

如果(StringFind(OrderComment(), UserComment, 0) > 0)

{

//在OrderComment中找到由UserComment确定的订单

}

而不是

如果(OrderComment() == UserComment)

{

// 订单可能是由UserComment识别的

// 如果OrderComment没有被经纪人改变的话

}

罗伯特

正是如此...还有,有时在EA中编码的原始评论太长,会被平台截断(不确定评论的其余部分是否在 "记忆 "中,但它不显示在评论栏中)。

冯玉祥

 

我的EA需要帮助

你好。

我正在开发一个同时开立多头和空头头寸的EA,我面临这个问题......当两种头寸都开立时,比如第一种是空头,第二种是多头......如果空头仍然开着,EA不会关闭多头头寸,它会等待空头被关闭,然后在条件满足时关闭多头,反之亦然。 以下是EA中应该关闭开立头寸的部分。

//---- 关闭未结头寸

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

{

OrderSelect(cnt, SELECT_BY_POS)。

{

//-- 关闭多头

如果(OrderSymbol() == Symbol() && OrderType() ==OP_BUY && rsi1>75 && rsi<75)

{

OrderClose(OrderTicket(),OrderLots(),Bid,5,Green)。

LotL=Lot。

}

//-- 关闭空头

如果(OrderSymbol() == Symbol() && OrderType() ==OP_SELL && rsi125)

{

OrderClose(OrderTicket(),OrderLots(),Ask,5,Red)。

LotS=Lot。

}

}

}

*其中rsi1是之前的rsi,rsi是当前的读数

*LotL和LotS是原始手数的倍数,我将其设置为每边最多打开3个头寸,所以当关闭一种未结头寸时,LotL和LotS将被重置为原始大小。

EA在开仓时按计划工作,但问题是在关闭开仓时,我认为循环部分的EA没有读取所有的开仓头寸,而只是读取了第一个头寸......如果能帮助解决这个问题,真的很感激

欢呼吧!

彼得

 

我正在尝试添加 "激活追踪止损的点数 "功能。我修改的内容是红色的。还有什么需要添加的?

extern string Remark1 = "== Main Settings ==";

extern int MagicNumber = 54321;

extern bool SignalMail = False;

extern bool EachTickMode = true;

extern double Lots = 4;

extern int Slippage = 2;

extern bool UseStopLoss = false;

extern int StopLoss = 100;

extern bool UseTakeProfit = false;

extern int TakeProfit = 15;

extern bool UseTrailingStop = true;

extern int TrailingStop = 45;

extern double Pips_Activate_TS = 5;

extern bool MoveStopOnce = False;

extern int MoveStopWhenPrice = 50;

extern int MoveStopTo = 1;

extern int MaxConcurrentTrades = 2;

//Version 2.01

int BarCount;

int Current;

bool TickCheck = False;

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

//| expert initialization function |

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

int init() {

BarCount = Bars;

if (EachTickMode) Current = 0; else Current = 1;

return(0);

}

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

//| expert deinitialization function |

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

int deinit() {

return(0);

}

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

//| expert start function |

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

int start()

{

int Order = SIGNAL_NONE;

int Total, Ticket;

double StopLossLevel, TakeProfitLevel;

if (EachTickMode && Bars != BarCount) TickCheck = False;

Total = OrdersTotal();

Order = SIGNAL_NONE;

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

//| Variable Begin |

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

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

//| 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() && OrderMagicNumber() == MagicNumber) {

IsTrade = True;

if(OrderType() == OP_BUY) {

//Close

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

//| Signal Begin(Exit Buy) |

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

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

//| 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;

}

//MoveOnce

if(MoveStopOnce && MoveStopWhenPrice > 0) {

if(Bid - OrderOpenPrice() >= Point * MoveStopWhenPrice) {

if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) {

OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

//Trailing stop

if(UseTrailingStop && 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 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;

}

//MoveOnce

if(MoveStopOnce && MoveStopWhenPrice > 0) {

if(OrderOpenPrice() - Ask >= Point * MoveStopWhenPrice) {

if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo) {

OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

//Trailing stop

if(UseTrailingStop && 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;

}

}

}

}

}

}

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

//| Signal Begin(Entry) |

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

if(Open[0] > Open[0+1] &&

Open[0+1] >= Open[0+2] &&

Open[0+2]>= Open[0+3] &&

Open[0+3] >= Open[0+4] &&

Open[0+4] >= Open[0+5] &&

Open[0+5] >= Open[0+6]) Order = SIGNAL_SELL;

if(Open[0] < Open[0+1] &&

Open[0+1] <= Open[0+2] &&

Open[0+2]<= Open[0+3] &&

Open[0+3] <= Open[0+4] &&

Open[0+4] <= Open[0+5] &&

Open[0+5] <= Open[0+6]) Order = SIGNAL_BUY;

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

//| Signal End |

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

//Buy

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

if(DecideToOpenTrade(OP_BUY) && TradeSlotsAvailable()) {

//Check free margin

if (AccountFreeMargin() < (1000 * Lots)) {

Print("We have no money. Free Margin = ", AccountFreeMargin());

return(0);

}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;

if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("BUY order opened : ", OrderOpenPrice());

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

} else {

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

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

//Sell

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

if(DecideToOpenTrade(OP_SELL) && TradeSlotsAvailable()) {

//Check free margin

if (AccountFreeMargin() < (1000 * Lots)) {

Print("We have no money. Free Margin = ", AccountFreeMargin());

return(0);

}

if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;

if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("SELL order opened : ", OrderOpenPrice());

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

} else {

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

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

if (!EachTickMode) BarCount = Bars;

return(0);

}

 
 
mifiglo:
你好,交易员朋友们。

我有这样一个小问题,从一个自定义指标开发一个专家顾问,我已经尝试了 "iCustom "功能,但我的指标总是返回相同的值。

它的返回值是21473......,就像这样。

我希望EA能够识别卖出和买入箭头信号产生的时间,并执行相应的交易操作(即当指标显示上升时买入,显示下降时卖出)。

这是指标的代码,如果有人能尽快拿出解决方案,我将非常感激。

请把你的iCustom()函数 的代码行也贴出来。

傅瑞福

 

对不起,这是我仅有的...

 
 

Rsi Ea

这是我的第一个EA。它在3个时间框架内使用2个Rsi的交叉点。我有一个问题,就是EA对交叉点进行交易。在应该卖出的时候买入,在应该买入的时候卖出。谁能看一下代码并告诉我哪里出错了。我看不出有什么问题。

我附上了EA和问题的照片。

附加的文件:
 

需要EA代码的帮助!

大家好。

正如你们所知,外汇市场是24小时不间断的,我不太愿意在不坐在电脑前的情况下通宵交易。所以我想最好的方法是在价格向我喜欢的方向移动时,用程序来保护交易。例如,如果我总共开了5手,当利润超过50点时,它会自动移动止损到收支平衡。当利润在100点以上时,它会移动到保护30点。当利润在200点以上时,它会移动到保护50点。

我试着给自己编码。但当我把它拖到我的图表中并设置为实时交易时,它并不工作。有谁能帮我看一下我的代码并加以修正?非常感谢。

#属性版权 "x li"

#属性link ""

#perty show_confirm

//---- 输入参数

extern int target1 =50;

extern int target2 =100;

extern int target3 =150;

extern int target4 =200;

extern int target5 =300;

外置 int protect1 =0;

extern int protect2 =5;

extern int protect3 =50;

extern int protect4 =100;

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

//| 脚本 "将止损转移到保护(50->0;100->5;150->50;200->50;300->100)" |

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

int start()

{

bool result;

double stop_loss,point,EntryPrice,profit;

int cmd,total,error,i;

//----

total=OrdersTotal();

point=MarketInfo(Symbol(),MODE_POINT)。

//----

for(i=0; i<total; i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

{

cmd=OrderType();

EntryPrice=OrderOpenPrice()。

//---- 买入订单被考虑

如果(cmd==OP_BUY)

{

profit=Bid-EntryPrice;

if(profit>target1*point && profit<target2*point)

{

stop_loss=EntryPrice+protect1*point;

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE);

}

if(profit>target2*point && profit<target3*point)

{

stop_loss=EntryPrice+protect2*point;

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE)。

}

if(profit>target3*point && profit<target4*point)

{

stop_loss=EntryPrice+protect3*point;

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE)。

}

if(profit>target4*point && profit<target5*point)

{

stop_loss=EntryPrice+protect3*point;

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE)。

}

如果(profit>target5*point)

{

stop_loss=EntryPrice+protect4*point。

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE)。

}

}

//----卖出订单 被视为

如果(cmd==OP_SELL)

{

profit=EntryPric-Ask;

if(profit>target1*point && profit<target2*point)

{

stop_loss=EntryPric-protect1*point;

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE);

}

如果(profit>target2*point && profit<target3*point)

{

stop_loss=EntryPric-protect2*point;

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE)。

}

如果(profit>target3*point && profit<target4*point)

{

stop_loss=EntryPric-protect3*point;

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE)。

}

如果(profit>target4*point && profit<target5*point)

{

stop_loss=EntryPric-protect3*point;

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE)。

}

如果(利润>目标5*点)

{

stop_loss=EntryPrice-protect4*point;

result=OrderModify(OrderTicket(),0,stop_loss,0,0,CLR_NONE)。

}

}

}

else { Print("订单选择时出错", GetLastError()); break; }

}

//----

return(0);

}

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

 

Rsi Ea

我不明白为什么你用同一个变量来开仓和平仓,但这可能是有效的。

这可能是问题所在。

"订单 "是一个全局变量。 因此,在每次通过Start函数 运行结束时,它将被设置为它被分配的最后一个值,并在下次运行开始时使用该值。 如果你把它变成局部的(把它移到Start里面),就可以解决这个问题。 否则,你将不得不在最后一次使用它之后重置它。

良好的狩猎。

大贝