新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 1808

 

下午好。我正在学习写代码,我有一个问题。测试器中的代码运行,打开一个交易,仅此而已。价格没有变化,一切都在当场停止。

谁不难,请指教。

if (CountTrades() == 0)
   {
    double body = Close[1] - Open[1];
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
//Открытие позиции Buy
    if (body > 0)
       {
        Forder = (OrderSend(_Symbol,OP_BUY,Lot,Ask,Slippage,0,0,"Коммент",Magic,0,Blue));
        {
         Print("Открыта Позиция BUY");
              {
               if(Forder > 0)
                 {
                  TP = NormalizeDouble((Ask+TakeProfit*_Point+OrderSwap()+OrderCommission()),_Digits);
                  Forder = OrderModify(Forder,OrderOpenPrice(),0,TP,0);
                 }Print("Ордер Модифицирован BUY ");
              }Print("Ошибка Модификации Ордера BUY");
        }
       }Print("Ошибка Открытия Позиции BUY");
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
//Открытие позиции Sell      
    if (body < 0)
       {
        Forder = (OrderSend(_Symbol,OP_SELL,Lot,Bid,Slippage,0,0,"Коммент Sell",Magic,0,Red));
        {
         Print("Открыта Позиция SELL");
              {
               if(Forder > 0)
                 {
                  TP = NormalizeDouble((Bid-TakeProfit*_Point+OrderSwap()+OrderCommission()),_Digits);
                  Forder = OrderModify(Forder,OrderOpenPrice(),0,TP,0);
                 }Print("Ордер Модифицирован SELL ");
              }Print("Ошибка Модификации Ордера SELL");
        }
       }Print("Ошибка Открытия Позиции Sell");
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
   }
 
Alexander Avksentyev #:

下午好。我正在学习写代码,我有一个问题。测试器中的代码运行,打开一个交易,仅此而已。价格没有变化,一切都停在原地。

谁不介意,请指教。

Ask+TakeProfit*_Point+OrderSwap()+OrderCommission()

你如何在价格中加入交换和佣金?

 
MakarFX #:

你如何在价格中加入交换和佣金?

我怎么做呢?)

(((Ask+TakeProfit*_Point+OrderSwap()+OrderCommission()*_Point))

你认为这是个问题吗?

 
如何使OnTimer功能中的注释 或打印在可视化过程中在测试器中发挥作用?
 
Alexander Avksentyev #:

我怎么会知道怎么算)。

你认为这就是问题所在吗?

首先,当你打开互换时,没有互换。

其次,让我们假设佣金为1美元,你在1.32500的英镑上开了一个订单

你加上(TakeProfit)200*_Point和(Commission)1美元,你最终得到了2.32700的收益 ...那会是什么年代呢?

 
Ivan Butko 评论 或打印在可视化过程中的日志中发挥作用?
将onTimer添加到onTick
 
MakarFX #:
将onTimer添加到onTick

谢谢你

 
Alexander Avksentyev #:

我怎么会知道怎么算)。

你认为这就是问题所在吗?

不,这是不对的。


有了OrderModify,这就更正确了。

而且最好是作为一个单独的区块。

if (OrderSelect(Forder, SELECT_BY_TICKET))
  {
  TP = NormalizeDouble((Ask+TakeProfit*_Point),_Digits);
  if(OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0)
    Print("Ордер Модифицирован BUY "); 
  else 
    Print("Ошибка Модификации Ордера BUY = ",GetLastError());
  }
 
Alexander Avksentyev #:

我怎么会知道怎么算)。

你认为这就是问题所在吗?

我不认为这是问题所在,只是不对。至于测试者冻结的问题,你最好把整个代码贴出来,我们再看看。

OrderCommission()*_Point

这也是不对的。

_点是小数位,不以任何方式转化为点
 
MakarFX #:

我不认为这是问题所在,只是不对。至于测试者冻结的问题,你最好把整个代码贴出来看看。

这也是不对的。

_点是小数位,不以任何方式转化为点
int      Login = 4950287;
datetime time  = D'2022.01.01 00:00:00';
string   name  = "AutoP_v.3.0";
datetime time1 = 0;
double   price, TP, lastlot, minlot;
int      Forder;

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
    {
     if(AccountNumber() != Login)
       {
        int close = MessageBox("Неверный номер счёта","Ошибка",MB_OK|MB_ICONSTOP);
        return(INIT_FAILED);
       }else (AccountNumber() == Login);
             {
              int close = MessageBox("Проверка прошла успешно.Экcперт может приступить к работе.","Инициализация",MB_OK|MB_ICONEXCLAMATION);
             }
 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//  
     if (TimeCurrent() > time)
        {
         int close = MessageBox("Время работы закончилось!!!","Время работы",MB_OK|MB_ICONSTOP);
         return(INIT_FAILED);
        }else(TimeCurrent() < time);
             {
              int close = MessageBox("Проверка времени работы прошла успешно.Эксперт может приступить к работе!","Время работы",MB_OK|MB_ICONEXCLAMATION);
             }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
     if(Digits == 3 || Digits == 5)
       {
        TakeProfit      *=10;
        TrailStart      *=10;
        TrailDist       *=10;
        TrailStep       *=10;
        TrailTakeProfit *=10;
        Step            *=10;
        Slippage        *=10;
       }
       return(INIT_SUCCEEDED);
    }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    double body = Close[1] - Open[1];
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
//Открытие позиции Buy
    if (body > 0)
       {
        Forder = (OrderSend(_Symbol,OP_BUY,Lot,Ask,Slippage,0,0,"Коммент",Magic,0,Blue));
        {
         Print("Открыта Позиция BUY");
              {
               if(Forder > 0)
                  if(OrderSelect(Forder, SELECT_BY_TICKET))
                    {
                     TP = NormalizeDouble((Ask+TakeProfit*_Point),_Digits);
                     if (OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0))
                        Print("Ордер Модифицирован BUY "); 
                     else 
                        Print("Ошибка Модификации Ордера BUY = ",GetLastError());
                     }
               }
         }Print("Ошибка Открытия Позиции BUY");
       }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
//Открытие позиции Sell      
    if (body < 0)
       {
        Forder = (OrderSend(_Symbol,OP_SELL,Lot,Bid,Slippage,0,0,"Коммент Sell",Magic,0,Red));
        {
         Print("Открыта Позиция SELL");
              if (Forder > 0)
                 if(OrderSelect(Forder, SELECT_BY_TICKET))
                   {
                    TP = NormalizeDouble((Bid-TakeProfit*_Point),_Digits);
                    if (OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0))
                     Print("Ордер Модифицирован SELL "); 
                    else 
                     Print("Ошибка Модификации Ордера SELL = ",GetLastError());
                   }
         }
        }Print("Ошибка Открытия Позиции BUY");}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
//---
   double ret=0.0;
//---

//---
   return(ret);
  }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
int CountTrades()
{
 int count = 0;
  for(int i = OrdersTotal()-1; i>=0; i++ )
     {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {
          if (OrderSymbol() == _Symbol && OrderMagicNumber() == Magic)
             {
              count++;
             }
         }
     }return (count);
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//


这一切都在那里。谢谢你的帮助。