View Single Post
  #17 (permalink)  
Old 04-06-2006, 06:06 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 994
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Lightbulb profit protector!

This is my profit protector code:

PHP Code:
extern bool      ProtectProfittrue;
extern double    ProfitToProtect 150;



int start()
{
...
if(
ProtectProfit)
   
ProfitProtect(ProfitToProtect);
....
}



void ProfitProtect(double profit)
{
      
int total  OrdersTotal();
      
double MyCurrentProfit=0;
      for (
int cnt cnt total cnt++)
      {
         
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
         if (
OrderMagicNumber() == MagicNumber)
            
MyCurrentProfit += OrderProfit();
      }
      Print(
"My Current Profit is : " DoubleToStr(MyCurrentProfit,2) + " While My Profit Target is " DoubleToStr(profit,2));
      if(
MyCurrentProfit>=profit)
         
CloseAll();
}
void CloseAll()
{
      
int total  OrdersTotal();
      for (
int cnt cnt total cnt++)
      {
         
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
         if (
OrderMagicNumber() == MagicNumber)
            if(
OrderType()==OP_BUY)
               
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);
            if(
OrderType()==OP_SELL)   
               
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet);
      }

__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Reply With Quote