MQL4 ve MQL5 ile ilgili herhangi bir acemi sorusu, algoritmalar ve kodlar hakkında yardım ve tartışma - sayfa 1705

 

Selamlar! Senaryo istediğim gibi çalışıyor.

 //+------------------------------------------------------------------+
//|                                                       Око_15.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link        " https://www.mql5.com "
#property version    "1.00"
#property strict
//#include <OOP_CLibArr_01.mqh>
struct Gass
  {
   int                mag;
   double             prof;
  };
Gass plus[]= {{ 0 },{ 0 }};
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class Ohistory
  {
public :
                     Ohistory(
       string         _sy = "" ,
       int            _op =- 1 ,
       int            _mn =- 1 ,
       datetime       _dt = 0
   )
     {
       int k= 3 ;
      GetProfit_His(_sy, _op, _mn, 0 );
       Alert ( "Конструктор" , " k =" ,k);
     }
                    ~Ohistory() { Alert ( "Деструктор" ); }

   double               inits(Gass& us[], int _magik, datetime _zeit)
     {
       double pro=GetProfit_His( Symbol (), - 1 , _magik, _zeit);
       for ( int i= 0 ; i< ArraySize (us); i++)
        {
         if (us[i].mag== 3 )
            pro+=us[i].prof;
        }
       return (pro);
     }
private :
   
   double             GetProfit_His( string sy= "" , int op=- 1 , int mn=- 1 , datetime dt= 0 )
     {
       double p= 0 ;
       int     i, k=OrdersHistoryTotal();

       if (sy== "" )
         sy= Symbol ();
       for (i= 0 ; i<k; i++)
        {
         if ( OrderSelect (i, SELECT_BY_POS, MODE_HISTORY))
           {
             if ((OrderSymbol()==sy || sy== "" ) && (op< 0 || OrderType()==op))
              {
               if (OrderType()==OP_BUY || OrderType()==OP_SELL)
                 {
                   if (mn< 0 || OrderMagicNumber()==mn)
                    {
                     if (dt<OrderCloseTime())
                       {
                        p+=OrderProfit()+OrderCommission()+OrderSwap();
                       }
                    }
                 }
              }
           }
        }
       Alert ( " p =" ,p);
       return (p);
     }
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart ()
  {
   int si= 5 ,
       m= 3 ;
   ArrayResize (plus,si);
   for ( int i= 0 ; i< ArraySize (plus); i++)
      plus[i].mag=m;

   int size= ArraySize (plus);
   if (si>= 3 )
     {
       switch (size== 0 )
        {
         case 0 :
             if (plus[ 0 ].mag==m)
               plus[ 0 ].prof= 400 ;

         case 1 :
             if (plus[ 1 ].mag==m)
               plus[ 1 ].prof= 300 ;
            ;
         case 2 :
             if (plus[ 1 ].mag== 5 )
               plus[ 2 ].prof= 90 ;
        }
     }
   for ( int i= 0 ; i< ArraySize (plus); i++)
     {
       Print ( " plus[i].prof =" ,plus[i].prof);
     }
   Ohistory hi;
   Alert ( "Мужду" );

   Print ( " Сколько ???',  " ,hi.inits(plus,- 1 , D'2021.10.28' ));

  }
//+------------------------------------------------------------------+

Ama eğer hareket edersem

 class Ohistory

bir içerme dosyasına, bir dizi yapı görmeyi durdurur

 struct Gass
  {
   int                mag;
   double             prof;
  };
Gass plus[]= {{ 0 },{ 0 }};

astar

   double               inits(Gass& us[], int _magik, datetime _zeit)

böyle çalışmıyor. Bunu nasıl düzelteceğimi anlayamıyorum.

 

Lütfen bana söyle. Burada, siparişler tablosunun ve minimum-maks siparişlerin fiyatını ortam tarafından hesaplamak ve görüntülemek için iki işlev bulunmaktadır. Sonuncusunu da bir öncekine benzer şekilde kendim yazdım. İlki gerektiği gibi çalışır, ancak ikincisi bkz. min max siparişin fiyatı grafikte fiyatı göstermek istemiyor.

Lütfen hatayı bulmama yardım edin. Teşekkür ederim.

 //+----------------------------------------------------------------------------+
//| Расчет средней цены (0)-buy (1)-sell ()-all                                |
//+----------------------------------------------------------------------------+
double GetAveragePrice( int ot=- 1 )
  {
   double order_lots = 0 , order_price = 0 , avg_price = 0 ;
     {
       for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
        {
         if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
           {
             if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic)
              {
               if (OrderType()==ot||ot< 0 )
                 {
                  order_lots += OrderLots();
                  order_price += OrderOpenPrice() * OrderLots();
                 }
              }
           }
        }
     }
   avg_price = NormalizeDouble (order_price / order_lots, Digits );

   if ( ObjectFind ( 0 , "AveragePriceLine" + IntegerToString (ot))!= 0 )
       ObjectCreate ( 0 , "AveragePriceLine" + IntegerToString (ot), OBJ_HLINE , 0 , 0 , avg_price);
   else
       ObjectSetDouble ( 0 , "AveragePriceLine" + IntegerToString (ot), OBJPROP_PRICE ,avg_price);
   if (ot== 0 )
      ObjectSet( "AveragePriceLine" + IntegerToString (ot), OBJPROP_COLOR , clrLime );
   if (ot== 1 )
      ObjectSet( "AveragePriceLine" + IntegerToString (ot), OBJPROP_COLOR , clrRed );
   return (avg_price);
  }
//+----------------------------------------------------------------------------+
//| Расчет средней цены мин и макс ордеров(0)-buy (1)-sell ()-all              |
//+----------------------------------------------------------------------------+
double GetAveragePriceManMaxOrders( int ot =- 1 )
  {
   double avg_price_min_max_orders = 0 ;
     {
       for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
        {
         if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
           {
             if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic)
              {
               if (OrderType()==ot||ot< 0 )
                 {
                  avg_price_min_max_orders = NormalizeDouble ((PriceMaxOrder()*FindLastLots() + PriceMinOrder()*GetMinLotOrder())
                                             /(FindLastLots() + GetMinLotOrder()), Digits ());
                   if ( ObjectFind ( 0 , "AveragePriceLineMinMaxOrders" + IntegerToString (ot))!= 0 )
                     ObjectCreate ( 0 , "AveragePriceLineMinMaxOrders" + IntegerToString (ot), OBJ_HLINE , 0 , 0 , avg_price_min_max_orders);
                   else
                     ObjectSetDouble ( 0 , "AveragePriceLineMinMaxOrders" + IntegerToString (ot), OBJPROP_PRICE , avg_price_min_max_orders);
                   if (ot== 0 )
                     ObjectSet( "AveragePriceLineMinMaxOrders" + IntegerToString (ot), OBJPROP_COLOR , clrLime );
                  ObjectSet( "AveragePriceLineMinMaxOrders" , OBJPROP_STYLE , STYLE_DASH );
                   if (ot== 1 )
                     ObjectSet( "AveragePriceLineMinMaxOrders" + IntegerToString (ot), OBJPROP_COLOR , clrRed );
                  ObjectSet( "AveragePriceLineMinMaxOrders" , OBJPROP_STYLE , STYLE_DASH );
                 }
              }
           }
        }
     }
   return (avg_price_min_max_orders);
  }
 
EVGENII SHELIPOV # :

Lütfen bana söyle. Burada, siparişler tablosunun ve minimum-maks siparişlerin fiyatını ortam tarafından hesaplamak ve görüntülemek için iki işlev bulunmaktadır. Sonuncusunu da bir öncekine benzer şekilde kendim yazdım. İlki gerektiği gibi çalışır, ancak ikincisi bkz. min max siparişin fiyatı grafikte fiyatı göstermek istemiyor.

Lütfen hatayı bulmama yardım edin. Teşekkür ederim.

 //+----------------------------------------------------------------------------+
//| Расчет средней цены мин и макс                                             |
//+----------------------------------------------------------------------------+
double GetAveragePriceManMaxOrders()
  {
   double avg_price_min_max_orders = 0 ;
   double avg= NormalizeDouble ((PriceMaxOrder()*FindLastLots() + PriceMinOrder()*GetMinLotOrder())
                                             /(FindLastLots() + GetMinLotOrder()), Digits ());
   if (avg> 0 )
     {
      avg_price_min_max_orders = avg;
       if ( ObjectFind ( 0 , "AveragePriceLineMinMaxOrders" + IntegerToString (ot))!= 0 )
         ObjectCreate ( 0 , "AveragePriceLineMinMaxOrders" + IntegerToString (ot), OBJ_HLINE , 0 , 0 , avg_price_min_max_orders);
       else
         ObjectSetDouble ( 0 , "AveragePriceLineMinMaxOrders" + IntegerToString (ot), OBJPROP_PRICE , avg_price_min_max_orders);
       if (ot== 0 )
         ObjectSet( "AveragePriceLineMinMaxOrders" + IntegerToString (ot), OBJPROP_COLOR , clrLime );
         ObjectSet( "AveragePriceLineMinMaxOrders" , OBJPROP_STYLE , STYLE_DASH );
       if (ot== 1 )
         ObjectSet( "AveragePriceLineMinMaxOrders" + IntegerToString (ot), OBJPROP_COLOR , clrRed );
         ObjectSet( "AveragePriceLineMinMaxOrders" , OBJPROP_STYLE , STYLE_DASH );
     }
   return (avg_price_min_max_orders);
  }
 
MakarFX # :

Hayır Makar bir şey çalışmıyor

 
EVGENII SHELIPOV # :

Hayır Makar bir şey çalışmıyor

Özellikleri düzenleyin

FiyatMaxSipariş()

FindLastLots()

FiyatMinSipariş()

GetMinLotOrder()

FindLastLots()

GetMinLotOrder()

 
MakarFX # :

Özellikleri düzenleyin

FiyatMaxSipariş()

FindLastLots()

FiyatMinSipariş()

GetMinLotOrder()

FindLastLots()

GetMinLotOrder()

 //+----------------------------------------------------------------------------+
//| Определение размера лота последнего ордера                                 |
//+----------------------------------------------------------------------------+
double FindLastLots()
  {
   int oldticket;
   double oldlots = 0 ;
   ticket = 0 ;

   for ( int cnt = OrdersTotal () - 1 ; cnt >= 0 ; cnt--)
     {
       if ( OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES))
        {
         if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic)
           {
             if (OrderType() == OP_BUY || OrderType() == OP_SELL)
              {
               oldticket = OrderTicket();
               if (oldticket > ticket)
                 {
                  ticket = oldticket;
                  oldlots = OrderLots();
                 }
              }
           }
        }
     }
   return (oldlots);
  }
//+----------------------------------------------------------------------------+
//| Определение цены открытия макс лота                                        |
//+----------------------------------------------------------------------------+
double PriceMaxOrder()
  {
   double max_price = 0 ;
   max_ticket = 0 ;
     {
       for ( int cnt = OrdersTotal () - 1 ; cnt >= 0 ; cnt--)
        {
         if ( OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES))
           {
             if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic)
              {
               if (OrderType() == OP_BUY || OrderType() == OP_SELL)
                 {
                   if (OrderTicket() > max_ticket)
                    {
                     max_ticket = OrderTicket();
                     max_price = OrderOpenPrice();
                    }
                 }
              }
           }
        }
     }
   return (max_price);
  }
//+----------------------------------------------------------------------------+
//| Определение размера лота минимального ордера в сетке                       |
//+----------------------------------------------------------------------------+
double GetMinLotOrder()
  {
   double min_lot_order = 0 ;
   min_ticket= INT_MAX ;
     {
       for ( int cnt = OrdersTotal () - 1 ; cnt >= 0 ; cnt--)
        {
         if ( OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES))
           {
             if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic)
              {
               if (OrderType() == OP_BUY || OrderType() == OP_SELL)
                 {
                   if (OrderTicket() < min_ticket)
                    {
                     min_ticket = OrderTicket();
                     min_lot_order = OrderLots();
                    }
                 }
              }
           }
        }
     }
   return (min_lot_order);
  }
//+----------------------------------------------------------------------------+
//| Определение цены открытия мин лота                                         |
//+----------------------------------------------------------------------------+
double PriceMinOrder()
  {
   double min_price = 0 ;
   min_ticket= INT_MAX ;
     {
       for ( int cnt = OrdersTotal () - 1 ; cnt >= 0 ; cnt--)
        {
         if ( OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES))
           {
             if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic)
              {
               if (OrderType() == OP_BUY || OrderType() == OP_SELL)
                 {
                   if (OrderTicket() < min_ticket)
                    {
                     min_ticket = OrderTicket();
                     min_price = OrderOpenPrice();
                    }
                 }
              }
           }
        }
     }
   return (min_price);
  }
 
EVGENII SHELIPOV #:
//+----------------------------------------------------------------------------+
//| Расчет средней цены мин и макс                                             |
//+----------------------------------------------------------------------------+
double GetAveragePriceManMaxOrders()
  {
   double avg_price_min_max_orders = 0;
   if(OrdersTotal()>1)
     {
      avg_price_min_max_orders = NormalizeDouble((PriceMaxOrder()*FindLastLots() + PriceMinOrder()
                                 *GetMinLotOrder())/(FindLastLots() + GetMinLotOrder()),Digits());
      if(ObjectFind(0,"AveragePriceLineMinMaxOrders")!=0)
         ObjectCreate(0,"AveragePriceLineMinMaxOrders",OBJ_HLINE, 0, 0, avg_price_min_max_orders);
      else
         ObjectSetDouble(0,"AveragePriceLineMinMaxOrders",OBJPROP_PRICE, avg_price_min_max_orders);
     }
   return(avg_price_min_max_orders);
  }
 
Galim_V # :

Selamlar! Senaryo istediğim gibi çalışıyor.

Ama eğer hareket edersem

bir içerme dosyasına, bir dizi yapı görmeyi durdurur

astar

böyle çalışmıyor. Bunu nasıl düzelteceğimi anlayamıyorum.

Ayrıca yapıyı sınıfın üstündeki dahil edilen dosyaya aktarın.

 
Alexey Viktorov # :

Ayrıca yapıyı sınıfın üstündeki dahil edilen dosyaya aktarın.

Bu doğru!) Teşekkürler Alexey!

 
MakarFX # :

Makar, bir sorun var. Teşekkürler seviyoruz. Kendim pek güzel bir seçenek bulamadım ama işe yarıyor