任何菜鸟问题,为了不给论坛添乱。专业人士,不要路过。没有你就无处可去 - 6. - 页 539

 
tatianati:

谢谢你!它起作用了,我高兴得像个孩子,但顾问不再显示 "新"。你能告诉我,我哪里错了吗?

咦,发现了错误,不是我原来要找的地方。我自己无法应付接下来的任务。

请告知如何设置偏差范围--价格与MA的距离。

extern string s10                = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>";
extern string s11                = ">>> Вход против МА";
extern int    iMA_Period         = 365;
extern int    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);
}
 
tatianati:

咦,发现了错误,不是我原来要找的地方。我无法独自处理下一个任务。

你能告诉我如何设置偏差范围--价格与MA的距离。

下面是进入的部分


extern int    Min_iMA_OpenDistance   = 60;
extern int    Max_iMA_OpenDistance   = 85;

因此,条件是

if(Ma_Bid_Diff > Min_iMA_OpenDistance && Ma_Bid_Diff < Max_iMA_OpenDistance && Bid > iMA_Signal)
 

我们需要将顾问中的原始数据正确地改为(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) 打印到新行中。

这里仅以随机指标为例。

 //+------------------------------------------------------------------+
//|                                                     binar_v1.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link        "https://www.mql5.com"
#property version    "1.00"


//--- input Time parameters
input uchar     hs = 9 ; 
input uchar     ms = 0 ; 
input uchar     he = 18 ; 
input uchar     me = 0 ;
//--- input Indicator parameters

//--- input Expiration parameters
input uchar     Expiration = 2 ; //время експирации в минутах


input bool      strategy_1  =   true ;


bool poz;                                   //открытая/закрытая позиция
datetime op_time;                         //время открытия
double op_price;                           //цена открытия
char type;                                 //тип открытой позиции -1 СЕЛЛ, 1- БАИ
//+=================================================================================+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- 
   
      
//---
   return ( INIT_SUCCEEDED );
  }
//+=================================================================================+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- destroy timer
   
      
  }
//+=================================================================================+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
   //подщитаем арифметическое среднее OC за прошлую неделю
   //Пощет один раз в неделю    
     /* if(isNewBar("",PERIOD_W1)){      
         uchar iPr=iBarShift(NULL,PERIOD_M1,iTime(NULL,PERIOD_W1,1));
         uchar iPn=iBarShift(NULL,PERIOD_M1,iTime(NULL,PERIOD_W1,1))+10080;
         double avgM1=AvgOC(iPr,iPn,0);                                     // M1 OC цредняя за прошлую неделю               
      }*/
       if (!fisTradeTimeInt( 9 , 0 , 18 , 0 )) return ;                                 //Время торгов
       if (strategy_1== true )fStrategy1();
  }
//+=================================================================================+
//| Timer function                                                   |
//+------------------------------------------------------------------+

//+=================================================================================+
void fStrategy1
   (
   
   )
//--------------------   
{
   

   if (poz== true )                             //если есть открыта позиция
      fClose_Pos(op_time,op_price,type);       //закрываем
   if (poz== false ){                           //если нет открытой
      fOpen_buy(poz,op_time,op_price,type);   //покупка   
      fOpen_sell(poz,op_time,op_price,type);   //продажа
   }       
}
//+=================================================================================+
void fOpen_buy
   (
   bool & op,                                 //открытая/закрытая позиция
   datetime & out_op_time,                       //время открытия
   double & out_op_price,                         //цена открытия
   char & out_type                               //тип открытой позиции -1 СЕЛЛ, 1- БАИ
   )
//--------------------
{
   double stoch_M0_1 = iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_MAIN , 1 );
   double stoch_M0_2 = iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_MAIN , 2 );
   double stoch_M0_1s= iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_SIGNAL , 1 );
   double stoch_M0_2s= iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_SIGNAL , 2 );
   
   string arrowName;
   
   if (!op){      
       if (stoch_M0_1 < 20 && stoch_M0_2 < stoch_M0_2s && stoch_M0_1s < stoch_M0_1){
          out_type=- 1 ;
          op= true ;
          out_op_price= Close [ 0 ];
          out_op_time= Time [ 0 ];
          arrowName= "Buy" + TimeToStr ( TimeCurrent (), TIME_DATE | TIME_SECONDS );
          fDrawArrow(arrowName= "" ,out_op_price,out_op_time,Blue, 240 );               //стрелка открытой позиции
      }
          
   }     
}
//+=================================================================================+
void fOpen_sell
   (
   bool op,                                 //открытая/закрытая позиция
   datetime & out_op_time,                       //время открытия
   double & out_op_price,                         //цена открытия
   char & out_type                               //тип открытой позиции -1 СЕЛЛ, 1- БАИ
   )
//--------------------   
{      
   double stoch_M0_1 = iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_MAIN , 1 );
   double stoch_M0_2 = iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_MAIN , 2 );
   double stoch_M0_1s= iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_SIGNAL , 1 );
   double stoch_M0_2s= iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_SIGNAL , 2 );
   
   string arrowName;
   
   if (!op){      
       if (stoch_M0_1 > 80 && stoch_M0_2 > stoch_M0_2s && stoch_M0_1s > stoch_M0_1){
          out_type=- 1 ;
          op= true ;
          out_op_price= Close [ 0 ];
          out_op_time= Time [ 0 ];
          arrowName= "Sell" + TimeToStr ( TimeCurrent (), TIME_DATE | TIME_SECONDS );
          fDrawArrow(arrowName= "" ,out_op_price,out_op_time,Red, 240 );               //стрелка открытой позиции
      }
          
   }     
}
//+=================================================================================+
void fClose_Pos //jei yra atidaryta, uzdarom
   (
   datetime fop_time,                       //время открытия
   double fop_price,                       //цена открытия
   char ftype                               //тип открытой позиции -1 СЕЛЛ, 1- БАИ
   )
//-------------------   
{
   string arrowName= "Close" + TimeToStr ( TimeCurrent (), TIME_DATE | TIME_SECONDS );    
   double cl_price;
   string fileName= StringConcatenate ( "Strategy_1  " ,Expiration, " " , Period (), ".csv" );
   
   if (Expiration<= 5 ){                     //
       datetime cl_time= Expiration* 60 +op_time;                                         //время закрытия
       if ( TimeCurrent ()>=cl_time){
         
         cl_price= Close [ 0 ];               //цена закрытия         
         fDrawArrow(arrowName,cl_price,cl_time,Yellow, 251 );                             //наносим крестик на график
         fSaveToFile(fileName,Expiration, fop_time, cl_time, fop_price, cl_price, ftype);   //в новую строку сохроняем в файле
      }   
   }
   else {
      cl_time= fExpiration_func(Expiration)* 60 +op_time;                                 //время закрытия
      
       if ( TimeMinute ( TimeCurrent ())>= TimeMinute (cl_time)){
         
         cl_price= Close [ 0 ];      
         fDrawArrow(arrowName,cl_price,cl_time,Yellow, 251 );                             //наносим крестик на график
         fSaveToFile(fileName,fExpiration_func(Expiration), fop_time, cl_time, fop_price, cl_price, ftype); //в новую строку сохроняем в файле
     }
   }   
}
//+=================================================================================+
bool fisNewBar 
   (
   string f_sy,   
   int f_tf
   )
{
     int iIndex = - 1 ;
//----
     switch (f_tf)
    {
         case 1     : iIndex = 0 ; break ;
         case 5     : iIndex = 1 ; break ;
         case 15    : iIndex = 2 ; break ;
         case 30    : iIndex = 3 ; break ;
         case 60    : iIndex = 4 ; break ;
         case 240   : iIndex = 5 ; break ;
         case 1440 : iIndex = 6 ; break ;
         case 10080 : iIndex = 7 ; break ;
         default    : iIndex =- 1 ; break ;
    }
    
     static int LastBar[ 8 ]= { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }; 
     datetime curbar = iTime (f_sy, f_tf, 0 );
     if (LastBar[iIndex] != curbar)
    {
        LastBar[iIndex] = curbar;
         return ( true );
    }
     else
    { return ( false );
 }
 }
//+=================================================================================+
int fExpiration_func
   (
   uchar e
   )
//--------------------   
{  
   uchar ex= 0 ;
   uchar mod= 0 ;
   if (e< 6 ) 
      ex=e; //return(e);
   else {
      mod= fmod (e, 5 );
       if (mod== 4 ) 
         ex=e+mod; //return(e+mod);
       else
         if (mod < 4 ) 
            ex=e-mod; //return(e-mod);
    }     
   return (ex); //grazina laiko tarpa minutemis
}
//+=================================================================================+
bool fisTradeTimeInt     //время торгов
   (
   uchar hstart= 0 , 
   uchar mstart= 0 , 
   uchar hend= 0 , 
   uchar mend= 0
   ) 
//--------------------   
{
   datetime db, de;           
   uchar       hc;              

  db= StrToTime ( TimeToStr ( TimeCurrent (), TIME_DATE )+ " " +hstart+ ":" +mstart);
  de= StrToTime ( TimeToStr ( TimeCurrent (), TIME_DATE )+ " " +hend+ ":" +mend);
  hc= TimeHour ( TimeCurrent ());
   if (db>=de) {
     if (hc>=hend) de+= 24 * 60 * 60 ; 
     else db-= 24 * 60 * 60 ;
  }
   if ( TimeCurrent ()>=db && TimeCurrent ()<=de) return ( True );
   else return ( False );
}
//+=================================================================================+
void fDrawArrow //наносим стрелки на график
   (
   string arrowName= "" ,
   double dwPrice= 0 ,
   datetime dwTime= 0 ,
   color dwColor=Silver,
   uchar dwArrowIndex= 0
   )
//--------------------   
{
   ObjectCreate       ( 0 ,arrowName, OBJ_ARROW , 0 , 0 , 0 , 0 , 0 );                 // создадим стрелку
   ObjectSetInteger   ( 0 ,arrowName, OBJPROP_ARROWCODE ,dwArrowIndex);       // установим код стрелки
   ObjectSetInteger   ( 0 ,arrowName, OBJPROP_COLOR ,dwTime);                 // зададим время
   ObjectSetInteger   ( 0 ,arrowName, OBJPROP_COLOR ,dwColor);               // зададим Цвет
   ObjectSetDouble    ( 0 ,arrowName, OBJPROP_PRICE ,dwPrice);               // зададим цену
   ChartRedraw ( 0 );
}
//+=================================================================================+
//Aritmetinis vidurkis

double fAvgOC
   (
   uchar count_start,       //nuo kurio baro pradesim skaiciuoti
   uchar end_count,         //iki kurio baro skaiciuosime
   uchar j= 0                //keli barai is eiles
   )
//--------------------   
{
   static double sum= 0 ;
   if (sum== 0 ){
       int n= 0 ;
       for ( int i=end_count; i<count_start; i++){
         double h= iClose ( NULL , PERIOD_M1 ,i);  
         double l= iOpen ( NULL , PERIOD_M1 ,i+j); 
         sum+= fabs (h-l);                   //padidinam avg 
         n++;                             //kie kartu buvo didintas avg
      }
       double avg=sum/n;                           //Surandam Mean aritmetini vidurki                 
   }   
   return (avg);                           //grazina kainu skirtumo vidurki
}
//+=================================================================================+
void fSaveToFile
   (
   string fileName,
   char expirration,       //realus ekspiracijos laikas minutemis
   datetime fop_time,
   datetime fcl_time,
   double fop_price,
   double fcl_price,
   uchar ftype
   )
