FxIgorDynBOSystem1-1ea





//+------------------------------------------------------------------+
//|                                            FXIgorSystem1.1.mq4   |
//|                                               Diego G. Almeida   |
//|           Magic number and MM added by Project1972               |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


extern double lots= 0.01; // 0.01 is a single micro lot
extern bool MM = false;       // if true the lots size will increase based on account balance 
extern int risk=1;           // percent of account balance to risk on each trade (only if mm is enabled)
extern double MinLots=0.1;   // minimal lots you want to trade or your broker allow (only if mm is enabled)
extern double MAXLots=10;    // max lots you want to trade or your broker allow (only if mm is enabled)               
//extern double takeProfit   = 0;                         
extern double slippage     = 10;
int      MagicNumber = 123787;
extern int hourtoclose = 20; //default 18 Alpari Fibogroup and MIG, 19 Northfinance and FXDD, 17 IBFX
double highday=0,lowday=0,h=0,l=0,media=0,mediacalc=0,pcompra=0,pvenda=0,TrailingStop=0,lotsi=0,stopLoss=0;
int cnt,dia=0,op=0,limitepos=0;
int init() 
{
   return(0);
}
int start()
{

if (MM==true) {{ lotsi=NormalizeDouble(AccountBalance()*risk/100000.0,1); }
if (lotsi<MinLots){ lotsi=MinLots; }
if (lotsi>MAXLots){ lotsi=MAXLots; }
}
else { lotsi=lots; }   
if(AccountFreeMargin() < 1000*lotsi) {
  Print("Not enough money to trade ");
      return(0); }
           
int orders=0,horas=0;
if(Day() != dia)
{
int R1=0,R5=0,R10=0,R20=0,RAvg=0;
int i=0;

   R1 =  (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/Point;
   for(i=1;i<=5;i++)
      R5    =    R5  +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
   for(i=1;i<=10;i++)
      R10   =    R10 +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
   for(i=1;i<=20;i++)
      R20   =    R20 +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;

   R5 = R5/5;
   R10 = R10/10;
   R20 = R20/20;
   RAvg  =  (R1+R5+R10+R20)/4;    
   media=RAvg/2;
   mediacalc=MathCeil(media);
   TrailingStop=mediacalc;
   stopLoss=mediacalc;
   h=0;
   l=0;
   dia=Day();
   op=0;
   limitepos=0;
}
   highday=iHigh(NULL,PERIOD_D1,0);
   lowday=iLow(NULL,PERIOD_D1,0);

if(highday > h)
   h=highday;
if(lowday < l)
   l=lowday;
Print("Trailing stop ",TrailingStop);
Print("Mediacalc ",mediacalc);

horas=hourtoclose - Hour();

int total=OrdersTotal();
  if(total>0)
   { 
   for(cnt=0;cnt<total;cnt++)
   {
      if(OrderSymbol() == Symbol() && OrderType() == OP_BUY)
      {
         op=1;
      }
      if(OrderSymbol() == Symbol() && OrderType() == OP_SELL)
      {
         op=2;
      }
   } 
   for(cnt=0;cnt<total;cnt++)
    {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
      {
      if(TrailingStop > 0) {             
               if(Bid-OrderOpenPrice() > TrailingStop*Point)
                {
                  if(OrderStopLoss() < (Bid - TrailingStop*Point))
                     //if(OrderTakeProfit() == 0)
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Blue);
               }
            }
         
      }   else {                              
            if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
            {
            if(TrailingStop > 0) {             
               if(OrderOpenPrice() - Ask > TrailingStop*Point)
                {
                  if(OrderStopLoss() == 0 || OrderStopLoss() > Ask + TrailingStop*Point)
                     //if(OrderTakeProfit() == 0)
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Red);
                }           
            }
          } 
        }
      if(OrderSymbol()==Symbol() && OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber)
      {
         if(Hour() >= hourtoclose && Hour() < 23)
            OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime);
         orders=1;
      }
      if(OrderSymbol()==Symbol() && OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber)
      {
         if(Hour() >= hourtoclose && Hour() < 23)
            OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime);
          orders=1;
      }
    
   
    }

  } 
else
{
   //horas=hourtoclose - Hour();
   if(horas >= 1)
   {
   
      if(orders == 0 && op == 2 && limitepos <2)
      {
         OrderSend(Symbol(),OP_BUY,lotsi,Ask,slippage,Ask-stopLoss*Point,0,"Power:Buy",MagicNumber,0,Lime);
         limitepos+=1;
      }
      if(orders == 0 && op == 1 && limitepos <2)
      {
         OrderSend(Symbol(),OP_SELL,lotsi,Bid,slippage,Bid+stopLoss*Point,0,"Power:Sell",MagicNumber,0,Red);
         limitepos+=1;
      }
   }
}

if(horas >=1)
{

if(orders == 0 && op == 0 && limitepos <2)
{
   pcompra=lowday+mediacalc*Point;
   pvenda=highday-mediacalc*Point;
   
   Comment("\n Break Channel: ",mediacalc," pips \n Buying Price: ",pcompra,"\n Selling Price: ",pvenda,"\n Lots: ",lotsi);
   
   Print("Buying Price: ",pcompra);
   Print("Selling Price: ",pvenda);
   Print("Lots: ",lotsi);
   if(Bid >= pcompra)
   {
      Print("Buy");
      OrderSend(Symbol(),OP_BUY,lotsi,Ask,slippage,Ask-stopLoss*Point,0,"Power:Buy",MagicNumber,0,Lime);      
      limitepos+=1;
   }

if(Bid <= pvenda)
{
      Print("Sell");
      OrderSend(Symbol(),OP_SELL,lotsi,Bid,slippage,Bid+stopLoss*Point,0,"Power:Sell",MagicNumber,0,Red);
      limitepos+=1;
}

}
}
return(0);
}





Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders
It can change open orders parameters, due to possible stepping strategy
It Closes Orders by itself
It automatically opens orders when conditions are reached

Other Features:


BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.57 Total Net Profit:-77.04

BackTest : EURUSD on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:0.79 Total Net Profit:-27.19

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.61 Total Net Profit:-64.56

BackTest : USDCAD on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.55 Total Net Profit:-27.27

BackTest : USDCHF on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.16 Total Net Profit:-105.42

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:1.19 Total Net Profit:6.67

Request Backtest for FxIgorDynBOSystem1-1ea


From : (yyyy/mm/dd) To: (yyyy/mm/dd)

Pair: Period: