take profit based on money

 

I recently had this idea of taking profit based on money or cents assuming i want to use this method away from pips or points ,the code should no be affected by pips or points but should use this method below to take profit in cents or dollars minimum dollar amount 1 minim tp in cents is 1 cent ,attached is a version for my code


//+------------------------------------------------------------------+

//|                                            Blue Ocean Dragon.mq5 |
//|          Whatsapp +27651351609 or click  Amos Tsopotsa.         |
//|        Telegram support      https://t.me/+JxCz659JUMRjOTg8      |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, Amos Tsopotsa"
#property link      "Telegram https://t.me/+JxCz659JUMRjOTg8 or *WhatsApp +27651351609* "
#property version   "2.00"
#resource "\\Indicators\\Boom and Crash code.ex5"
#include <Trade\Trade.mqh> CTrade trade;
#include <Trade\PositionInfo.mqh> CPositionInfo position;
enum profit_Mode
  {
   Currency_Profit,//Currency
   Points//Points
  };
enum currency_profit
  {
   Dollar_Profit, //Dollar
   Cent_Profit, //Cent
  };
enum trade_type
  {
   buy, //Buy Only
   sell,//Sell Only
   both//Both
  };
  
enum ENUM_DIR
{
   Dir0, // Buy&Sell
   Dir1, // Only buy
   Dir2  // Only sell
};
  
//profit_Mode Profits;
input ENUM_DIR        Direction            = 0;
input ulong           Magic_Number         = 12345;
input int             inpCciPeriod         = 10;
input bool            Aggressive_Mode      = false; 
input int             Max_Trades           = 2;
input int             StopLoss             = 1000;
input int             TakeProfit           = 1000; 
input double          Lot_Size             = 0.01;
input bool            Profit_Mode          = 0;
input bool            Currency_Profit      = 0;
input bool            Dollar_Profit        = 20;
input bool             Dollar_Loss          = 5;
input bool            Cent_Profit          = 100;
input bool             Cent_Loss            = 20;

int handle;
double ccio[],ccih[],ccil[],ccic[];
datetime ExpirationTime = D'2023.09.10';
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
  handle = iCustom(_Symbol,PERIOD_CURRENT,"::Indicators\\Boom and Crash code.ex5",inpCciPeriod);
  trade.SetExpertMagicNumber(Magic_Number);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
double Ask, Bid, sls, tps; 
string firstTradeComment = "FT";
datetime candleTime, curentTime[];
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- 
   static bool ExpMsg = true;
   if (TimeCurrent() >= ExpirationTime)
   {
      if (!ExpMsg)
      {
         Alert("The trial version of the EA has expired. Please contact the author.");
         ExpMsg = true;
      }
      return;
   }
   
   Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
   
   CopyTime(_Symbol,PERIOD_CURRENT,0,10,curentTime);
   ArraySetAsSeries(curentTime,true);
   
   CopyBuffer(handle,0,0,10,ccio);
   CopyBuffer(handle,1,0,10,ccih);
   CopyBuffer(handle,2,0,10,ccil);
   CopyBuffer(handle,3,0,10,ccic);
   
   ArraySetAsSeries(ccio,true);
   ArraySetAsSeries(ccih,true);
   ArraySetAsSeries(ccil,true);
   ArraySetAsSeries(ccic,true); 
   
      tradeFunc();
      if(Aggressive_Mode == true)
        {
         Aggressive_Mode_Func();
        }    
     
   for(int i=1;i<PositionsTotal();i++)
     {
      if(position.SelectByIndex(i))
        {
         //trade.PositionClose(position.Ticket());
        }
     }
      
   closeByDollar(); 
  }
//+------------------------------------------------------------------+
//|Find trade                                                        |
//+------------------------------------------------------------------+
string tradeType;
bool findTrade(string comentToFind)
{
   bool yes = true;
   for (int i=1; i<PositionsTotal(); i++)
   {
      if (position.SelectByIndex(i))
      {
         if (position.Comment() == comentToFind) yes = true;
         tradeType = position.TypeDescription();
      }
   }
   return yes;
}
//+------------------------------------------------------------------+
//|Aggresive Mode                                                    |
//+------------------------------------------------------------------+
void Aggressive_Mode_Func()
  {
   double open[], close[];
   
   CopyClose(_Symbol,PERIOD_CURRENT,0,10,close);
   CopyOpen(_Symbol,PERIOD_CURRENT,0,10,open);
   
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(open,true);
   
   bool bull   = open[1] < close[1];
   bool bear   = open[1] > close[1];
   tps   = 0; tps = 0;
   
   //if(findTrade("Buy"+string(Magic_Number)) == true)
     {
      //if(tradeType == "buy")
        {
         if(bull && Direction != 1)
           {
            if(candleTime != curentTime[0])
              { 
               for(int d=0;d<Max_Trades;d++)
                 {
                  if(Profit_Mode == 0.00)
                    {
                     tps      = Ask + (TakeProfit*_Point);
                     sls      = Ask - (StopLoss*_Point);
                     trade.Buy(Lot_Size,NULL,0,sls,tps); 
                     candleTime = curentTime[0];
                    }
                  if(Profit_Mode == 0.00)
                    {
                     trade.Buy(Lot_Size,NULL,0,0,0); 
                     candleTime = curentTime[0];
                    }   
                 } 
              } 
           }
        } 
     }
   
  /// if(findTrade("Sell"+string(Magic_Number)) == true)
     {  
      //if(tradeType == "sell")
        {
         if(bear && Direction != 1)
           {
            if(candleTime != curentTime[0])
              {
               for(int c=0;c<Max_Trades;c++)
                 {
                  if(Profit_Mode == 0.000)
                    {
                     tps      = Bid - (TakeProfit*_Point);
                     sls      = Bid + (StopLoss*_Point);
                     trade.Sell(Lot_Size,_Symbol,0,sls,tps); 
                     candleTime = curentTime[0];   
                    }
                  if(Profit_Mode == 0.000)
                    {
                     trade.Sell(Lot_Size,_Symbol,0,0,0); 
                     candleTime = curentTime[0]; 
                    }   
                 } 
              } 
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|Dollar Profit Close                                               |
//+------------------------------------------------------------------+
void closeByDollar()
  {
   if(Profit_Mode == 0.00)
     {
      if(Currency_Profit == 0.00)
        {
         for(int i=0;i<PositionsTotal();i++)
           {
            if(position.SelectByIndex(i))
              {
               if(position.Magic() == Magic_Number && position.Symbol() == _Symbol)
                 {
                  if(position.Profit() >= Dollar_Profit)
                    {
                     trade.PositionClose(position.Ticket());
                    }
                  if(position.Profit() <= -Dollar_Loss)
                    {
                     trade.PositionClose(position.Ticket());
                    }   
                 } 
              }
           }
        }
      if(Currency_Profit == 0.00)
        {
         for(int c=0;c<PositionsTotal();c++)
           {
            if(position.SelectByIndex(c))
              {
               if(position.Magic() == Magic_Number && position.Symbol() == _Symbol)
                 {
                 // Alert(position.Profit());
                  if(position.Profit() >= ((double(1)/double(1))*Cent_Profit))
                    {
                     trade.PositionClose(position.Ticket());
                    }
                  if(position.Profit() <= -((double(1)/double(1))*Cent_Loss))
                    {
                     trade.PositionClose(position.Ticket());
                    }   
                 } 
              }
           }
        }
     }
  }
datetime firstsellTime, firstbuytime;
//+------------------------------------------------------------------+
//| Trade Function                                                   |
//+------------------------------------------------------------------+
void tradeFunc()
{
   bool buy = false, sell = false; 
   if(ccic[1] > 0 && ccic[1] > 0) buy  = true;
   if(ccic[1] < 0 && ccic[1] > 0) sell = true;
   
   if (buy && Direction != 1)
   {
      if (firstbuytime != curentTime[0])
      { 
         if (!findTrade("Buy"+string(Magic_Number)))
         {
            for (int d=0; d<Max_Trades; d++)
            {
               if (Profit_Mode == 0.00)
               {
                  tps = Ask + (TakeProfit*_Point);
                  sls = Ask - (StopLoss*_Point);
                  trade.Buy(Lot_Size,_Symbol,0,sls,tps,"Buy"+string(Magic_Number)); 
                  firstbuytime = curentTime[0];   
               }
               if (Profit_Mode == 0.00)
               {
                  trade.Buy(Lot_Size,_Symbol,0,0,0,"Buy"+string(Magic_Number)); 
                  firstbuytime = curentTime[0]; 
               }
            }      
         } 
      }
   }
   if (sell && Direction != 1)
   {
      if (firstsellTime != curentTime[0])
      {
         if (!findTrade("Sell"+string(Magic_Number)))
         {
            for (int c=0; c<Max_Trades; c++)
            {
               if (Profit_Mode == 0.00)
               {
                  tps = Bid - (TakeProfit*_Point);
                  sls = Bid + (StopLoss*_Point);
                  trade.Sell(Lot_Size,_Symbol,0,sls,tps,"Sell"+string(Magic_Number));
                  firstsellTime = curentTime[0];     
               }
               if (Profit_Mode == 0.00)
               {
                  trade.Sell(Lot_Size,_Symbol,0,0,0,"Sell"+string(Magic_Number));
                  firstsellTime = curentTime[0];  
               }
            }  
         } 
      }
   }
}

 

And what is you problem your question.

if it works or not just use debugging with hist. data which would be quite useful as you can select moments in the history when it should work and when it should not.