The Theory of Cycles

Author: The Theory of Cycles
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
Miscellaneous
It plays sound alerts
1 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
56.00 %
Total Trades 363
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -1.90
Gross Profit 882.60
Gross Loss -1572.00
Total Net Profit -689.40
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
67.00 %
Total Trades 245
Won Trades 59
Lost trades 186
Win Rate 0.24 %
Expected payoff -1.50
Gross Profit 747.90
Gross Loss -1116.00
Total Net Profit -368.10
-100%
-50%
0%
50%
100%
The Theory of Cycles



#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<OrdersTotal(); i++) 
      {
      
       if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC ) {
          if (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP ) iTmp++;
    }
     }
      }
   
   if (iTmp == 0 || iTmp == 2) 
      {
      initialize = 0;
      fl = 0;
      return(0);
      }
   
    for (i=0; i<OrdersTotal(); i++) 
      {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC ) {
          if (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP ) OrderDelete(OrderTicket());
    }
     }
      }
  return(0);
   }



CheckForOpen();
TrailingPositions();


}


void CheckForOpen() {
 
 if (fl == 1 )
   {
   fl = 0;
   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,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<OrdersTotal(); i++) 
      {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC ) {
          if (OrderType()==OP_BUYSTOP ) b++;
          if (OrderType()==OP_SELLSTOP )s++;
          if (s + b == 2) return(0);
          }
         }
   }
   }
  

if (OrdersTotal() != 0 && b + s == 1) 
   {
   for (i=0; i<OrdersTotal(); i++) 
      {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC ) {
          if (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP ) OrderDelete(OrderTicket());
  
  }
  }
  }
  return(0);
  
}




if (OrdersTotal() == 0 && b + s == 0) 
   {

   ho = High[1];
   lo = Low[1];
  
   for (i=NotyCycle; i<=1; i++)

      {
      if (High[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; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
  
        if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC ) {
          if (OrderType()==OP_BUY) {
            if (!ProfitTrailing || (Bid-OrderOpenPrice())>TrailingStop*Point) {
             
              if (OrderStopLoss()<Bid-(TrailingStop+TrailingStep-1)*Point) {
                  ModifyStopLoss(Bid-TrailingStop*Point, clModifyBuy);
              }
            }
          }
          if (OrderType()==OP_SELL) {
            if (!ProfitTrailing || OrderOpenPrice()-Ask>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);
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---