//--------------------   
{
   //--- правильный способ работы в "файловой песочнице"
   ResetLastError ();
  
   int filehandle= FileOpen (fileName, FILE_WRITE | FILE_CSV );
   if (filehandle!= INVALID_HANDLE )
     {
      FileWrite(filehandle,
               expirration, //real expiration time
               fop_time, //TimeToStr(op_time,TIME_DATE|TIME_SECONDS),
               fcl_time, //TimeToStr(cl_time,TIME_DATE|TIME_SECONDS),
               op_price,
               fcl_price,
               type);
       FileClose (filehandle);
       Print ( "FileOpen OK" );
     }
   else Print ( "Операция FileOpen неудачна, ошибка " ,GetLastError());
}
//+=================================================================================+
/*int gUrdala_News()
{
   HideTestIndicators(true);
   int nResult = iCustom(NULL, PERIOD_M1, "Urdala_News", MinDo, MinPosle, ChasPoyasServera, 0, 0);
   HideTestIndicators(false);
   return(nResult);
}*/
//+=================================================================================+
/*datetime SecondsAfter    //grazinamas laiko tarpas po timeOp
   (
   datetime timeOp,      //laiko atskaitos pradzia
   datetime t
   ) 
{
     
   if (t<timeOp) t=timeOp;          
   return(TimeCurrent()-t);
}*/
//+=================================================================================+
//---------------------------------------------------
   /* void click
   (
   int x, 
   int y
   ) 
   {    
      SetCursorPos(x,y); // см. тут _http://www.vsokovikov.narod.ru/New_MSDN_API/Cursor/fn_setcursorpos.htm 
      mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); 
      mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); 
   }*/
//+=================================================================================+
//---------------------------------------------------
   /*void key
   (
   uchar kodas
   )
   {  
      keybd_event(kodas,0,0,0);      
      keybd_event(kodas,0,KEYEVENTF_KEYUP,0); 
   } */   
 

那么问题是如何返回这两个值。试过了,但出错了

void OnTick()
  {
//---
   
   xy(10,20,100,100);
   Print("x=",x,"y=",y);
  }
//+------------------------------------------------------------------+
void xy(int xx,int xxx, int yy,int yyy,int & x,int & y){
   x=xx*xxx;
   y=yy+yyy;
}
 
gince:

那么问题是如何返回这两个值。试过了,但出错了


void OnTick()
  {
//---
   int x,y;
   xy(10,20,100,100,x,y);
   Print("x=",x,"y=",y);
  }
//+------------------------------------------------------------------+
void xy(int xx,int xxx, int yy,int yyy, int &x,int &y){
   x=xx*xxx;
   y=yy+yyy;
}
 
gince:

那么问题是如何返回这两个值。试过了,但出错了


你试过使用变量吗?也许会有帮助。

void OnTick()
  {
//---
   int x=100.0, y=100.0;
   xy(10,20,100, 100, x,y);
   Print("x=",x,"y=",y);
  }
//+------------------------------------------------------------------+
void xy(int xx,int xxx, int yy,int yyy,int & x,int & y){
   x=xx*xxx;
   y=yy+yyy;
}
 

如果你不介意的话,请提供帮助

教导专家顾问按指标进行交易

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

);

我试图阅读评论中的数值,但它们总是静态的。

 
Vinin:


你试过使用变量吗?这可能会有帮助。


谢谢你,这很有效。

 
sannin:

如果你不介意的话,请提供帮助

教导专家顾问按指标进行交易

BS_Living Now ver #1.mq4 https://www.mql5.com/ru/code/11014#50910


UP= iCustom(Symbol(),NULL,"Now",BQuant,0,2);//

DOW= iCustom(Symbol(),NULL,"Now",BQuant,1,2);


if(DOW != 0){OrderSend(Symbol(), OP_SELL, Lot, Bid, Slip, 0, 0, "Forex-Robots.ru SELL", Magic, 0,Red);}



if(UP != 0){OrderSend(Symbol(), OP_BUY, Lot, Ask, Slip, 0, 0, "Forex-Robots.ru BUY", Magic, 0,Blue);}
我还没有真正深入了解,但我认为它是这样的。