Navigation´╝ÜHome > Content >

The_Theory_of_Cycles.mq4

Time: 2017-05-09 | Download file:The_Theory_of_Cycles.mq4



#property copyright "The Theory of Cycles"
#define   MAGIC     02001010137


extern string _Parameters_Trade = "Parameters_Trade"; 
extern double Lots           = 0.1;    
extern int    StopLoss       = 50;     
extern int    TakeProfit     = 300;
extern int    TrailingStop   = 30;   
extern int    TrailingStep   = 0; 
extern string _Parameters_Expert = "Parameters_Expert";
extern int    DelayCycle     = 10;      
extern int    PassCycle      = 10;  

 bool   UseSound      = True;         
 string NameFileSound = "expert.wav"; 
color  clOpenBuy     = LightBlue;    
color  clOpenSell    = LightCoral;  
color  clModifyBuy   = Aqua;         
 color  clModifySell  = Tomato;       
color  clCloseBuy    = Blue;         
color  clCloseSell   = Red;   
bool   ProfitTrailing = True;  
int    cnt=0;
int    HighLowCycle=100;
int    NotyCycle=2;
int    AmpliCycle=10;


int    initialize=1;
int    iTmp=0;
int    s=0;
int    b=0;
double ho=0;
double lo=0;
int    i=0;
int    fl=0;
int    lotsi;


void start() {


if (OrdersTotal() > 0 )
   {
   if(CurTime()- OrderOpenTime() < DelayCycle * 864) return(0);
  
   }
  else
   {
   if (CurTime()- OrderOpenTime() < PassCycle * 10) return(0);
   }



if (initialize == 1)
   {
   if (OrdersTotal() == 0)
      {
      initialize = 0;
      fl = 0;
      return(0);
      }
   iTmp = 0;
  
   for (i=0; i lo - AmpliCycle * Point ) 
   OrderSend(Symbol(),OP_SELLSTOP,Lots,lo - AmpliCycle * Point,3,lo + StopLoss * Point,lo - TakeProfit * Point,"B.A.R.S.",MAGIC,0,Red);

 
   
   if (Low[0] < lo - AmpliCycle * Point ) 
   OrderSend(Symbol(),OP_SELLSTOP,Lots,lo - AmpliCycle * Point,3,lo + StopLoss * Point,lo - TakeProfit * Point,"B.A.R.S.",MAGIC,0,Yellow);
}

b = 0;
s = 0;

if (OrdersTotal() != 0)
   {
   
    for (i=0; i ho) ho = High[i];
      if (Low[i] < lo ) lo = Low[i];
      }
   }


if ( OrdersTotal() == 0 && b + s == 0 && ho - lo < HighLowCycle * Point) 
   {
   fl = 1;
   if (High[0] > ho - AmpliCycle * Point) 
   
   OrderSend(Symbol(),OP_BUYSTOP,Lots,ho + AmpliCycle * Point,3,ho - StopLoss * Point,ho + TakeProfit * Point,"B.A.R.S.",MAGIC,0,Blue);

    if (High[0] < ho - AmpliCycle * Point) 
   
   OrderSend(Symbol(),OP_BUYSTOP,Lots,ho + AmpliCycle * Point,3,ho - StopLoss * Point,ho + TakeProfit * Point,"B.A.R.S.",MAGIC,0,Blue);

   }
}



void TrailingPositions() {

  for (int i=0; iTrailingStop*Point) {
             
              if (OrderStopLoss()TrailingStop*Point) {
              if (OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*Point || OrderStopLoss()==0) {
                ModifyStopLoss(Ask+TrailingStop*Point, clModifySell);
              }
            }
          }
        }
      }
    }
  }

void ModifyStopLoss(double ldStop, color clModify) {

  bool   fm;
  double ldOpen=OrderOpenPrice();
  double ldTake=OrderTakeProfit();

  fm=OrderModify(OrderTicket(), ldOpen, ldStop, ldTake, 0, clModify);
 
  if (fm && UseSound) PlaySound(NameFileSound);
}

Recommend