Forex



Go Back   Forex Trading > Discussion Areas > Setup Questions
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 09-02-2006, 09:00 PM
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 09-03-2006, 11:39 AM
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

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


All times are GMT. The time now is 08:32 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.