Forex
Google

Go Back   Forex Trading > Discussion Areas > Setup Questions
Forex Forum Register FAQ Members List Calendar Today's Posts


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-02-2006, 08: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);
   }
    
   
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 09-03-2006, 10:39 AM
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
re-thought

I see I was making a stuff-up, all one doesn't have to count the closed orders, as they are wrapped up in the accountbalance or accountequity. So the calc is far more simple, maybe this is right.

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 = AccountEquity();
}
   if((AccountEquity()-currentBal)/currentBal>0.05)
   {
    return(true);
   }
   else
   {
    return(false);
   }
	 
	
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Daily Direction......... ValeoFX General Discussion 4 05-25-2008 05:31 PM
What is Daily Range??? yyc196 General Discussion 1 04-11-2007 02:09 AM
Daily HL foreground iwan Indicators - Metatrader 4 3 01-30-2007 07:22 AM
profit Vs Profit factor cardio Metatrader 4 4 02-10-2006 06:24 PM


All times are GMT. The time now is 07:04 PM.