Quaisquer perguntas de recém-chegados sobre MQL4 e MQL5, ajuda e discussão sobre algoritmos e códigos - página 1394

 
Caros Watchmen, quem sabe.
é possível obter dados do mt5, por exemplo, para um site ou algum sistema para análise https://www.mql5.com/ru/docs/integration/python_metatrader5
existe uma api similar para obter dados do mt4 sem usar a EA?
Документация по MQL5: Интеграция / MetaTrader для Python
Документация по MQL5: Интеграция / MetaTrader для Python
  • www.mql5.com
MetaTrader для Python - Интеграция - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Se você tem uma Goko, eu gostaria de ver o código de como escrevê-la.
 
Tenimagalon:
Se você tiver um, eu gostaria de ver o código de como fazê-lo.

Apanhe

double MyProfit=1000; // уровень профита
//+--------------------------------------------------------------------------------------------------------------------+
//| Expert tick function                                                                                               |
//+--------------------------------------------------------------------------------------------------------------------+
void OnTick()
  {
//---
   if(Open_Pr()>MyProfit)DelOrders();
//---
  }
//+--------------------------------------------------------------------------------------------------------------------+
//|  Суммарный профит в валюте депозита открытых позиций                                                               |
//+--------------------------------------------------------------------------------------------------------------------+
double Open_Pr(string sy="")
  { double p = 0;
   if (sy == "0") sy = Symbol();
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS)==true)
        {
         if(OrderSymbol() == sy || sy == ""){p+=OrderProfit()+OrderSwap()+OrderCommission();}
        }
     }
   return(p);
  }
//+--------------------------------------------------------------------------------------------------------------------+
//| Функция удаления и закрытия ордеров                                                                                |
//+--------------------------------------------------------------------------------------------------------------------+
void DelOrders()
  {
   while(true)
     {
      bool find_order=false;
      //----
      for(int pos=OrdersTotal()-1;pos>=0;pos--)
      if(OrderSelect(pos,SELECT_BY_POS)==true)
      if(OrderSymbol()==_Symbol)
        {
         find_order=true;
         //----
         if(OrderType()==OP_BUY)
           {
            RefreshRates(); int slip=(int)(((Ask-Bid)/Point)*2);
            if(OrderClose(OrderTicket(),OrderLots(),Bid,slip,clrBlue)==false){}
           }
         //----
         if(OrderType()==OP_SELL)
           {
            RefreshRates(); int slip=(int)(((Ask-Bid)/Point)*2);
            if(OrderClose(OrderTicket(),OrderLots(),Ask,slip,clrRed)==false){}
           }
         //----
         if(OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)
         if(OrderDelete(OrderTicket(),clrRed)==false){}
         //----
         if(OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT)
         if(OrderDelete(OrderTicket(),clrBlue)==false){}
         Alert("Все ордера закрыты!");
        } 
      if(find_order==false) Alert("Нет ордеров!");break;
     } 
  }
//+--------------------------------------------------------------------------------------------------------------------+
 
MakarFX:

Apanhe

Olá! Eu tentei o código - ele não fecha por alguma razão

Foto 5674

 
SanAlex:

Olá! Eu tentei o código - ele não fecha por alguma razão


Sobre o lucro total, não separadamente....
 
SanAlex:

Olá! tentei o código - não fecha por alguma razão.


Eu fiz assim. Está funcionando!

//+------------------------------------------------------------------+
//|                                             MakarFX_MyProfit.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
input string   t2="------------ Exchange TP SL --------"; //
input double   InpTProfit       = 10;            // Exchange TP уровень профита
input double   InpStopLoss      = 1000000;       // Exchange SL
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   ProfitOnTick();
  }
//+------------------------------------------------------------------+
//| Суммарный профит в валюте депозита открытых позиций              |
//+------------------------------------------------------------------+
bool ProfitOnTick(void)
  {
   bool res=false;
   double PROFIT_BUY=0.00;
   double PROFIT_SELL=0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
           {
            PROFIT_BUY=PROFIT_BUY+NormalizeDouble(OrderProfit(),2);
           }
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
           {
            PROFIT_SELL=PROFIT_SELL+NormalizeDouble(OrderProfit(),2);
           }
        }
     }
   int Close_ticketb=0;
   int totalb=OrdersTotal();
   int b = 0;
   for(b = totalb; b >=0; b--)
     {
      if(OrderSelect(b,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         //OrderSelect(i,SELECT_BY_POS);
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
           {
            if(PROFIT_BUY<-InpStopLoss || PROFIT_BUY>=InpTProfit)
              {
               Close_ticketb = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_BID),5);
               PlaySound("ok.wav");
              }
           }
        }
      res=true;
     }
   int Close_tickets=0;
   int totals=OrdersTotal();
   int s = 0;
   for(s = totals; s >=0; s--)
     {
      if(OrderSelect(s,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
           {
            if(PROFIT_SELL<-InpStopLoss || PROFIT_SELL>=InpTProfit)
              {
               Close_tickets = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_ASK),5);
               PlaySound("ok.wav");
              }
           }
        }
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
 
Vladislav Andruschenko:
Lucro total, não separado....

Bem, aí está! Então eu peço desculpas!

Foi assim que eu estraguei tudo.

//+------------------------------------------------------------------+
//| Check  closing                                                   |
//+------------------------------------------------------------------+
bool ProfitTarget(void)
  {
   bool res=false;
   if(AccountInfoDouble(ACCOUNT_EQUITY)>=TargetProfit)
     {
      CloseAllOrders();
      Sleep(SLEEPTIME*1000);
      CloseAllOrders();
      ExpertRemove();
      DeleteChart();
      PlaySound("expert.wav");
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
 
SanAlex:

Ah, estou vendo! Então peço desculpas!

Foi assim que eu estraguei tudo.

Aqui está, pronto para a batalha!!!

//+------------------------------------------------------------------+
//|                                             MakarFX_MyProfit.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include <stdlib.mqh>
//--- Inputs
input string   t="------------- Balans Parameters -----"; //
input string   Template         = "ADX";         // Имя шаблона(without '.tpl')
input double   TargetProfit     = 1000000;       // Баланс + Прибыль(прибавить к балансу)
input string   t2="------------ Exchange TP SL --------"; //
input double   InpTProfit       = 10;            // Exchange TP уровень профита
input double   InpStopLoss      = 1000000;       // Exchange SL
//---
uint   SLEEPTIME        = 1;
bool   CloseOpenOrders  = true;
double Price[2];
ENUM_TIMEFRAMES TimeFrame; // Change TimeFrame - Current = dont changed
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   ProfitOnTick();
   ProfitTarget();
  }
//+------------------------------------------------------------------+
//| Суммарный профит в валюте депозита открытых позиций              |
//+------------------------------------------------------------------+
bool ProfitOnTick(void)
  {
   bool res=false;
   double PROFIT_BUY=0.00;
   double PROFIT_SELL=0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
           {
            PROFIT_BUY=PROFIT_BUY+NormalizeDouble(OrderProfit(),2);
           }
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
           {
            PROFIT_SELL=PROFIT_SELL+NormalizeDouble(OrderProfit(),2);
           }
        }
     }
   int Close_ticketb=0;
   int totalb=OrdersTotal();
   int b = 0;
   for(b = totalb; b >=0; b--)
     {
      if(OrderSelect(b,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         //OrderSelect(i,SELECT_BY_POS);
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
           {
            if(PROFIT_BUY<-InpStopLoss || PROFIT_BUY>=InpTProfit)
              {
               Close_ticketb = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_BID),5);
               PlaySound("ok.wav");
              }
           }
        }
      res=true;
     }
   int Close_tickets=0;
   int totals=OrdersTotal();
   int s = 0;
   for(s = totals; s >=0; s--)
     {
      if(OrderSelect(s,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
           {
            if(PROFIT_SELL<-InpStopLoss || PROFIT_SELL>=InpTProfit)
              {
               Close_tickets = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_ASK),5);
               PlaySound("ok.wav");
              }
           }
        }
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//| Check  closing                                                   |
//+------------------------------------------------------------------+
bool ProfitTarget(void)
  {
   bool res=false;
   if(AccountInfoDouble(ACCOUNT_EQUITY)>=TargetProfit)
     {
      CloseAllOrders();
      Sleep(SLEEPTIME*1000);
      CloseAllOrders();
      ExpertRemove();
      DeleteChart();
      PlaySound("expert.wav");
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
void CloseAllOrders(void)
  {
   int iOrders=OrdersTotal()-1, i;
   if(CloseOpenOrders)
     {
      for(i=iOrders; i>=0; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()<=OP_SELL) && GetMarketInfo() &&
            !OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],0))
            Print(OrderError());
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderDelete(OrderTicket()))
               Print(OrderError());
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Function..: OrderError                                           |
//+------------------------------------------------------------------+
string OrderError(void)
  {
   int iError=GetLastError();
   return(StringConcatenate("Order:",OrderTicket()," GetLastError()=",iError," ",ErrorDescription(iError)));
  }
