Check - what have I done wrong?

 

Writing code

int GetN()
{
   int n = 0;
   for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
   {
      if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber() == Magic && OrderSymbol() == _Symbol)
      {
         bool profit = OrderType() == OP_BUY ? OrderClosePrice() > OrderOpenPrice() : OrderClosePrice() < OrderOpenPrice();
         
         bool loss = OrderType() == OP_BUY ? OrderClosePrice() < OrderOpenPrice() : OrderClosePrice() > OrderOpenPrice();
         
         bool neutral = OrderClosePrice() == OrderOpenPrice();

            SumPosOrder = OrderLots();
            Tiket2 = OrderTicket();
           }


         if(loss)
           {
            n++;
            ObchMin = ObchMin + SumPosOrder; // Подсчет общего минуса
            Minus++;                         //Подсчет отрицательных сделок
            Sdelok++;                        //Подсчет количества сделок
           }

         if(n >= MartinSteps)
           {
            n = 0;
            break;
           }

         if(profit)
           {
            ObchPlus = ObchPlus + (SumPosOrder * 0.8); // Расчет для Бинарных опционов поэтому умножаю на 0,8
           }

         if(profit && ObchPlus < ObchMin)
           {
            n++;
            Pobeda++;
            Sdelok++;
           }



         if(profit && ObchPlus > ObchMin)
           {
            ObchPlus = 0;
            ObchMin = 0;
            Pobeda++;
            Sdelok++;
            n = 0;
            break;
           }
        }
     
   return n;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double SelectVolume(int n)
  {
   return
      n == 0 ? Volume1
      : n == 1 ? Volume2
      : n == 2 ? Volume3
      : n == 3 ? Volume4
      : n == 4 ? Volume5
      : n == 5 ? Volume6
      : n == 6 ? Volume7
      : n == 7 ? Volume8
      : n == 8 ? Volume9
      : n == 9 ? Volume10
      : Volume1;
  }
//+------------------------------------------------------------------+

The task was originally:
Find the last closed order.
Check whether it closed in the plus or minus position.
Count the number of trades
Count the number of plus and minus trades.

Calculate the amount of bet.


If trade is profitable (and total minus = 0) then bet number 1
If trade is minus, then count minus and bet number 2
If plus, but minus > 0 then next bet.
But for some reason it doesn't count the number of bets and bet amount correctly...

 

e.g. string

bool neutral = OrderClosePrice() == OrderOpenPrice();

we should probably shape the operation of the algorithmic conditions like this:

   bool neutral=false;

   if(NormalizeDouble(OrderClosePrice(),_Digits) == NormalizeDouble(OrderOpenPrice(),_Digits)neutral=true;

and the other two conditions in the same vein

 

By the way, the last deal in history is not always the last deal in time.

 
Nikita Chernyshov #:

By the way, the last deal in the history is not always the last deal in time.

Yes, I removed the time sampling, but it still doesn't work yet...
Renat Akhtyamov #:

e.g. line

perhaps we should form the work of algorithmic conditions like this:

   bool neutral=false;

   if(NormalizeDouble(OrderClosePrice(),_Digits) == NormalizeDouble(OrderOpenPrice(),_Digits)neutral=true;

and the other two conditions in the same vein

I've just used this block before in other systems and it worked perfectly in this part.
but still, I'll certainly check and rewrite. I'll let you know the outcome.
 
Natalya Smirnova #:
Yes I have removed the time sampling, but it still doesn't work yet... I've just used this block before in other systems and it worked perfectly in this part.
but still, I'll certainly check and rewrite. I'll let you know the outcome.

are these variables reset somewhere?

            ObchMin = ObchMin + SumPosOrder; // Подсчет общего минуса
            Minus++;                         //Подсчет отрицательных сделок
            Sdelok++;                        //Подсчет количества сделок
 
Renat Akhtyamov #:

are these variables reset somewhere?

Yes, at startup they have a value of 0
and before completion.
 
Renat Akhtyamov #:

are these variables zeroed out somewhere?

Maybe go from the mapped one.
I will remove the collection of statistics from this function for now, and general minus and statistics in another (separate function will produce)

Writing by blocks.

Gather statistics and calculate minus and plus (minus and plus are global variables)

if(OrderSelect((OrdersHistoryTotal() - 1), SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber() == Magic && OrderSymbol() == _Symbol)
              {
               if(OrderTicket() != Tiket2)
                 {
                  bool profit1 = false;
                  if(OrderClosePrice() > 0)
                    {
                     profit1 = true;
                    }
                  bool loss1 = false;
                  if(OrderClosePrice() < 0)
                    {
                     loss1 = true;
                    }


                  SumPosOrder = OrderLots();
                  Tiket2 = OrderTicket();
                  Print(OrderCloseTime());
                 


               if(loss1)
                 {
                  ObchMin = ObchMin + SumPosOrder;
                  Minus++;
                  Sdelok++;
                 }



               if(profit1)
                 {
                  ObchPlus = ObchPlus + (SumPosOrder * 0.8);
                 }

               if(profit1 && ObchPlus < ObchMin)
                 {

                  Pobeda++;
                  Sdelok++;
                 }




               if(profit1 && ObchPlus > ObchMin)
                 {
                  ObchPlus = 0;
                  ObchMin = 0;
                  Pobeda++;
                  Sdelok++;

                 }
}


Block 2 - selection of the variable n for calculation (or rather selection) of the rate

int GetN()
  {
   int n = 0;
   for(int i = OrdersHistoryTotal() - 1; i >= 0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber() == Magic && OrderSymbol() == _Symbol)
        {
         bool profit = false;
         if(OrderClosePrice() > 0)
            profit = true;

         bool loss = false;
         if(OrderClosePrice() < 0)
            loss = true;


        }


      if(loss)
        {
         n++;
        }

      if(n >= MartinSteps)
        {
         n = 0;
         break;
        }

      

      if(profit && ObchPlus < ObchMin)
        {
         n++;
        }



      if(profit && ObchPlus > ObchMin)
        {
         n = 0;
         break;
        }
     }

   Print(n);

   return n;
  }


double SelectVolume(int n)
  {
   return
      n == 0 ? Volume1
      : n == 1 ? Volume2
      : n == 2 ? Volume3
      : n == 3 ? Volume4
      : n == 4 ? Volume5
      : n == 5 ? Volume6
      : n == 6 ? Volume7
      : n == 7 ? Volume8
      : n == 8 ? Volume9
      : n == 9 ? Volume10
      : Volume1;
  }
//+------------------------------------------------------------------+


This would probably be correct...

 

I still don't understand the logic.

How so?

bool profit = false;
         if(OrderClosePrice() > 0)
            profit = true;

         bool loss = false;
         if(OrderClosePrice() < 0)
            loss = true;

How can the close price of the order be less than zero?

BUY order is in profit if the close price is higher than the open price

here is the condition of a buy plus (excluding commissions and swap):

OrderClosePrice() > OrderOpenPrice()
If it is the other way round, that's a minus
 
Renat Akhtyamov the close price of the order be lower than zero?

BUY order is in profit if the close price is higher than the open price

here is the condition of a buy plus (excluding commissions and swap):

If it is the other way round, that's a minus

As I am writing for binary options I have done things a little differently:

if(OrderProfit() > 0)


This would probably be correct?

 
Natalya Smirnova #:

Maybe go from the mapped one.
I will remove the collection of statistics from this function for now, and the total minus and statistics in another (separate function I will produce)

Writing by blocks

Cumulative minus and plus (minus and plus are global variables)


Block 2 - selection of the variable n for calculation (or rather selection) of the rate


This would probably be correct...

I don't want to interfere and haven't even looked through your code and tips...

double SelectVolume(int n)
  {
   return
      n == 0 ? Volume1
      : n == 1 ? Volume2
      : n == 2 ? Volume3
      : n == 3 ? Volume4
      : n == 4 ? Volume5
      : n == 5 ? Volume6
      : n == 6 ? Volume7
      : n == 7 ? Volume8
      : n == 8 ? Volume9
      : n == 9 ? Volume10
      : Volume1;
  }

caught my eye. In this connection, a question: isn't it easier and more readable to use switch operator

double SelectVolume(int n)
  {
   double Volume = 0.0;
    switch(n)
    {
     case 1  :  Volume = Volume2;     break;
     case 2  :  Volume = Volume3;     break;
     case 3  :  Volume = Volume4;     break;
     case 4  :  Volume = Volume5;     break;
     case 5  :  Volume = Volume6;     break;
     case 6  :  Volume = Volume7;     break;
     case 7  :  Volume = Volume8;     break;
     case 8  :  Volume = Volume9;     break;
     case 9  :  Volume = Volume10;    break;
     default :  Volume = Volume1;     break;
    }
   return(Volume);
  }
I think it's easier to read and understand. Perhaps it works a little faster too.
 
Alexey Viktorov #:

You've already been given advice on the whole algorithm, I don't want to interfere and haven't even looked at your code and the same advice... But this

caught my eye. In this connection, a question: isn't it easier and more readable to use switch operator

I think it's easier to read and understand. Perhaps it also works a little faster.
Since I am not very experienced, your suggestion is completely new to me.
I originally did it the way I found it, it worked, so I didn't think about improving it.
You know what they say - It works - don't touch it.

But now I will certainly try to apply this method. Because it is necessary to learn and develop.

But I will only deal with my variable n now. It does not want to be counted.
always n = 0 (so far)
Reason: