externstring s10 = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>";
externstring s11 = ">>> Вход против МА";
externint iMA_Period = 365;
externint iMA_OpenDistance = 60; // как задать диапазон? например 60-85 за его пределами не открывать ордеров
下面是进入的部分
int GetSignal()
{
int Signal = 0;
double iMA_Signal = iMA(Symbol(), 0, iMA_Period, 0, MODE_SMMA, PRICE_CLOSE, 0);
int Ma_Bid_Diff = MathAbs(iMA_Signal - Bid)/vPoint;
if(Ma_Bid_Diff > iMA_OpenDistance && Bid > iMA_Signal) Signal = -1;
if(Ma_Bid_Diff > iMA_OpenDistance && Bid < iMA_Signal) Signal = 1;
return(Signal);
}
bool cbm(int magic, int slipage, int type) { /* 用魔法关闭(用给定的魔法号码关闭所有给定类型的订单)。 允许的最大滑移量已被考虑在内 使用close_by_ticket函数。 */ int n = 0。 while (find_orders(magic, type)) for (int i2=OrdersTotal()-1; i2>=0; i2--){ if (!OrderSelect(i2,SELECT_BY_POS,MODE_TRADES)) break;
谢谢你!它起作用了,我高兴得像个孩子,但顾问不再显示 "新"。你能告诉我,我哪里错了吗?
咦,发现了错误,不是我原来要找的地方。我自己无法应付接下来的任务。
请告知如何设置偏差范围--价格与MA的距离。
下面是进入的部分
咦,发现了错误,不是我原来要找的地方。我无法独自处理下一个任务。
你能告诉我如何设置偏差范围--价格与MA的距离。
下面是进入的部分
因此,条件是
我们需要将顾问中的原始数据正确地改为(1买入,-1卖出)。
//+------------------------------------------------------------------+
//| SimpleBars_rob.mq4|//| Copyright © 2010, ENSED Team | 版权所有。
//| http://www.ensed.org |
//+------------------------------------------------------------------+
#property copyright"Copyright © 2010, ENSED Team"
#属性链接 "http://www.ensed.org"
extern int SL = 50; // 止损值(以点计)。
TP = 150; // 获利值(单位:点)。
extern double Lots = 0.1; // working lot (Micro lots - 0.01, mini lots - 0.1, normal lots - 1.0)
extern string Order_Comment = "robot"; // 将用于下订单的注释
extern int Slipage = 5; // 最大允许的滑移水平(单位:点)。
extern int int Magic_Number = 777; // 机器人的神奇订单数(用于区分 "友好 "交易)。
extern bool Play_Sound = false; // 开场时播放声音:true - 允许,false - 禁止。
//--------------------------------------------------------------------------------------------------------------------+
//+ 设置SimpleBars指标的时间框架和参数。
外来的int period = 6;
外部 bool useClose = true。
外来的int宽度=3。
//+ 调整指标SimpleBars的时间框架和参数|。
//--------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//+追踪止损 |
外部 bool UseTrailing = true; // Trailing stop on/off
外部int TrailingStop = 50; // 固定的追踪止损大小(单位:点)。
外部int TrailingStep = 1; // 尾随止损步骤(以点为单位)。
//+ 后续止损
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//|函数在程序初始化时执行。
void init() {
如果(GlobalVariableCheck("this_bar "+Symbol()+Period()))
GlobalVariableDel("this_bar "+Symbol()+Period())。
返回。
}
//|函数,在程序初始化时执行。
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//|函数在程序去初始化时执行。
void deinit() {
如果(GlobalVariableCheck("this_bar "+Symbol()+Period()))
GlobalVariableDel("this_bar "+Symbol()+Period())。
返回。
}
//|函数,在程序去初始化时执行。
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//|搜索交易信号的功能|
int fsignals() {
double signal = iCustom(NULL, 0, "SimpleBars", period, 0, 1, 4, 0);
return(0); // 开启买入的信号
return(1); //打开Sell信号
return(-1); // 没有信号
} //结束 int fsignals()
//|寻找交易信号的功能
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| 追踪机器人在给定条上的工作的功能
bool this_bar() {
如果(
(!GlobalVariableCheck("this_bar "+Symbol()+Period()))
|| (GlobalVariableGet("this_bar "+Symbol()+Period()!=Time[0])
){
GlobalVariableSet("this_bar "+Symbol()+Period(),Time[0])。
return(false)。
} else {
return(true)。
} //结束 如果(.(!GlobalVariableCheck("this_bar "+Symbol()+Period()))
} //结束 bool this_bar()
//| 追踪机器人在给定条上工作的事实的功能
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| 搜索这种类型的订单的功能。
bool find_orders(int magic=-1, int type=-1, string symb="NULL") {
/* 如果通过给定的符号至少找到一个具有给定魔数的给定类型的订单,则返回真 */
for (int i=OrdersTotal()-1; i>=0; i--){
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
如果(((OrderType()==type) || (type==-1))
&& ((OrderMagicNumber()==magic) || (magic==-1))
&& ((OrderSymbol()==Symbol() || (symb=="NONE"))))){
//如果找到一个订单,返回(true)并退出循环。
return(true)。
突破。
} //结束 if((OrderType()==type) && (OrderMagicNumber()==magic) && (OrderSymbol()==Symbol() )
} //end for (int i2=OrdersTotal()-1; i2>=0; i2--)
return(false); //返回false
} //结束 bool find_orders(int magic, int type)
//| 搜索给定类型的订单的功能。
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//|计算订单止损值的功能。
double sl(int sl_value, int type, double price=0.0, string symb="NONE", int rmode=1) {
//type=0 -> 市场购买
//type=1 -> 市场销售
如果(symb=="NONE") symb==Symbol();
如果(type==0) price=NormalizeDouble(MarketInfo(symb,MODE_ASK),MarketInfo(symb,MODE_DIGITS)
如果(type==1) price=NormalizeDouble(MarketInfo(symb,MODE_BID),MarketInfo(symb,MODE_DIGITS))。
if(sl_value<=0) return(0);
如果(rmode==1) {
if((type==0)|(type==2)|(type==4)) return(MarketInfo(symb,MODE_ASK)-sl_value*MarketInfo(symb,MODE_POINT)); //for purchases
if((type==1)|(type==3)|(type==5)) return(MarketInfo(symb,MODE_BID)+sl_value*MarketInfo(symb,MODE_POINT)); //for sales
}
如果(rmode==2) {
if((type==0)|(type==2)|(type==4)) return(MarketInfo(symb,MODE_BID)-sl_value*MarketInfo(symb,MODE_POINT)); //for buying
if((type==1)|(type==3)|(type==5)) return(MarketInfo(symb,MODE_ASK)+sl_value*MarketInfo(symb,MODE_POINT)); //for selling
}
} //结束 double sl(int sl_value, int type, double price=0.0, string symb="NONE", int rmode=1)
//|计算订单止损值的函数||
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| 用于计算订单获利值的函数
double tp(int tp_value, int type, double price=0.0, string symb="NONE" ) {
//type=0->市场买入
//type=1 -> 市场销售
如果(symb=="NONE") symb==Symbol();
如果(type==0) price=NormalizeDouble(MarketInfo(symb,MODE_ASK),MarketInfo(symb,MODE_DIGITS);
如果(type==1) price=NormalizeDouble(MarketInfo(symb,MODE_BID),MarketInfo(symb,MODE_DIGITS))。
if(tp_value<=0) return(0);
if((type==0)|(type==2)|(type==4)) return(price+tp_value*MarketInfo(symb,MODE_POINT)); //for purchases
if((type==1)|(type==3)|(type==5)) return(MarketInfo(symb,MODE_BID)-tp_value*MarketInfo(symb,MODE_POINT)); //for sales
} //结束 double tp(int tp_value, int type, double price=0.0, string symb="NONE")
//|计算订单的获利值的函数。
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| 开启订单的功能
void open_positions(int signal, double lot, double price=0.0, string symb="NONE") {
//signal=0 -- -- 开盘买入的信号
//signal=1 -- 开盘卖出的信号
/*extern */ int Count_Of_Trade_Try=5, Pause_Of_Trade_Try=5。
int i = 0; //用于循环计数器的变量。
int err = 0;
如果(symb=="NONE") symb==Symbol();
如果(signal==0)
price=NormalizeDouble(MarketInfo(symb,MODE_ASK),MarketInfo(symb,MODE_DIGITS)); //买入时的开盘价格
如果(signal==1)
price=NormalizeDouble(MarketInfo(symb,MODE_BID),MarketInfo(symb,MODE_DIGITS)); //open price for selling
while(i<=Count_Of_Trade_Try) {
打开订单的//功能(内置)。为了方便感知,这些参数被放在不同的行上。
int ticket = OrderSend(Symbol(), //symbol
信号,//订单类型
批量,//体积
价格, //开放价格
Slipage, //允许的重新报价水平
sl(SL,signal), // 止损的价值
tp(TP,信号), //获取利润值
Order_Comment, //订单评论
Magic_Number, //魔法数字
0, //到期时间(用于挂单)。
CLR_NONE); //图表上显示的箭头的颜色(CLR_NONE - 箭头不被绘制)。
if(ticket!=-1) //如果打开成功,画一个图形对象并退出循环。
突破。
err=GetLastError()。
if(err!=0) Print("Error: "+Market_Err_To_Str(err))。
i++;
Sleep(Pause_Of_Trade_Try*1000); //在出错的情况下,重试前暂停。
} //结束 while(i<=count)
} //结束 void open_positions(int signal, double lot, double price=0.0, string symb="NONE")
//|打开订单的功能|
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------+
//|解码错误代码的功能|
string Market_Err_To_Str(int err) {
/* 函数只包括交易操作的错误代码 */
switch(err) {
case(0): return("No error");
case(1): return("No error, but the result is unknown")。
case(2): return("General error")。
case(3): return("参数不正确")。
case(4): return("Trade server is busy")。
case(5): return("客户终端的旧版本")。
case(6): return("No connection to trade server");
case(7): return("没有足够的权利")。
case(8): return("Too frequent requests")。
case(9): return("Invalid operation disrupting server operation")。
case(64): return("Account blocked")。
case(65): return("Incorrect account number")。
case(128): return("The deadline for the transaction has expired")。
case(129): return("不正确的价格")。
case(130): return("Incorrect stops")。
case(131): return("Incorrect volume")。
case(132): return("Market is closed");
case(133): return("禁止交易")。
case(134): return("没有足够的钱来执行交易")。
case(135): return("The price has changed");
case(136): return("No price");
case(137): return("The broker is busy")。
case(138): return("New prices");
case(139): return("该订单已被阻止并已被处理")。
case(140): return("只允许购买")。
case(141): return("Too many requests")。
case(145): return("Modification is not allowed, because the order is too close to market");
case(146): return("The trading subsystem is busy")。
case(147): return("经纪人禁止使用到期日")。
case(148): return("未结订单和挂单的数量已经达到经纪人设定的上限;)
case(149): return("在禁止套期保值的情况下,试图建立与现有头寸相反的头寸")。
case(150): return("试图在违反先进先出规则的情况下关闭一个符号的头寸")。
默认:返回("")。
}//结束 switch(err)
}//结束字符串Err_To_Str(int err)。
//|对错误代码进行解码的功能|
//+-------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------+
//|交易结束操作||
//+----------------------------------------------------------------------------------------------------+
//|根据订单编号(票据)关闭订单的功能。
bool close_by_ticket(int c_ticket, int slipage) {
/*
按编号(票)关闭交易的功能。
当关闭一个市场订单时,会考虑到最大允许滑点的水平(滑点)。
*/
/*extern */ int Count_Of_Trade_Try=5, Pause_Of_Trade_Try=5。
int i = 0; //用于循环计数器的变量。
int err = 0;
bool ticket = false; //用于交易(未)成功关闭的变量。
double price = 0.0; //要关闭的交易的价格(对于市场订单)。
if(OrderSelect(c_ticket,SELECT_BY_TICKET,MODE_TRADES)){ //选择按票数排序
if(OrderType()==OP_BUY) price = NormalizeDouble(Bid,Digits); //买入的价格
如果(OrderType()==OP_SELL) price = NormalizeDouble(Ask,Digits); //卖出的价格
for(i=0;i<=Count_Of_Trade_Try;i++) {
如果(OrderType()<=1) //如果订单是市场订单,关闭它,如果是挂单,删除它。
ticket=OrderClose(OrderTicket(),OrderLots(),price,slipage,CLR_NONE)。
否则
ticket=OrderDelete(OrderTicket())。
if(ticket) { //如果关闭或删除成功 - 返回true并退出循环。
return(true)。
突破。
}//结束 if(ticket)
err=GetLastError()。
if(err!=0) Print("Error: "+Market_Err_To_Str(err))。
Sleep(Pause_Of_Trade_Try*1000); //在出现错误时,在重试前暂停。
} //结束 for(i=0;i<=Count_Of_Trade_Try;i++)
} //结束 if(OrderSelect(c_ticket,SELECT_BY_TICKET,MODE_TRADES))
return(false); //返回false
} //结束 bool close_by_ticket(int c_ticket)
//|根据订单编号(票据)关闭订单的功能。
//+----------------------------------------------------------------------------------------------------+
bool cbm(int magic, int slipage, int type) {
/*
用魔法关闭(用给定的魔法号码关闭所有给定类型的订单)。
允许的最大滑移量已被考虑在内
使用close_by_ticket函数。
*/
int n = 0。
while (find_orders(magic, type))
for (int i2=OrdersTotal()-1; i2>=0; i2--){
if (!OrderSelect(i2,SELECT_BY_POS,MODE_TRADES)) break;
如果((OrderType()==type) && (OrderMagicNumber()==magic)){
close_by_ticket(OrderTicket(), slip;)
n++;
} //结束 如果((OrderType()==OP_BUY) || (OrderType()==OP_SELL))&& (OrderMagicNumber()==magic))
} //end for (int i2=OrdersTotal()-1; i2>=0; i2--)
如果(n>0)
return(true)。
return(false)。
}//结束 bool cbm(int magic, int slipage, int type)
//| 贸易结算业务 |
//+-------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//|追踪止损|
空白的T_SL() {
if(!UseTrailing) 返回。
int i = 0。
for(i=0; i<OrdersTotal(); i++){
if(!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) 继续。
如果(OrderSymbol() != Symbol() || OrderMagicNumber() !=Magic_Number) 继续。
如果(OrderType()==OP_BUY){
如果(normalizeDouble(Bid-OrderOpenPrice(),Digits)>NormalizeDouble(TrailingStop*Point,Digits)){
如果(NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-(TrailingStop+TrailingStep-1) *Point,Digits))
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*Point,Digits), OrderTakeProfit(), 0, CLR_NONE)
} //结束 if(NormalizeDouble(Bid-OrderOpenPrice(),Digits)>NormalizeDouble(TrailingStop*Point,Digits))
} //结束 if(OrderType()==OP_BUY)
如果(OrderType()==OP_SELL) {
如果(NormalizeDouble(OrderOpenPrice()-Ask,Digits)>NormalizeDouble(TrailingStop*Point,Digits)){
如果(normalizeDouble(OrderStopLoss(),Digits)>NormalizeDouble(Ask+(TrailingStop+TrailingStep-1)*Point,Digits)
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*Point,Digits), OrderTakeProfit(), 0, CLR_NONE)
} //结束 if(NormalizeDouble(OrderOpenPrice()-Ask,Digits)>NormalizeDouble(TrailingStop*Point,Digits))
} //结束 if(OrderType()==OP_SELL)
} //结束 for(i=0; i<OrdersTotal(); i++)
} //结束 void T_SL()
//|追踪止损|
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//|主函数|
空白启动() {
int sig = fsignals()。
if(!find_orders(Magic_Number)){
如果((sig!=-1)){
if(!this_bar()){
open_positions(sig, Lots)。
如果(Play_Sound)
PlaySound("alert.wav")。
}
} //结束 if((sig!=-1) && (!this_bar())
} else {
如果(sig==0) {
如果(cbm(Magic_Number, Slipage, 1)){
open_positions(sig, Lots)。
如果(Play_Sound)
PlaySound("alert.wav")。
} //结束 if(cbm(Magic_Number, Slipage, 1))
} //结束 if(sig==0)
如果(sig==1) {
如果(cbm(Magic_Number, Slipage, 0)){
open_positions(sig, Lots)。
如果(Play_Sound)
PlaySound("alert.wav")。
} //结束 if(cbm(Magic_Number, Slipage, 0))
} //结束 if(sig==1)
T_SL()。
} //结束 if(!find_orders(Magic_Number))(其他)
返回。
}
//|主函数|
//+-------------------------------------------------------------------------------------------------------------------+
各位鉴赏家您好。帮助 - 不工作。我想我对变量的初始化感到困惑。我头晕目眩,但我找不到任何错误。
EA 不应开仓,而是应以 Klose(0) 价格绘制箭头,而不是平仓 - 交叉并将数据 ( fExpiration_func(Expiration)、fop_time、cl_time、fop_price、cl_price、ftype) 打印到新行中。
这里仅以随机指标为例。
那么问题是如何返回这两个值。试过了,但出错了
那么问题是如何返回这两个值。试过了,但出错了
那么问题是如何返回这两个值。试过了,但出错了
你试过使用变量吗?也许会有帮助。
如果你不介意的话,请提供帮助
教导专家顾问按指标进行交易
BS_Living Now ver #1.mq4 https://www.mql5.com/ru/code/11014#50910
UP= iCustom(Symbol(),NULL, "Now",BQuant,0,0)。
DOW= iCustom(Symbol(),NULL, "Now",BQuant,1,0)。
如果(DOW){OrderSend(Symbol(, OP_SELL, Lot, Bid, Slip, 0, 0, "Forex-Robots.ru SELL", Magic, 0,Red);}。
如果(UP ){OrderSend(Symbol(, OP_BUY, Lot, Ask, Slip, 0, 0, "Forex-Robots.ru BUY", Magic, 0,Blue);}。
评论
(
"n Profit:", UP,
"n Profit:",DOW
);
我试图阅读评论中的数值,但它们总是静态的。
你试过使用变量吗?这可能会有帮助。
谢谢你,这很有效。
如果你不介意的话,请提供帮助
教导专家顾问按指标进行交易
BS_Living Now ver #1.mq4 https://www.mql5.com/ru/code/11014#50910