VininE_Cyber_Cycle





//+------------------------------------------------------------------+
//|                                                     VininE_Cyber Cycle |
//|                                Copyright © 2008, Victor Nicolaev |
//|                                            e-mail: vinin@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Victor Nicolaev"
#property link      "e-mail: vinin@mail.ru"

//===================================================================
extern string  S1             = "Ïàðàìåòðû èíäèêàòîðà";
extern double alpha=0.01;
extern double betta=1.0;
extern double level_Buy_Open=0.5;
extern double level_Sell_Open=-0.5;
extern double level_Buy_Close=0.5;
extern double level_Sell_Close=-0.5;


extern string  S2             = "Ïàðàìåòðû MM";
extern double  Lots           =  1  ;
extern int     StopLoss       = 0	;              // Ñòîïëîññ 
extern int     TakeProfit     = 0	;              // Ñòîïëîññ 
extern int Slippage=50;

extern string  S3             = "Ïàðàìåòðû Ñîâåòíèêà";
extern int     Magic        = 20090309;
extern string  _comment      = "";           // Êîììåíòàðèé 

color clOpenBuy=Red; 
color clOpenSell=Blue;
color clCloseBuy=Red; 
color clCloseSell=Blue;


int Order_Count[6];
string NameOP[]={"BUY","SELL","BUYLIMMIT","SELLLIMIT","BUYSTOP","SELLSTOP"};

#include <stdlib.mqh>
#include <WinUser32.mqh>

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {//0
   GetLastError();         // Î÷èñòêà ïîñëåäíåé îøèáêè


return(0);}//0



//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
   return(0); 
}


//+------------------------------------------------------------------+
//Ðàáîòà ïî îòäåëüíîé ÒÑ
//+------------------------------------------------------------------+ 
int start() { 
   if (!NevBar()) return(0);
   if (CheckClose()) Order_Close();
   
   int cmd1=CheckOpen();
   if (cmd1==-1) return(0);
   SetOrder(cmd1);
   return(0);
} 

bool SetOrder(int OP){
   bool Res=false;
   int cmd=MathAbs(OP-1);
   Order_Count_Calculate();          // Ïîäñ÷åò îòêðûòûõ ïîçèöèé   
   if (Order_Count[cmd]>0)             // Êîíòðîëü ïîçèöèé äëÿ çàêðûòèÿ
      Order_Close(cmd);
   if (Order_Count[OP]==0)             // Êîíòðîëü ïîçèöèé äëÿ îòêðûòèÿ
      Order_Open( OP);
   return(Res);
}

int CheckOpen(){
   int Res=-1;
   double tmp1=iCustom(NULL,0,"VininI_Cyber Cycle(V2)", alpha, betta,PRICE_OPEN,0,1);
   double tmp2=iCustom(NULL,0,"VininI_Cyber Cycle(V2)", alpha, betta,PRICE_OPEN,0,2);
   if (tmp1>level_Buy_Open) Res=OP_BUY;
   if (tmp1<level_Sell_Open) Res=OP_SELL;

   
   return(Res);
   
}

bool CheckClose(){
   bool Res=false;
   double tmp1=iCustom(NULL,0,"VininI_Cyber Cycle(V2)", alpha, betta,PRICE_OPEN,0,1);
   if (tmp1<level_Buy_Close && tmp1>level_Sell_Close) Res=true;

   
   return(Res);
   
}



bool NevBar() {
   static int PrevBar=0;
   int NevBar=Time[0];
   if (PrevBar==NevBar) return(false);
   PrevBar=NevBar;
   return(true);
}



//======================================================================================================
// Ôóíêöèÿ ëîãè÷åñêîãî ñðàâíåíèÿ
//=====================================================================================================
double iif(bool A, double B, double C) {if(A) return(B); return(C); }

//======================================================================================================
// Ôóíêöèÿ îòêðûòèÿ îðäåðîâ
//=====================================================================================================
void Order_Open(int OP){
   int err=GetLastError();
   RefreshRates();

   int cmd=iif(OP==OP_BUY,1,-1);
   double _ask     =MarketInfo(Symbol(),MODE_ASK);
   double _bid     =MarketInfo(Symbol(),MODE_BID);
   double _point   =MarketInfo(Symbol(),MODE_POINT);
   double _digits  =MarketInfo(Symbol(),MODE_DIGITS);
   double price= iif(OP==OP_BUY,_ask,_bid);
   double _sl=NormalizeDouble(iif(StopLoss==0,0,price-cmd*StopLoss*_point),_digits);
   double _tp=NormalizeDouble(iif(TakeProfit==0,0,price+cmd*TakeProfit*_point),_digits);
   double lots=GetLots();      

   OrderSend(Symbol(), OP,  lots, price, 3,_sl,_tp,_comment,Magic, 0); 
   err=GetLastError();
   if (err>0) Print(Ask," ;", Bid, " ;", price," ;",_sl," ;",_tp);

}
 
//======================================================================================================
// Ôóíêöèÿ çàêðûòèÿ îðäåðîâ
//=====================================================================================================
void Order_Close(int OP=-1){
   bool res;
   GetLastError();
   for(int i = OrdersTotal() - 1;  i >= 0;  i--) {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))   continue;
      if (OrderSymbol() != Symbol())                     continue;
      if (OrderMagicNumber() != Magic)                   continue;
      if (OrderType()!=OP && OP!=-1)                     continue;
      
      RefreshRates();
      double _ask      =MarketInfo(Symbol(),MODE_ASK);
      double  _bid     =MarketInfo(Symbol(),MODE_BID);
      double  _point   =MarketInfo(Symbol(),MODE_POINT);
      double  _digits  =MarketInfo(Symbol(),MODE_DIGITS);

      double ClosePrice=NormalizeDouble(iif(OrderType()==OP_BUY,_bid, _ask),_digits);
      res=OrderClose(OrderTicket(), OrderLots(), ClosePrice, 3, iif(OrderType()==OP_BUY,clCloseBuy,clCloseSell));
      if (!res) {
         int err=GetLastError();
         Print("Error(",err,") delete order ",NameOP[OP],": ",ErrorDescription(err));
      }
   }
}

double NormalizePrice(double Price){
   RefreshRates();
   double Res=Price;
   double MinStop=MarketInfo(Symbol(),MODE_STOPLEVEL);
   if (MathAbs(Price-Close[0])<MinStop*Point) {
      if (Price<Close[0]) Res=Close[0]-MinStop*Point;
      else Res=Close[0]+MinStop*Point;
   }
   Res=NormalizeDouble(Res,Digits);
   return(Res);
}

//===============================================================================
// Ôóíêöèÿ âîçâðàùàþøàÿ êîëè÷åñòâî îðäåðîâ îïðåäåëåííîãî òèïà èñõîäà èç çàäàííûõ îãðàíè÷åíèé
//===============================================================================
void Order_Count_Calculate(){
   ArrayInitialize(Order_Count,0);
   for (int i = OrdersTotal() - 1;  i >= 0;  i--) {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))   continue;
      if (OrderSymbol() != Symbol())                     continue;
      if (OrderMagicNumber() != Magic)                   continue;
      Order_Count[OrderType()]++;
   }
}

//===============================================================================
// Ôóíêöèÿ ðàñ÷èòûâàåò îáúåì ëîòà èñõîäÿ èç çàäàííîãî óðîâíÿ ðèñêà
//   ëîò=Ý/(ÄÄ/10/(%Ý*%Ð)+Ì)
//   
//   Ì - ìàðæà, çàëîã íà 1 ëîò
//
//===============================================================================
double GetLots() {
   double LotMin=MarketInfo(Symbol(),MODE_MINLOT);
   double LotMax=MarketInfo(Symbol(),MODE_MAXLOT);
   double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP);
   double lot=MathRound(Lots/LotStep)*LotStep;
   
   
   
   lot=MathMax(LotMin,MathMin(LotMax,lot));
   
   return(lot); 
}





Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains close prices for each bar


Indicator Curves created:


Indicators Used:




Custom Indicators Used:
VininI_Cyber Cycle(V2)

Order Management characteristics:
It automatically opens orders when conditions are reached
Checks for the total of open orders

It Closes Orders by itself

Other Features:

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

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

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.00 Total Net Profit:0.00

BackTest : USDCAD on H1

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

BackTest : USDCHF on H1

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

BackTest : USDJPY on H1

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

Request Backtest for VininE_Cyber_Cycle


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

Pair: Period: