Navigation´╝ÜHome > Content >

OBOS_TOE_Long_Only.mq4

Time: 2012-03-13 | Download file:OBOS_TOE_Long_Only.mq4

//+------------------------------------------------------------------+
//|                                       Magix Trigger on Grid .mq4 |
//|                                                totom sukopratomo |
//|                                                    Variant OF SWB|
//+------------------------------------------------------------------+


//This is a remake of the original SWB by Totom Sukopratomo.

//There is always risk in trading market through the use of automated 
//traders, so use should always be monitored for account safety and 
//use only if you have funds that you can afford to lose.

//This is a trade strategy automated trader and was meant for others
//to use the same selected indicators used in this EA for educational
//puroses.  Use as a live trading robot may prove to be profitable
//but may also drain your account.

//Have fun with this tool, and Happy Pips!

//Magix



#define buy -2
#define sell 2
//---- input parameters
bool      use_daily_target=false;
double    daily_target=100;
bool      EachTickMode = True;
bool      trade_in_fri=true;
extern int       magic=68;
extern string    Comments = "OBOS Divergence TOE Long";

extern string     Trade_Lot_Settings = "Money Management";
extern double     start_lot=0.01;
extern double     range=10;
extern int        level=15;
bool              lot_multiplier=false;
double            multiplier=2.0;
extern double     increment=0.01;
bool              use_sl_and_tp=false;
double            sl=60;
double            tp=10;
extern double     tp_in_money=1.0;
bool              stealth_mode=true;
extern string    Envelope = "Set The Channel";
extern int        EnvelopePeriod    =24;    //moving average length
extern int        EnvMaMethod       =0;      //0=sma,1=ema,2=smma,3=lwma.
extern int        Shift           =0;      //shift relative to current bar indicator data is posted
extern double     EnvelopeDeviation =0.04;    //envelope width
extern string    Moving_Average = "Set The Breakout";
extern int       MAPeriod=10;//
extern int       MAMethod=0;//
extern int       MAShift=0;
int              MAPrice=0;
extern string    Derivative_Oscillator_Settings= "Set The Trigger";
extern double     RSIDer=14;

bool      hedge=false;
int       hedge_start=1;
double    h_lot_factor=0.5;
double    h_tp_factor=1.0;
double    lot_multiplier_2=1.5;
int       lot_multi_2_level=3;

double pt;
double minlot;
double stoplevel;
int prec=0;
int a=0;
int ticket=0;
//----
double s_lot,s_lot2,hf,h_tp,lm_1,lm_2,lm_2_level,O_equity;
bool Close_All; // Part of Close_All Inhibit ...
int O_rst=0;
string opt="NULL";


int BarCount;
int Current;
bool TickCheck = False;







//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----


BarCount = Bars;
   if (EachTickMode) Current = 0; else Current = 1;





   if(Digits==3 || Digits==5) pt=10*Point;
   else                          pt=Point;
   minlot   =   MarketInfo(Symbol(),MODE_MINLOT);
   stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
   if(start_lot=daily_target)
   {
     Comment("\ndaily target achieved.");
     return(0);
   }
   if(!trade_in_fri && DayOfWeek()==5 && total()==0)
   {
     Comment("\nstop trading in Friday.");
     return(0);
   }
//+------------------------------------------------------------------+
   int T_cnt=0,b_cnt=0,s_cnt=0,h_cnt,O_cnt=0,OOT,FOOT; // Close_All Inhibit ...
   bool s_hedge=false,b_hedge=false; string FOT="0";
   for(int cnt=0; cnt<=OrdersTotal(); cnt++)
   {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()<2)
      {
         T_cnt+=1; OOT=OrderOpenTime();
         if(OrderType()==0){ b_cnt+=1; } if(OrderType()==1){ s_cnt+=1; }
         if(T_cnt==1 || OOT=hedge_start-1){ s_hedge=true; }
   }
   if(FOT=="S")
   {
      O_cnt=s_cnt; h_cnt=b_cnt; opt="SELL"; if(hedge==true && s_cnt>=hedge_start-1){ b_hedge=true; }
   }
//----
   multiplier=lm_1; if(lm_2>0 && O_cnt>=lm_2_level-1){ multiplier=lm_2; }
//----
   if(T_cnt==0){ Close_All=false; }
//+------------------------------------------------------------------+
   if(O_cnt==0 && a==0 && h_cnt==0) // substituted total() with O_cnt ...
   {
     if(signal()==buy /*&& Close_All==false*/) // added close_all and hedge
     {
        if(stealth_mode)
        {
          if(use_sl_and_tp){ s_lot=start_lot; ticket=OrderSend(Symbol(),0,s_lot,Ask,3,Ask-sl*pt,Ask+tp*pt,Comments,magic,0,Blue); }
          else             { s_lot=start_lot; ticket=OrderSend(Symbol(),0,s_lot,Ask,3,        0,        0,Comments,magic,0,Blue); }
        }
        else
        {
          if(use_sl_and_tp) 
          {
             s_lot=start_lot;
             if(OrderSend(Symbol(),0,start_lot,Ask,3,Ask-sl*pt,Ask+tp*pt,Comments,magic,0,Blue)>0)
             {
                for(int i=1; i0)
             {
                for(i=1; i0)
             {
                for(i=1; i0)
             {
                for(i=1; i0 && O_cnt=op+range*pt && Close_All==false) // added close_all and hedge
     {
        if(use_sl_and_tp)
        {
           if(lot_multiplier){ s_lot=NormalizeDouble(lastlot*multiplier,prec); ticket=OrderSend(Symbol(),1,s_lot,Bid,3,Bid+sl*pt,Bid-tp*pt,Comments,magic,0,Red); }
           else              { s_lot=NormalizeDouble(lastlot+increment,prec); ticket=OrderSend(Symbol(),1,s_lot,Bid,3,Bid+sl*pt,Bid-tp*pt,Comments,magic,0,Red); }
        }
        else
        {
           if(lot_multiplier){ s_lot=NormalizeDouble(lastlot*multiplier,prec); ticket=OrderSend(Symbol(),1,s_lot,Bid,3,0,0,Comments,magic,0,Red); }
           else              { s_lot=NormalizeDouble(lastlot+increment,prec); ticket=OrderSend(Symbol(),1,s_lot,Bid,3,0,0,Comments,magic,0,Red); }
        }
        if(b_hedge==true){ ticket=OrderSend(Symbol(),0,s_lot*hf,Ask,3,0,Ask+h_tp,"Hedge",magic,0,Blue); }
     }
   }
//+------------------------------------------------------------------+
   double st_lots=0,h_lots,t_lots,n_lots; cnt=0; // Close_All Inhibit ...
   for(cnt=0; cnt<=OrdersTotal(); cnt++)
   {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()<2)
      {
         if((FOT=="B" && OrderType()==1) || (FOT=="S" && OrderType()==0)){ h_lots+=OrderLots(); }
         t_lots+=OrderLots(); st_lots=t_lots-h_lots; n_lots=st_lots-h_lots;
      }
   }
//+------------------------------------------------------------------+
   double AE=AccountEquity(),a_profit=AE-O_equity,b_profit; if(a_profit>b_profit){ b_profit=a_profit; }
   Comment("OPT = ",opt,"  /  LEVEL = ",O_cnt,"  /  Hedge Start = ",hedge_start,"  |  Standard Lots = ",DoubleToStr(st_lots,2),
   "  /  Hedge Lots = ",DoubleToStr(h_lots,2),"  /  Net Lots = ",DoubleToStr(n_lots,2),"\n","Account Equity = ",DoubleToStr(AE,2),"  /  Account Profit = ",DoubleToStr(a_profit,2));
//+------------------------------------------------------------------+
   if(use_sl_and_tp && total()>1)
   {
     double s_l, t_p;
     for(i=0; i1) continue;
         type=OrderType();
         s_l=OrderStopLoss();
         t_p=OrderTakeProfit();
     }
     for(i=OrdersTotal()-1; i>=0; i--)
     {
       OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
       if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic || OrderType()>1) continue;
       if(OrderType()==type)
       {
          if(OrderStopLoss()!=s_l || OrderTakeProfit()!=t_p)
          {
             OrderModify(OrderTicket(),OrderOpenPrice(),s_l,t_p,0,CLR_NONE);
          }
       }
     }
   }
   double profit=0;
   for(i=0; i1) continue;
      profit+=OrderProfit();
   }
   if(profit>=tp_in_money&&signal()==sell || a>0) 
   {
      closeall();
      closeall();
      closeall();
      a++;
      if(total()==0) a=0;
   }
   if(!stealth_mode && use_sl_and_tp && total()DO2) return (buy);
            if (MAP>bline&&DO2>0&&DO1=0; i--)
  {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue; Close_All=true; // Close_All Inhibit ...
      if(OrderType()>1) OrderDelete(OrderTicket());
      else
      {
        if(OrderType()==0) OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
        else               OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
      }
  }
} 

Recommend