Tutte le domande dei nuovi arrivati su MQL4 e MQL5, aiuto e discussione su algoritmi e codici - pagina 1394

 
Caro Watchmen, chi lo sa.
è possibile ottenere dati da mt5 per esempio ad un sito web o qualche sistema per l'analisi https://www.mql5.com/ru/docs/integration/python_metatrader5
c'è un api simile per ottenere dati da mt4 senza usare EA?
Документация по MQL5: Интеграция / MetaTrader для Python
Документация по MQL5: Интеграция / MetaTrader для Python
  • www.mql5.com
MetaTrader для Python - Интеграция - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Se avete un Goko, mi piacerebbe vedere il codice di come scriverlo.
 
Tenimagalon:
Se ne avete uno, mi piacerebbe vedere il codice di come farlo.

Cattura

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:

Cattura

Ciao, ho provato il codice - non si chiude per qualche motivo

Immagine 5674

 
SanAlex:

Ciao, ho provato il codice - non si chiude per qualche motivo


Sul profitto totale, non separatamente....
 
SanAlex:

Ciao, ho provato il codice - non si chiude per qualche motivo.


L'ho fatto così, funziona!

//+------------------------------------------------------------------+
//|                                             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:
Utile totale, non separato....

Oh, capisco, allora mi scuso!

È così che ho sbagliato.

//+------------------------------------------------------------------+
//| 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:

Beh, ecco, allora mi scuso!

È così che ho sbagliato.

Eccola qui, pronta per la battaglia!!!

//+------------------------------------------------------------------+
//|                                             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:

Eccola qui, pronta per la battaglia!!!

Perché imbrogliare?

Basta mettere il simbolo giusto qui

Open_Pr(Symbol())

e tutto andrà bene.

P.S. Sasha, non hai contato swap e commissioni.

 

MakarFX:

Perché imbrogliare?

Metti il simbolo giusto qui.

e tutto andrà bene.

P.S. Sasha, non hai tenuto conto di swap e commissioni

Mi sono abituato a tali impostazioni - e per quanto riguarda le commissioni e gli swap - sono tutte sciocchezze, mi interessa il profitto - ho impostato 100, lascio che chiuda per me a 90 e va anche bene - ma a volte chiude anche a 110

Non so che tipo di azione e come il broker la chiude ma la funzione funziona in base al set (importo) nelle impostazioni.

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

per esempio ho messo 5 nelle impostazioni - ha chiuso 5.20

Immagine 567469

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

o un altro esempio - avevo specificato nelle impostazioni che su tutte le coppie dove Expert Advisor è(hanno tutti le stesse impostazioni) per un profitto totale di 70 000 ho chiuso tutto - ho finito con 15 perdite

Immagine 777469

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

Ho il sospetto che non tutti capiscano di cosa stiamo parlando. - Per quanto riguarda il profitto complessivo, è una cosa - ma il profitto su ogni coppia è diverso. Devi mettere un Expert Advisor su ogni coppia.

come questo!!!

Immagine 777469 ex.

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

Quando la funzione lavora sul profitto totale, cambierà il modello su tutti i grafici aperti contemporaneamente.

Puoi creare il tuo modello, dargli un nome - usarlo come un Expert Advisor con un nuovo prezzo o qualsiasi cosa tu voglia.

Motivazione: