Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1838

 
Andrey Sokolov #:

Yes. I made it as simple as possible, plugged it in in the app, it works.

And you call it in mql5 in TestLib context? It should be TestLib::TestClass::Inc()
 
законопослушный гражданин #:

Thank you!) Happy New Year!)

Anytime!

 
законопослушный гражданин #:

I think I've got it together, but it only works once in the tester

where did I go wrong?

The debugger is good for solving such problems. I recommend to use it

 
Vladimir Simakov #:
And you call it in mql5 in TestLib context? It should be TestLib::TestClass::Inc()

Thank you

 
законопослушный гражданин #:

seems to be assembled, but it only works once in the tester

Where did I go wrong?
// Параметры советника
input string  sParametersEA = "";     // Параметры советника
input double  Lot           = 0.01;   // Количество лотов
input double  Lotcontrol    = 0.08;   // -----  
input int     StopLoss      = 30;     // Стоп (SL)
input int     TakeProfit    = 30;     // Тейк (TP)
input int     HourPause     = 1;      // Пауза в часах
input int     Slippage      = 3;      // Проскальзование (в пунктах)
input int     Magic         = 1;      // Индентификатор советника
input double  K_Martin1     = 0.01;   // Множитель мартин 1
input double  K_Martin2     = 1.9;    // Множитель мартин 2
input double  K_Martin3     = 1.4;    // Множитель мартин 3
input int     OrdersClose   = 3;      // Ограничение лотности мартин1
input int     OrdersClose2  = 5;      // Ограничение лотности мартин2
input int     DigitsLot     = 2;      // Точность лотности
// Параметры индикатора
input string  sParametersMA = "";     // Параметры индикатора
input int     PeriodMA      = 14;     // Период мувинга
input int     MovingShift   = 1;      // Сдвиг мувинга
// Глобальные переменные
datetime Start=0,newbar;
double dMA;
double MaxMartinLot;
double MaxMartinLot2;
//+-----------------------------------------------------------------------------------------------+
int OnInit()
  {
Start          = TimeCurrent();
MaxMartinLot   = Lot*MathPow(1.4,OrdersClose);
MaxMartinLot2  = Lot*MathPow(K_Martin2,OrdersClose2);
int Y          = 15;
DrawLABEL("nextlot",1,5,Y,clrLime,""); 
Y += 20;
DrawLABEL("currentlot",1,5,Y,clrLime,"");
Y += 30;
return(INIT_SUCCEEDED);
  }
//+-----------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+-----------------------------------------------------------------------------------------------+
void OnTick()
  {
// Получим значение индикатора
   dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 0); // MODE_SMA - простое усреднение , значение 0. PRICE_CLOSE- цена закрытия, значение 0.
// выключаем торговлю      
   if (GetInfoLastPos(1)>=Lotcontrol)
     {
      Start=GetInfoLastPos(3)+(HourPause*60*60);
     }
// Если нет открытых ордеров, то входим в условие
   if((CountOrders()==0)&& Start<=TimeCurrent())
     {
// Если появился сигнал на покупку, то откроем ордер на покупку
      if(bSignalBuy() == true)
         vOrderOpenBuy();

// Если появился сигнал на продажу, то откроем ордер на продажу
      if(bSignalSell() == true)
         vOrderOpenSell();
     }
// Пишем какой лот текущий и какой следующий
      DrawLABEL("nextlot",1,5,0,Color1(),StringConcatenate("CURRENT LOT: ",DoubleToStr(LOT(),2)));
      DrawLABEL("currentlot",1,5,0,Color2(),StringConcatenate("NEXT LOT: ",DoubleToStr(LOT(),2))); 
  }
//+----------------------------------------------------------------------------+
//|  Функция возвращает по символу и магику                                    |
//|  1 - размер лота последней закрытой позиции                                |
//|  2 - размер профита с учетом комиссии и свопа последней закрытой позиции   |
//|  3 - время последней закрытой позиции                                      |
//+----------------------------------------------------------------------------+
double GetInfoLastPos(int a=1)
  {
   datetime t=0;
   double result=0,l=0,p=0,f=0;
   int i=OrdersHistoryTotal()-1;
   for(int pos=i;pos>=0;pos--)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL)
              {
               if(t<OrderCloseTime()) {t=OrderCloseTime(); l=OrderLots(); p=OrderProfit()+OrderCommission()+OrderSwap();}
              }
           }
        }
     }
   if(a==1) {result=l;} else
   if(a==2) {result=p;} else
   if(a==3) {result=(double)t;}
   else     {result=0;}
   return(result);
  }
 
Tretyakov Rostyslav #:

Thank you.

And Iused a void to getInfoLastPos()....

 

Good afternoon!!! Happy New Year to all!!!

Here is a screenshot showing the display of average price of orders in the grid

Here is the code for creating a horizontal line of average price and inscription

//+----------------------------------------------------------------------------+
//| Расчет среденй цены (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);
   ObjectCreate("signal4",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("signal4",OBJPROP_XDISTANCE,100);
   ObjectSet("signal4",OBJPROP_YDISTANCE,260);
   ObjectSetText("signal4","- Средняя цена сетки ордеров на покупку",14,"Times New Roman", clrLime);
   if(ot==1)
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrRed);
   ObjectCreate("signal3",OBJ_LABEL,0, 0, 0, 0, 0);
   ObjectSet("signal3",OBJPROP_XDISTANCE, 100);
   ObjectSet("signal3",OBJPROP_YDISTANCE, 280);
   ObjectSetText("signal3", "- Средняя цена сетки ордеров на продажу", 14, "Times New Roman", clrRed);
   return(avg_price);
  }

Here is the code that removes the horizontal line

//-------------------------------------------------------------------+  Команда на удаление линий отображающую среднюю цену
   if(CountTrade() == 0)
     {
      if(ObjectFind(0,"AveragePriceLine" + IntegerToString(0))==0&&CountTrade(0)<1)//для бай
        {
         ObjectDelete(0,"AveragePriceLine"+ IntegerToString(0));
        }
      if(ObjectFind(0,"AveragePriceLine" + IntegerToString(1))==0&&CountTrade(1)<1)//для селл
        {
         ObjectDelete(0,"AveragePriceLine" + IntegerToString(1));
        }
     }

Please help to redo the code so that the inscription appears above the line and is removed when the line is removed

Thanks for your help.

 
EVGENII SHELIPOV #:

Please help me rewrite the code so that

If youcan help, what exactly is it that you can't do?

 
Andrey Sokolov #:

If youcan help, what exactly is it that you can't do?

Let's not be rude. If I knew how to do it, I wouldn't have come here.

The question is very simple you need to know the coordinates of the inscription with reference to the horizontal line as I do not know how to calculate it.


 
EVGENII SHELIPOV #:

Let's not be rude. If I knew how to do it, I wouldn't have come here.

The question is very simple need to know the coordinates of the inscription with reference to the horizontal line as I do not know how to calculate it.


What do you mean, " Let's not be rude"? Did I write "help" and not "do me".

Reason: