Thread: Daily Profit
View Single Post
  #1 (permalink)  
Old 09-02-2006, 09:00 PM
cardio cardio is offline
Senior Member
 
Join Date: Sep 2005
Location: St Louis, MO, USA
Posts: 176
cardio is an unknown quantity at this point
Daily Profit

Hi

I am working on a function to determine whether an ea has hit is daily profit target, but I am unsure if I am doing this right. Specifically when I check the closed orders. All my orders open up as pending orders, does a pending order's ordertype convert from OP_BUYSTOP to OP_BUY when the stop is reached and the order is executed?
Please check my function - if you have a better way please let me know
Code:
bool IsProfitforDayReached()
{
//Got to get this function to see the new Day
static int totalPips = 0;
static double totalProfits = 0.0;
static double currentBal

if newday()
{
 totalPips = 0;
 totalProfits = 0.0;
 currentBal = AccountBalance();
}
	int orders = OrdersTotal();
	//check is there is an existing order
   for(int i=orders-1;i>=0;i--)
    {   
     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=MAGICMA) continue;
     switch (OrderType())
      {
         case OP_BUY:
            totalPips += (Bid-OrderOpenPrice())/Point;
            totalProfits += OrderProfit();
            break;
            
         case OP_SELL:
            totalPips += (OrderOpenPrice()-Ask)/Point;
            totalProfits += OrderProfit();
            break;
      }   
	 }
	 for(int i=orders-1;i>=0;i--)
    {   
     OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
     if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=MAGICMA) continue;
     //check that the order was opened and closed today
     if (OrderOpenTime()<TimeToStr(CurTime(),TIME_DATE)) continue;
     switch (OrderType())
      {
         case OP_BUY:
            totalPips += (OrderClosePrice-OrderOpenPrice())/Point;
            totalProfits += OrderProfit();
            break;
            
         case OP_SELL:
            totalPips += (OrderOpenPrice()-OrderOpenPrice)/Point;
            totalProfits += OrderProfit();
            break;
      }   
	 }
   if(totalProfits/currentBal>0.05)
   {
    return(true);
   }
   else
   {
    return(false);
   }
	 
	
}

////////////////////
bool newday()
{
//Returns true if it is a new Day
 int lastVal;
 int curretVal; 
 
 //We have the current value
 currentVal = Day();
 
 //Get the previous value
  gvname = "newday"
  gvvalue = Day();
  if(GlobalVariableCheck(gvname)) 
   {
      lastVal = GlobalVariableGet(gvname);
   }
   else
   {
   //there was no previous value so set up a previous value and return true so things can start
    GlobalVariableSet(gvname,gvvalue);
    return(true);
   }
   
   if (lastVal!=currentVal) 
   {
    return(true);
    GlobalVariableSet(gvname,gvvalue);
   }
   else
   {
     return(false);
   }
    
   
}
Reply With Quote