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

 
Valeriy Yastremskiy:

module difference. Without module, only top zone falls into the condition. | OpenPrice - Bid |> 10*_Point opening condition

This is how the condition should be, Bid is lower than OpenPrice and no modules.

Otherwise we will get correct result if Bid is higher than OpenPrice

 
Valeriy Yastremskiy:

module difference. Without the module only the top zone falls into the condition. | OpenPrice - Bid |> 10*_Point opening condition

I don't quite get it...

Can you please make it clearer...for a beginner)

 
MakarFX:

You surprise me.


With what?
 
Alexey Viktorov:
How?
Alexey Viktorov:

From the picture you can see that OpenPrice - Bid should not be more than 10*_Point

but can be less, including negative

 
MakarFX:

but can be less, including negative

Yeah... and you get the condition with "&& > 0"

What's the question? Just like that, or for something?

 
Alexey Viktorov:

Yeah... and you get the condition with "&& > 0"

What's the question? Just like that, or for something?

I'm currently using this definition of the moment to enter the market

if(Bid < OpenPrice && Bid > OpenPrice-Х*Point)
if(Ask > OpenPrice && Ask < OpenPrice+Х*Point)

I thought there might be a way to simplify it)

 

Help optimise a piece of code for martin

The task is this:

-after the stop, a Martin will multiply the lot;

-The number of multiplications can be adjusted with function OrdersClose, and when it reaches a specified value, lot will be reset to the starting one;

- the lot volume should not be reset to the starting volume, but must be decreased sequentially in reverse order;

for example OrdersClose=5, Martin=2, lot=0.01:

we have the sequence: 0.01; 0.02; 0.04; 0.08; 0.16 (reset) 0.01; 0.01;,,,,

need: 0.01; 0.02; 0.04; 0.08; 0.16 (reset) 0.16; 0.08; 0.04; .... 0,01.

I don't have enough knowledge to solve the problem myself.

I have tried different combinations, but have not achieved the desired effect.

double LOT()
{
   int n=0;
   double OL=dLots;
   for (int j = OrdersHistoryTotal()-1; j >= 0; j--)
   {
      if (OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == iMagic)
         {
            if (OrderProfit()<0) 
            {
               if (n==0) OL=NormalizeDouble(OrderLots()*K_Martin,DigitsLot);
               n++;
               if (n>=OrdersClose) {Comment("1");return(dLots);}
            }
            else
            {
               if (n==0) {Comment("2");return(dLots);}
               else {Comment("3");return(OL);}
            }
         }
      }
   }
   return(OL);
}
 
MakarFX:

I am currently using this definition of market entry point

I thought there might be a way to simplify it)

if(Bid < OpenPrice && Bid > OpenPrice-Х*Point)
if(Ask > OpenPrice && Ask < OpenPrice+Х*Point) // цену в середину диапазона ставим

OpenPriceS=OpenPrice-X*Point/2;
if(fabs(Bid-OpenPriceS)>Х*Point){ ....   }

And Alexey has it right))

Alexey Viktorov:

This is how it should be by condition, Bid below OpenPrice and no modules.

Otherwise we get correct result if Bid is higher than OpenPrice

Fixed)

Yes, correct. Did not change the condition. Out of habit. It confuses in the picture that Bid is in the middle))))

But there second condition, entry is the same in number of conditions.

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

Help optimise a piece of code for martin

The task is this:

-after the stop, a Martin will multiply the lot;

-The number of multiplications can be adjusted with function OrdersClose, and when it reaches a specified value, lot will be reset to the starting one;

- the lot volume should not be reset to the starting volume, but must be decreased sequentially in reverse order;

for example OrdersClose=5, Martin=2, lot=0.01:

we have the sequence: 0.01; 0.02; 0.04; 0.08; 0.16 (reset) 0.01; 0.01;,,,,

need: 0.01; 0.02; 0.04; 0.08; 0.16 (reset) 0.16; 0.08; 0.04; .... 0,01.

I don't have enough knowledge to solve the problem myself.

I have tried entering different combinations, but have not achieved the desired effect.

//+------------------------------------------------------------------+
//| Расчет лота                                                      |
//+------------------------------------------------------------------+
double Lots()
  {
   double L=0;
   // если последняя закрытая сделка убыточная и лот равен стартовому
   // включаем Мартин
   if(GetInfoLastPos(2)<0&&GetInfoLastPos(1)==Lot) 
     {
      Martin=true;
     }
   // если последняя закрытая сделка убыточная и лот больше или равен максимальному
   // выключаем Мартин
   if(GetInfoLastPos(2)<0&&GetInfoLastPos(1)>=MaxMartinLot)
     {
      Martin=false;
     }
   // если последняя закрытая сделка убыточная и Мартин включен, умножаем лот
   if(Martin==true)
     {
      L=NormalizeDouble(GetInfoLastPos(1)*K_Martin,DigitsLot);
     }
   // если последняя закрытая сделка убыточная и Мартин выключен, делим лот
   if(Martin==false)
     {
      L=NormalizeDouble(GetInfoLastPos(1)/K_Martin,DigitsLot);
     }

   if(L>MAXLOT) L = MAXLOT;
   if(L<MINLOT) L = MINLOT;
   return(L);
  }
//+----------------------------------------------------------------------------+
//|  Функция возвращает по символу и магику                                    |
//|  1 - размер лота последней закрытой позиции                                |
//|  2 - размер профита с учетом комиссии и свопа последней закрытой позиции   |
//|  3 - время последней закрытой позиции                                      |
//+----------------------------------------------------------------------------+
double GetInfoLastPos(int a=1)
  {
   datetime t=0;
   double result=0,l=0,p=0,f=0;
   int i=OrdersHistoryTotal();
   for(int pos=0; pos<i; 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);
  }
 
Valeriy Yastremskiy:

And Alexei has it right))

Yes, that's right. Didn't change the condition. Out of habit. It's confusing in the picture that Bid is in the middle)))

Thanks, but it doesn't simplify my code in any way)

Reason: