MQL4 및 MQL5에 대한 초보자 질문, 알고리즘 및 코드에 대한 도움말 및 토론 - 페이지 1705

 

인사말! 스크립트는 내가 요청한 대로 작동합니다.

 //+------------------------------------------------------------------+
//|                                                       Око_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' ));

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

하지만 내가 움직이면

 class Ohistory

인클루드 파일에 구조 배열 보기를 중지합니다.

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

라인

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

이렇게 작동하지 않습니다. 이 문제를 해결하는 방법을 알 수 없습니다.

 

말해 주세요. 다음은 오더 그리드와 최소-최대 오더의 가격을 환경에 따라 계산하고 표시하는 두 가지 기능입니다. 나는 이전 것과 유사하게 마지막 것을 직접 썼다. 첫 번째는 제대로 작동하지만 두 번째는 cf. 최소 최대 주문 가격이 차트에 가격을 표시하고 싶지 않습니다.

오류를 찾을 수 있도록 도와주세요. 고맙습니다.

 //+----------------------------------------------------------------------------+
//| Расчет средней цены (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 # :

말해 주세요. 다음은 오더 그리드와 최소-최대 오더의 가격을 환경에 따라 계산하고 표시하는 두 가지 기능입니다. 나는 이전 것과 유사하게 마지막 것을 직접 썼다. 첫 번째는 제대로 작동하지만 두 번째는 cf. 최소 최대 주문 가격이 차트에 가격을 표시하고 싶지 않습니다.

오류를 찾을 수 있도록 도와주세요. 고맙습니다.

 //+----------------------------------------------------------------------------+
//| Расчет средней цены мин и макс                                             |
//+----------------------------------------------------------------------------+
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 # :

No Makar 뭔가 작동하지 않습니다

 
EVGENII SHELIPOV # :

No Makar 뭔가 작동하지 않습니다

기능 배치

가격 최대 주문()

FindLastLots()

PriceMinOrder()

GetMinLotOrder()

FindLastLots()

GetMinLotOrder()

 
MakarFX # :

기능 배치

가격 최대 주문()

FindLastLots()

PriceMinOrder()

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 # :

인사말! 스크립트는 내가 요청한 대로 작동합니다.

하지만 내가 움직이면

포함 파일에 구조 배열 보기를 중지합니다.

라인

이렇게 작동하지 않습니다. 이 문제를 해결하는 방법을 알 수 없습니다.

또한 클래스 위의 포함된 파일로 구조를 전송합니다.

 
Alexey Viktorov # :

또한 클래스 위의 포함된 파일로 구조를 전송합니다.

맞습니다!) 감사합니다, Alexey!

 
MakarFX # :

마카르, 뭔가 잘못됐어. 감사합니다. 나는 나 자신이 아주 아름다운 옵션은 아니지만 작동합니다.