Close only profitable trade - page 2

 
Eleni Anna Branou #:

If you leave the remaining losing trades run you will end up destroying your account, that is the problem with grid and martingale systems.

Users always hope to see the losing trades return to profit, but all that ends in a disaster.

The recipe for success is to cut losses short and let profits run, not the other way around.

I understand, what you mean, but in ranging markets is this not bad, to close only profitable trades in a basket-sum again and again, because after a while, the open looser trades become profitable.

 
Artep05:

Hello,

I search a EA similar the known EA "Close all at profit or loss".

But I want, if a predefinied level of profit (or loss) is reached, that the EA close only the profitable trades and not the other trades, which currently still in loss.

Have someone this EA?

This is the code that determines the profit and loss of a position. You only need to put your own transaction closing code.

I don’t know if my answer fits the topic?

My English is not very good, so I use Google Translate, haha, please forgive me if there are any mistakes.

bool PositionProfit(int P_Type, string P_Symbol, int P_Point, int P_Multiple, int P_Magic)
{
   for(int i = PositionsTotal() - 1; i >= 0; i--)
   {
      if(PositionGetTicket(i) <= 0)
      {
         continue;
      }
      bool L_Type   = PositionGetInteger(POSITION_TYPE)  == P_Type;
      bool L_Symbol = PositionGetString(POSITION_SYMBOL) == P_Symbol;
      bool L_Magic  = PositionGetInteger(POSITION_MAGIC) == P_Magic;
      if (L_Type && L_Symbol && L_Magic)
      {
         double L_BID       = SymbolInfoDouble(P_Symbol,SYMBOL_BID);
         double L_ASK       = SymbolInfoDouble(P_Symbol,SYMBOL_ASK);
         double L_Point     = SymbolInfoDouble(P_Symbol,SYMBOL_POINT);
         double L_OpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
         if (P_Type == POSITION_TYPE_BUY)
         {
            bool L_Condition = L_BID >= L_OpenPrice + P_Point * P_Multiple * L_Point;
            if (L_Condition)
            {
               return(true);
            }
         }
         else if (P_Type == POSITION_TYPE_SELL)
         {
            bool L_Condition = L_ASK <= L_OpenPrice - P_Point * P_Multiple * L_Point;
            if (L_Condition)
            {
               return(true);
            }
         }
      }
   }
   return (false);
}

bool PositionLoss(int P_Type, string P_Symbol, int P_Point, int P_Multiple, int P_Magic)
{
   for(int i = PositionsTotal() - 1; i >= 0; i--)
   {
      if(PositionGetTicket(i) <= 0)
      {
         continue;
      }
      bool L_Type   = PositionGetInteger(POSITION_TYPE)  == P_Type;
      bool L_Symbol = PositionGetString(POSITION_SYMBOL) == P_Symbol;
      bool L_Magic  = PositionGetInteger(POSITION_MAGIC) == P_Magic;
      if (L_Type && L_Symbol && L_Magic)
      {
         double L_BID       = SymbolInfoDouble(P_Symbol,SYMBOL_BID);
         double L_ASK       = SymbolInfoDouble(P_Symbol,SYMBOL_ASK);
         double L_Point     = SymbolInfoDouble(P_Symbol,SYMBOL_POINT);
         double L_OpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
         if (P_Type == POSITION_TYPE_BUY)
         {
            bool L_Condition = L_BID <= L_OpenPrice - P_Point * P_Multiple * L_Point;
            if (L_Condition)
            {
               return(true);
            }
         }
         else if (P_Type == POSITION_TYPE_SELL)
         {
            bool L_Condition = L_ASK >= L_OpenPrice + P_Point * P_Multiple * L_Point;
            if (L_Condition)
            {
               return(true);
            }
         }
      }
   }
   return (false);
}
 
Hong Yi Li #:

This is the code that determines the profit and loss of a position. You only need to put your own transaction closing code.

I don’t know if my answer fits the topic?

My English is not very good, so I use Google Translate, haha, please forgive me if there are any mistakes.

Thanks

 
Artep05 #:

 I search a EA, if a predefinied sum (basket) of profit (or loss) is reached, that the EA close only the profitable trades and not the other trades, which currently still in loss.

Because it is not often to have a overall-profit, so I want let the looser trades run. For example: I trade often a grid-system, some trades are profitable and some trades are not, but I want close only profitable trades, if they reach together a predefined sum in money. 

I often do the same, but my ea will open more profit trades until 1 or more of the losing trades are closed with an average price + small profit. But i do not think basket closer does this, but it could be modified to do it.

try search terms average closer or search for ilan ea there is lots of versions on codebase and google. You can use code from it.