//+------------------------------------------------------------------+
//| Function..: GetMarketInfo                                        |
//+------------------------------------------------------------------+
bool GetMarketInfo(void)
  {
   RefreshRates();
   Price[0]=MarketInfo(OrderSymbol(),MODE_ASK);
   Price[1]=MarketInfo(OrderSymbol(),MODE_BID);
   double dPoint=MarketInfo(OrderSymbol(),MODE_POINT);
   if(dPoint==0)
      return(false);
   return(Price[0]>0.0 && Price[1]>0.0);
  }
//+------------------------------------------------------------------+
//| start function                                                   |
//+------------------------------------------------------------------+
void DeleteChart(void)
  {
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   bool errTemplate;
   while(i<limit)
     {
      currChart=ChartNext(prevChart);
      if(TimeFrame!=PERIOD_CURRENT)
        {
         ChartSetSymbolPeriod(prevChart,ChartSymbol(prevChart),TimeFrame);
        }
      errTemplate=ChartApplyTemplate(prevChart,Template+".tpl");
      if(!errTemplate)
        {
         Print("Error ",ChartSymbol(prevChart),"-> ",GetLastError());
        }
      if(currChart<0)
         break;
      Print(i,ChartSymbol(currChart)," ID =",currChart);
      prevChart=currChart;
      i++;
     }
  }
//+------------------------------------------------------------------+
 
SanAlex:

Aqui está, pronto para a batalha!!!

Por que trapacear?

Basta colocar aqui o símbolo certo

Open_Pr(Symbol())

e tudo ficará bem.

P.S. Sasha, você não contou a troca e a comissão.

 

MakarFX:

Por que trapacear?

Coloque aqui o símbolo certo.

e tudo ficará bem.

P.S. Sasha, você não levou em conta a troca e a comissão

acostumei-me a tais configurações - e sobre comissões e trocas - é tudo um absurdo, eu me importo com o lucro - eu estabeleço 100, deixe-o fechar para mim a 90 e isso é bom também - mas às vezes ele também fecha a 110

não sei que tipo de ação e como o corretor a fecha, mas a função funciona com base no conjunto (quantidade) nos ajustes.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

por exemplo, eu coloquei 5 nos ajustes - fechou 5,20

Foto 567469

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

ou outro exemplo - eu tinha especificado nas configurações que em todos os pares onde está o Expert Advisor(todos têm as mesmas configurações) para um lucro total de 70 000 eu fechei tudo - acabei com 15 perdas

Foto 777469

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Tenho a suspeita de que nem todos entendem do que estamos falando. - Quanto ao lucro geral, é uma coisa - mas o lucro em cada par é diferente. Você tem que colocar um Consultor Especialista em cada par.

assim !!!!

Figura 777469, ex.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Quando a função funciona sobre o lucro total, ela mudará o padrão em todos os gráficos abertos de uma só vez.

Você pode criar seu próprio padrão, dar-lhe um nome - usá-lo como um Expert Advisor com um novo preço ou o que você quiser.

Razão: