Increment take profit and Lot size

 

Hello I have written this piece of code into my EA but it's not working kindly help me correct the bug and make it function well: 

Below are the the conditions under which the function should follow: 

Every time a multiple of "n_op" successive loss-making operations is reached, the EA increases both the lot and the TP. If e.g. n_op=5 and we have just closed the fourth trade at a loss, the fifth trade will have tp and lot as follows set Y = (number of subsequent losing operations +1) / n_op. When Y is an integer we apply the lot and TP change to the trade we are opening, holding and using the Y value as follows lot: lot_start + lot_incr x Y tp: opening quota + take_profit x take_profit_multiplier x Y.

Belo is also my written code though not working. Help me solve this as per the conditions. Thank you.

void UpdateLotAndTP(int successiveLosses)
  {
     double y = (successiveLosses + 1) / n_op;
     
     if(y >= 1 && (int)y == y)
       {
          double newLot = lotto_inizio + lotto_incr * y;
          int newTP = (take_profit * Point) + (take_profit_multplier * take_profit) * y;
          
           lotto_inizio = newLot;
           take_profit = newTP;
       }
  }
//+------------------------------------------------------------------+
int  countSuccessiveLosses()
  {
      int consecutiveLosses = 0;
      int totalOrders = OrdersHistoryTotal();
      
      for(int i = totalOrders - 1; i >= 0; i--)
         {
             if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))continue;
             if(OrderSymbol() != Symbol())continue;
             
             if(OrderProfit() < 0)
               {
                  consecutiveLosses++;
               }
             else
               {
                  break;
               }  
         }
      return consecutiveLosses;   
  }
 
Ernest Akoyi:

Hello I have written this piece of code into my EA but it's not working kindly help me correct the bug and make it function well: 

Below are the the conditions under which the function should follow: 

Every time a multiple of "n_op" successive loss-making operations is reached, the EA increases both the lot and the TP. If e.g. n_op=5 and we have just closed the fourth trade at a loss, the fifth trade will have tp and lot as follows set Y = (number of subsequent losing operations +1) / n_op. When Y is an integer we apply the lot and TP change to the trade we are opening, holding and using the Y value as follows lot: lot_start + lot_incr x Y tp: opening quota + take_profit x take_profit_multiplier x Y.

Belo is also my written code though not working. Help me solve this as per the conditions. Thank you.

I’m 85% sure the function for consecutive loses does not truly return the correct number of consecutive losses 
 

MODE_TRADES is used to search the open trades only, right?

from mt4 documentation...

OrderSelect

pool=MODE_TRADES

[in]  Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values:

MODE_TRADES (default)- order selected from trading pool(opened and pending orders),
MODE_HISTORY - order selected from history pool (closed and canceled order).

 
Revo Trades #:
MODE_TRADES is used to search the open trades only, right?

I am new to programming so what option should I use

 
Revo Trades #:
MODE_TRADES is used to search the open trades only, right?

This is true kindly help me solve this

 
Ernest Akoyi #:

This is true kindly help me solve this

OrderSelect

pool=MODE_TRADES

[in]  Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values:

MODE_TRADES (default)- order selected from trading pool(opened and pending orders),
MODE_HISTORY - order selected from history pool (closed and canceled order).

 
Chioma Obunadike #:
I’m 85% sure the function for consecutive loses does not truly return the correct number of consecutive losses 

Sure kindly help me solve this I am a newbie in progmamming

 
Revo Trades #:
OrderSelect

pool=MODE_TRADES

[in]  Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values:

MODE_TRADES (default)- order selected from trading pool(opened and pending orders),
MODE_HISTORY - order selected from history pool (closed and canceled order).

You mean I should use MODE_HISTORY instead

 
Your code will only report the total number of losses. if you want just the consecutive losses, then you will need to search for order by date first. And I suggest that you search codebase. There will be some scripts or codes in there that are already made to do what you want.
 
Revo Trades #:
Your code will only report the total number of losses. if you want just the consecutive losses, then you will need to search for order by date first. And I suggest that you search codebase. There will be some scripts or codes in there that are already made to do what you want.

Ok thank you

 
Revo Trades #: MODE_TRADES is used to search the open trades only, right?).

Open or pending.

Revo Trades #: MODE_HISTORY - order selected from history pool (closed and canceled order).

MT4:

  1. Do not assume history has only closed orders.
              OrderType() == 6, 7 in the history pool? - MQL4 programming forum #4 and #5 (2017)

  2. Do not assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012)
              Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020)

  3. Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
              "balance" orders in account history - Day Trading Techniques - MQL4 programming forum (2017)

    Broker History
    FXCM
    Commission - «TICKET»
    Rollover - «TICKET»

    >R/O - 1,000 EUR/USD @0.52

    #«ticket»  N/A
    OANDA
    Balance update
    Financing (Swap: One entry for all open orders.)