Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 710

 
borilunad:
You can do this: Km=MathMax(i/r,Point); // with division, and it won't be zero!

wow!!! Head! Thank you very much!!! After the extremely tedious four-hour work I finally found how to stick this function so that the tester did not swear) came out about the following.

double a=iLowest(Symbol(),PERIOD_M1,MODE_LOW,m1,0); //return bar index for n-periods with min price

double b=iHighest(Symbol(),PERIOD_M1,MODE_HIGH,m1,0); //return the bar index for n-periods with max price

double MinLOWPeriod=iLow(Symbol(),PERIOD_M1,a); //return the bar price value with the lowest price

double MaxHIGHPeriod=iHigh(Symbol(),PERIOD_M1,b); //return the price of the bar with the highest price

double PriceCloseBar=iClose(Symbol(),PERIOD_M1,0); //return the close price of the last bar

double xm1=(PriceCloseBar-MinLOWPeriod)/(MathMax((MaxHIGHPeriod-MinLOWPeriod)/100,Point));

Print(xm1);

and also made the formula smoother;)

Thank you!

 
Жалко, кнопочки "Спасибо" нету(
 

sponger:

It's a pity there's no "Thank you" button.

But there is another magic button: SRC, when you use it, the code (or its fragments) get neater and more readable in the post of the questioner, adding a plus to the questioner's karma and increasing the number of those who will look at this code and decide to help.

Just shhhh. . So in the secret knowledge of the magic of the SRC button are devoted, in general, only those who read the sacred texts of the manuals on the site. For example, such as these.

And success to you here in mastering the secret knowledge in solving further questions!
 
sponger:

wow!!! Head! Thank you very much!!! After extremely tedious four-hour work I finally found how to stick this function so that the tester did not swear) came out approximately the following.

double xm1=(PriceCloseBar-MinLOWPeriod)/(MathMax((MaxHIGHPeriod-MinLOWPeriod)/100,Point));

Print(xm1);

and also made the formula smoother;)

Thanks!

You're welcome! And I agree withDiPach 100%! Good luck!
 
void ChagingLots(int Magic,double percent,double lot)
{ 
  double t=2,             //коэффициент при делении,для того чтобы узнать цену закрытия
         PriceCl,         //цена закрытия части ордера
         takeprofit;      //нужна для вычислений
  int count = 0,order;
  for(int i=OrdersTotal()-1;i>=0;i--)    //пробегаемся по массиву ордеров
     {
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
          {
            if(OrderSymbol()==Symbol() && OrderMagicNumber() == Magic)
              {
                 if(OrderType()== OP_BUY)        //если ордер на покупку
                 {
                 takeprofit = OrderTakeProfit();   //вычисляем тейк ордера
                 PriceCl    = NormalizeDouble((takeprofit + OrderOpenPrice())/t,Digits);  //примерную цену закрытия
                 order = OrderTicket();    //получили ордер
                 if(Bid>PriceCl) //если текущая цена оказалась выше нашей цены ,то закрываем часть ордера
                 {OrderClose(order,NormalizeDouble(lot*percent/100,2),PriceCl,3);} 
                 }
                 if( OrderType()== OP_SELL )// для продажи аналогично
                 {
                   takeprofit = OrderTakeProfit();
                   PriceCl    = NormalizeDouble((takeprofit + OrderOpenPrice())/t,Digits);
                   order = OrderTicket();
                   if(Bid<PriceCl)
                   {OrderClose(order,NormalizeDouble(lot*percent/100,2),Bid,3);}
                 }
              }
          }
     }
     
}

Hi all)

I tried to write a function to close a part of the position, but when I run in the tester, 138 is popping up an error, I do not understand what the problem. Help please.

Here is an Expert Advisor in which this function should work)

Files:
zigzagx.mq4  16 kb
 
LBatters:

Hi all)

I tried to write a function to close a part of the position, but when I run in the tester, 138 is popping up an error, I do not understand what the problem. Help please.

I have an EA where this function should work.)

Did you look in the Dock, what this error means! From there you will find the answer!

At what price does buy close? And the Sell?

 

Greetings all
My question is more related to methaquotes developers, but nevertheless...


Сколько баров храниться история? Т.е. с каким максимальным по сдвигу баром можно работать?

Code:

Print(iMA(Symbol(),0,14,0,MODE_SMA,PRICE_CLOSE,1200));

Print(iClose(Symbol(),0,1200));

When testing this shift, the terminal outputs 0.0 for 2 cases

But

Print(iMA(Symbol(),0,14,0,MODE_SMA,PRICE_CLOSE,120));

Print(iClose(Symbol(),0,120)); 

In the test everything works

Is it possible to somehow adjust the size of available history? Maybe someone has faced such a problem and already found a solution?
Thanks in advance!

 

Hi all.

I am trying to update a simple trawl EA by Kim to delete pending orders after closing all market orders, it fails(

I have added function to delete pending orders:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 28.11.2006                                                     |
//|  Описание : Удаление ордеров                                               |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любой ордер)                    |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
void DeleteOrders(string sy="", int op=-1, int mn=-1) {
  bool fd;
  int  err, i, it, k=OrdersTotal(), ot;

  if (sy=="0") sy=Symbol();
  for (i=k-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      ot=OrderType();
      if (ot>1 && ot<6) {
        if ((OrderSymbol()==sy || sy=="") && (op<0 || ot==op)) {
          if (mn<0 || OrderMagicNumber()==mn) {
            for (it=1; it<=NumberOfTry; it++) {
              if (!IsTesting() && (!IsExpertEnabled() || IsStopped())) break;
              while (!IsTradeAllowed()) Sleep(5000);
              fd=OrderDelete(OrderTicket(), clDelete);
              if (fd) {
                if (UseSound) PlaySound(SoundSuccess); break;
              } else {
                err=GetLastError();
                if (UseSound) PlaySound(SoundError);
                Print("Error(",err,") delete order ",GetNameOP(ot),": ",ErrorDescription(err),", try ",it);
                Sleep(1000*5);
              }
            }
          }
        }
      }
    }
  }
}

I faced another problem which I should not be able to solve because I'm not too good at coding.

I guess I should write a condition such as:

This is just an example from another EA.

   if(AccountProfit()<-TargetLoss || AccountProfit()>TargetProfit) 
     {
      ClosePosFirstProfit();
      if(DeleteOrders) DeleteOrders();
     }


Please help me out.

Files:
tral.mq4  19 kb
 
Gentlemen MQL-4 connoisseurs, how can MQ4 code unload and load an indicator again?
 
LBatters:

Hi all)

I tried to write a function to close a part of the position, but when I run in the tester, 138 is popping up error. I do not understand what the problem. Please help.

Here is an EA where this function should work)

138 - "Requested price is out of date or bid and ask are mixed up".

The open/close price cannot be recalculated, because it is there, and here is the problem(you need to request the price and give it a value using MarketInfo, and rename this one to another variable):

                 PriceCl    = NormalizeDouble((takeprofit + OrderOpenPrice())/t,Digits);  //примерную цену закрытия
                 order = OrderTicket();    //получили ордер
                 if(Bid>PriceCl) //если текущая цена оказалась выше нашей цены ,то закрываем часть ордера
                 {OrderClose(order,NormalizeDouble(lot*percent/100,2),PriceCl,3);}
Reason: