CyberiaTrader

Author: Copyright c 2006, Cyberia Decisions
Price Data Components
Series array that contains close prices for each barSeries array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
Movement directional indexCommodity channel indexFractalsMoving average indicatorMACD Histogram
0 Views
0 Downloads
0 Favorites
CyberiaTrader
ÿþ//+------------------------------------------------------------------+

//|                       CyberiaTrader(barabashkakvn's edition).mq5 |

//|        #property copyright "Copyright c 2006, Cyberia Decisions" |

//|                           #property link "http://cyberia.org.ru" |

//+------------------------------------------------------------------+

#property copyright "Copyright c 2006, Cyberia Decisions"

#property link      "http://cyberia.org.ru"

#property version   "1.001"



#include <Trade\SymbolInfo.mqh>  

#include <Trade\AccountInfo.mqh>

#include <Trade\Trade.mqh>

#include <Trade\PositionInfo.mqh>

CSymbolInfo    m_symbol;               // symbol info object

CAccountInfo   m_account;              // account info wrapper

CTrade         m_trade;                // trading object

CPositionInfo  m_position;             // trade position object



#define DECISION_BUY 1

#define DECISION_SELL 0

#define DECISION_UNKNOWN -1



#define MODE_PLUSDI 1

#define MODE_MINUSDI 2



#define MODE_UPPER 0

#define MODE_LOWER 1



#define MODE_MAIN 0



//--- input parameters

input bool ExitMarket=false;

input bool ShowSuitablePeriod=false;

input bool ShowMarketInfo=false;

input bool ShowAccountStatus=false;

input bool ShowStat=false;

input bool ShowDecision=false;

input bool ShowDirection=false;

input bool BlockSell= false;

input bool BlockBuy = false;

input bool ShowLots = false;

input bool BlockStopLoss=false;

input bool DisableShadowStopLoss=true;

input bool DisableExitSell= false;

input bool DisableExitBuy = false;

input bool EnableMACD=false;

input bool EnableMA=false;

input bool EnableFractals=false;

input bool EnableCCI=false;

input bool EnableCyberiaLogic = true;

input bool EnableLogicTrading = true;

input bool EnableADX=false;

input bool BlockPipsator=true;

input bool EnableMoneyTrain=false;

input bool EnableReverceDetector=false;

input double ReverceIndex=3;

input double MoneyTrainLevel=4;

input int MACDLevel = 10;

input bool AutoLots = true;

input bool AutoDirection=true;

input double ValuesPeriodCount=6;

input double ValuesPeriodCountMax=6;

double SlipPage=1;

input double Lots=0.1;                 // lots

double StopLoss=0;

double TakeProfit=0;

input double SymbolsCount=1;

input double Risk=0.5;

input double StopLossIndex=1.1;

input bool AutoStopLossIndex= true;

input double StaticStopLoss = 7;

double StopLevel;



bool DisableSell= false;

bool DisableBuy = false;

bool ExitSell= false;

bool ExitBuy = false;

double Disperce=0;

double DisperceMax=0;

bool DisableSellPipsator= false;

bool DisableBuyPipsator = false;

//---

int ValuePeriod=1;

double ValuePeriodPrev=1;

int FoundOpenedPosition=false;

bool DisablePipsator=false;

double BidPrev = 0;

double AskPrev = 0;

//--- variables for assessment of quality of modeling

double BuyPossibilityQuality;

double SellPossibilityQuality;

double UndefinedPossibilityQuality;

double PossibilityQuality;

double QualityMax=0;

//---

double BuySucPossibilityQuality;

double SellSucPossibilityQuality;

double UndefinedSucPossibilityQuality;

double PossibilitySucQuality;

//---

double ModelingPeriod;

double ModelingBars;

//---

double Spread;

int Decision;

double DecisionValue;

double PrevDecisionValue;

//---

ulong m_ticket;

int pos_total,cnt;

//---

double BuyPossibility;

double SellPossibility;

double UndefinedPossibility;

double BuyPossibilityPrev;

double SellPossibilityPrev;

double UndefinedPossibilityPrev;

//---

double BuySucPossibilityMid; // A@54=OO 25@>OB=>ABL CA?5H=>9 ?>:C?:8 // average probability of successful purchase

double SellSucPossibilityMid; // A@54=OO 25@>OB=>ABL CA?5H=>9 ?@>4068 // average probability of successful sale

double UndefinedSucPossibilityMid; // A@54=OO CA?5H=0O 25@>OB=>ABL =5>?@545;5==>3> A>AB>O=8O // average successful probability of an uncertain state

//---

double SellSucPossibilityCount; // :>;8G5AB2> 25@>OB=>AB59 CA?5H=>9 ?@>4068 // amount of probabilities of successful sale

double BuySucPossibilityCount; // :>;8G5AB2> 25@>OB=>AB59 CA?5H=>9 ?>:C?:8 // amount of probabilities of successful purchase

double UndefinedSucPossibilityCount; // :>;8G5AB2> 25@>OB=>AB59 =5>?@545;5==>3> A>AB>O=8O // amount of probabilities of an uncertain state

//---

double BuyPossibilityMid; // A@54=OO 25@>OB=>ABL ?>:C?:8 // average probability of purchase

double SellPossibilityMid; // A@54=OO 25@>OB=>ABL ?@>4068 // average probability of sale

double UndefinedPossibilityMid; // A@54=OO 25@>OB=>ABL =5>?@545;5==>3> A>AB>O=8O // average probability of an uncertain state

//---

double SellPossibilityCount; // :>;8G5AB2> 25@>OB=>AB59 ?@>4068 // amount of probabilities of sale

double BuyPossibilityCount; // :>;8G5AB2> 25@>OB=>AB59 ?>:C?:8 // amount of probabilities of purchase

double UndefinedPossibilityCount; // :>;8G5AB2> 25@>OB=>AB59 =5>?@545;5==>3> A>AB>O=8O // amount of probabilities of an uncertain state

//--- ?5@5<5==K5 4;O E@0=5=8O 8=D>@<0F8O > @K=:5 //--- variables for storage information on the market

double ModeLow;

double ModeHigh;

datetime ModeTime;

double ModeBid;

double ModeAsk;

double ModePoint;

int ModeDigits;

int ModeSpread;

int ModeStopLevel;

double ModeLotSize;

double ModeTickValue;

double ModeTickSize;

double ModeSwapLong;

double ModeSwapShort;

datetime ModeStarting;

datetime ModeExpiration;

ENUM_SYMBOL_TRADE_MODE ModeTradeAllowed;

double ModeMinLot;

double ModeLotStep;

//---

double ExtLots=0.0;

bool   ExtBlockBuy=false;

bool   ExtBlockSell=false;

bool   ExtDisableExitSell= false;

bool   ExtDisableExitBuy = false;

double ExtStopLoss=0;

double ExtStopLevel;

double ExtValuesPeriodCount=23;

double ExtStopLossIndex=1.1;

int    handle_iADX;        // variable for storing the handle of the iADX indicator 

int    handle_iCCI;        // variable for storing the handle of the iCCI indicator 

int    handle_iFractals;   // variable for storing the handle of the iFractals indicator 

int    handle_iMA;         // variable for storing the handle of the iMA indicator 

int    handle_iMACD;       // variable for storing the handle of the iMACD indicator 

//+------------------------------------------------------------------+

//| !G8BK205< 8=D>@<0F8N > @K=:5                                     |

//| We read out information on the market                            |

//+------------------------------------------------------------------+

int GetMarketInfo()

  {

//--- refresh rates

   m_symbol.Refresh();

   if(!m_symbol.RefreshRates())

      return(0);

//--- read the information on the market

   ModeLow=m_symbol.BidLow();

   ModeHigh = m_symbol.BidHigh();

   ModeTime = m_symbol.Time();

   ModeBid = m_symbol.Bid();

   ModeAsk = m_symbol.Ask();

   ModePoint=m_symbol.Point();

   ModeDigits = m_symbol.Digits();

   ModeSpread = m_symbol.Spread();

   ModeStopLevel=m_symbol.StopsLevel();

   ModeLotSize=m_symbol.ContractSize();

   ModeTickValue= m_symbol.TickValue();

   ModeTickSize = m_symbol.TickSize();

   ModeSwapLong = m_symbol.SwapLong();

   ModeSwapShort= m_symbol.SwapShort();

   m_symbol.InfoInteger(SYMBOL_START_TIME,ModeStarting);

   m_symbol.InfoInteger(SYMBOL_EXPIRATION_TIME,ModeExpiration);

   ModeTradeAllowed=m_symbol.TradeMode();

   ModeMinLot=m_symbol.LotsMin();

   ModeLotStep=m_symbol.LotsStep();

//--- 2K2>48< 8=D>@<0F8N > @K=:5 //--- we output information on the market

   if(ShowMarketInfo)

     {

      Print("ModeLow:",DoubleToString(ModeLow,Digits()));

      Print("ModeHigh:",DoubleToString(ModeHigh,Digits()));

      Print("ModeTime:",TimeToString(ModeTime,TIME_DATE|TIME_MINUTES));

      Print("ModeBid:",DoubleToString(ModeBid,Digits()));

      Print("ModeAsk:",DoubleToString(ModeAsk,Digits()));

      Print("ModePoint:",DoubleToString(ModePoint,Digits()));

      Print("ModeDigits:",ModeDigits);

      Print("ModeSpread:",ModeSpread);

      Print("ModeStopLevel:",ModeStopLevel);

      Print("ModeLotSize:",DoubleToString(ModeLotSize,2));

      Print("ModeTickValue:",DoubleToString(ModeTickValue,Digits()));

      Print("ModeTickSize:",DoubleToString(ModeTickSize,Digits()));

      Print("ModeSwapLong:",DoubleToString(ModeSwapLong,Digits()));

      Print("ModeSwapShort:",DoubleToString(ModeSwapShort,Digits()));

      Print("ModeStarting:",TimeToString(ModeStarting,TIME_DATE|TIME_MINUTES));

      Print("ModeExpiration:",TimeToString(ModeExpiration,TIME_DATE|TIME_MINUTES));

      Print("ModeTradeAllowed:",EnumToString(ModeTradeAllowed));

      Print("ModeMinLot:",DoubleToString(ModeMinLot,2));

      Print("ModeLotStep:",DoubleToString(ModeLotStep,2));

     }

   return (0);

  }

//+------------------------------------------------------------------+

//|  0AG5B :>;8G5AB20 ;>B>2                                          |

//| Calculation of quantity of lots                                  |

//+------------------------------------------------------------------+

int CyberiaLots()

  {

   GetMarketInfo();

   double S;                           // AC<<0 AG5B0 // account sum

   if(AutoLots==true)                  // AB>8<>ABL >4=>3> ?C=:B0 // cost of one point

     {

      if(SymbolsCount!=PositionsTotal())

        {

         S=(m_account.Balance()*Risk-m_account.Margin())*m_account.Leverage()/

           (SymbolsCount-PositionsTotal());

        }

      else

        {

         S=0;

        }

      //--- ?@>25@O5<, O2;O5BAO ;8 20;NB0 ?> 52@> // we check whether the currency for euro is

      if(ModeBid==0) // 70I8B0 >B 45;5=8O =0 =>;L // protection against division into zero

         return(0);

      if(StringFind(Symbol(),"USD",0)==-1)

        {

         if(StringFind(Symbol(),"EUR",0)==-1)

           {

            S=0;

           }

         else

           {

            S=S/iClose("EURUSD",0,0);

            if(StringFind(Symbol(),"EUR",0)!=0)

              {

               S/=ModeBid;

              }

           }

        }

      else

        {

         if(StringFind(Symbol(),"USD",0)!=0)

           {

            S/=ModeBid;

           }

        }

      S /= ModeLotSize;

      S -= ModeMinLot;

      S /= ModeLotStep;

      S=NormalizeDouble(S,0);

      S *= ModeLotStep;

      S += ModeMinLot;

      ExtLots=S;

      if(ShowLots==true)

         Print("Lots:",ExtLots);

     }

   return (0);

  }

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit(void)

  {

   m_symbol.Name(Symbol());         // sets symbol name

   ExtLots=Lots;

   ExtBlockBuy=BlockBuy;

   ExtBlockSell=BlockSell;

   ExtDisableExitSell=DisableExitSell;

   ExtDisableExitBuy=DisableExitBuy;

   ExtValuesPeriodCount=ValuesPeriodCount;

   ExtStopLossIndex=StopLossIndex;

   ExtStopLoss=StopLoss;



//--- create handle of the indicator iADX

   handle_iADX=iADX(Symbol(),PERIOD_CURRENT,14);

//--- if the handle is not created 

   if(handle_iADX==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the iADX indicator for the symbol %s/%s, error code %d",

                  Symbol(),

                  EnumToString(PERIOD_CURRENT),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }



//--- create handle of the indicator iCCI

   handle_iCCI=iCCI(Symbol(),PERIOD_CURRENT,13,PRICE_TYPICAL);

//--- if the handle is not created 

   if(handle_iCCI==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the iCCI indicator for the symbol %s/%s, error code %d",

                  Symbol(),

                  EnumToString(PERIOD_CURRENT),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }



//--- create handle of the indicator iFractals

   handle_iFractals=iFractals(Symbol(),PERIOD_CURRENT);

//--- if the handle is not created 

   if(handle_iFractals==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the iFractals indicator for the symbol %s/%s, error code %d",

                  Symbol(),

                  EnumToString(PERIOD_CURRENT),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }



//--- create handle of the indicator iMA

   handle_iMA=iMA(Symbol(),PERIOD_CURRENT,1,0,MODE_EMA,PRICE_CLOSE);

//--- if the handle is not created 

   if(handle_iMA==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d",

                  Symbol(),

                  EnumToString(PERIOD_CURRENT),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }



//--- create handle of the indicator iMACD

   handle_iMACD=iMACD(Symbol(),PERIOD_CURRENT,2,4,1,PRICE_CLOSE);

//--- if the handle is not created 

   if(handle_iMACD==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the iMACD indicator for the symbol %s/%s, error code %d",

                  Symbol(),

                  EnumToString(PERIOD_CURRENT),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }



   m_symbol.Name(Symbol());         // sets symbol name

   Initialization();



   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Calculate real Spread                                            |

//+------------------------------------------------------------------+

int CalculateSpread()

  {

   Spread=ModeAsk-ModeBid;

   return (0);

  }

//+------------------------------------------------------------------+

//| Calculate Possibility                                            |

//+------------------------------------------------------------------+

int CalculatePossibility(int shift)

  {

   DecisionValue=iClose(Symbol(),0,ValuePeriod*shift) -

                 iOpen(Symbol(),0,ValuePeriod*shift);

   PrevDecisionValue=iClose(Symbol(),0,ValuePeriod *(shift+1)) -

                     iOpen(Symbol(),0,ValuePeriod *(shift+1));

   SellPossibility= 0;

   BuyPossibility = 0;

   UndefinedPossibility=0;

   if(DecisionValue!=0) // 5A;8 @5H5=85 =5 >?@545;5==> // if the decision isn't certain

     {

      if(DecisionValue>0) // 5A;8 @5H5=85 2 ?>;L7C ?@>4068 // if the decision in favor of sale

        {

         //--- ?>4>7@5=85 =0 25@>OB=>ABL ?@>4068 // suspicion on probability of sale

         if(PrevDecisionValue<0) // ?>4B25@645=85 @5H5=8O 2 ?>;L7C ?@>4068 // confirmation of the decision in favor of sale

           {

            Decision=DECISION_SELL;

            BuyPossibility=0;

            SellPossibility=DecisionValue;

            UndefinedPossibility=0;

           }

         else                          // 8=0G5 @5H5=85 =5 >?@545;5=> // otherwise the decision isn't defined

           {

            Decision=DECISION_UNKNOWN;

            UndefinedPossibility=DecisionValue;

            BuyPossibility=0;

            SellPossibility=0;

           }

        }

      else                             // 5A;8 @5H5=85 2 ?>;L7C ?>:C?:8 // if the decision in favor of purchase

        {

         if(PrevDecisionValue>0) // ?>4B25@645=85 @5H5=8O 2 ?>;L7C ?@>4068 // confirmation of the decision in favor of sale

           {

            Decision=DECISION_BUY;

            SellPossibility=0;

            UndefinedPossibility=0;

            BuyPossibility=-1*DecisionValue;

           }

         else                          // @5H5=85 =5 >?@545;5=> // the decision isn't defined

           {

            Decision=DECISION_UNKNOWN;

            UndefinedPossibility=-1*DecisionValue;

            SellPossibility= 0;

            BuyPossibility = 0;

           }

        }

     }

   else

     {

      Decision=DECISION_UNKNOWN;

      UndefinedPossibility=0;

      SellPossibility= 0;

      BuyPossibility = 0;

     }

   return (Decision);

  }

//+------------------------------------------------------------------+

//| KG8A;O5< AB0B8AB8:C 25@>OB=>AB59                                |

//| Calculate statistics of probabilities                            |

//+------------------------------------------------------------------+

int CalculatePossibilityStat()

  {

   int i;

   BuySucPossibilityCount=0;

   SellSucPossibilityCount=0;

   UndefinedSucPossibilityCount=0;

//---

   BuyPossibilityCount=0;

   SellPossibilityCount=0;

   UndefinedPossibilityCount=0;

//--- 2KG8A;O5< A@54=85 7=0G5=8O 25@>OB=>AB8 // we calculate average values of probability

   BuySucPossibilityMid=0;

   SellSucPossibilityMid=0;

   UndefinedSucPossibilityMid=0;

   BuyPossibilityQuality=0;

   SellPossibilityQuality=0;

   UndefinedPossibilityQuality=0;

   PossibilityQuality=0;

//---

   BuySucPossibilityQuality=0;

   SellSucPossibilityQuality=0;

   UndefinedSucPossibilityQuality=0;

   PossibilitySucQuality=0;

   for(i=0; i<ModelingBars; i++)

     {

      //--- 2KG8A;O5< @5H5=85 4;O 40==>3> 8=B5@20;0 // we calculate the decision for this interval

      CalculatePossibility(i);

      //--- 5A;8 @5H5=85 4;O 7=0G5=8O i - ?@>4020BL // if - to sell the decision for value i         

      if(Decision==DECISION_SELL)

         SellPossibilityQuality++;

      //--- 5A;8 @5H5=85 4;O 7=0G5=8O i - ?>:C?0BL // if - to buy the decision for value i

      if(Decision==DECISION_BUY)

         BuyPossibilityQuality++;

      //--- 5A;8 @5H5=85 4;O 7=0G5=8O i - =5 >?@545;5=> // if the decision for value i - isn't defined

      if(Decision==DECISION_UNKNOWN)

         UndefinedPossibilityQuality++;

      //--- B5 65 >F5=:8 4;O CA?5H=KE A8BC0F89 // the same estimates for successful situations              

      if((BuyPossibility>Spread) || (SellPossibility>Spread) || 

         (UndefinedPossibility>Spread))

        {

         if(Decision==DECISION_SELL)

            SellSucPossibilityQuality++;

         if(Decision==DECISION_BUY)

            BuySucPossibilityQuality++;

         if(Decision==DECISION_UNKNOWN)

            UndefinedSucPossibilityQuality++;

        }

      //--- 2KG8A;O5< A@54=85 25@>OB=>AB8 A>1KB89 // we calculate average probabilities of events

      //--- 25@>OB=>AB8 ?>:C?:8 // probabilities of purchase

      BuyPossibilityMid*=BuyPossibilityCount;

      BuyPossibilityCount++;

      BuyPossibilityMid+=BuyPossibility;

      if(BuyPossibilityCount!=0)

         BuyPossibilityMid/=BuyPossibilityCount;

      else

         BuyPossibilityMid=0;

      //--- 25@>OB=>AB8 ?@>4068 // probabilities of sale

      SellPossibilityMid*=SellPossibilityCount;

      SellPossibilityCount++;

      SellPossibilityMid+=SellPossibility;

      if(SellPossibilityCount!=0)

         SellPossibilityMid/=SellPossibilityCount;

      else

         SellPossibilityMid=0;

      //--- 25@>OB=>AB8 =5>?@545;5==>3> A>AB>O=8O // probabilities of an uncertain state

      UndefinedPossibilityMid*=UndefinedPossibilityCount;

      UndefinedPossibilityCount++;

      UndefinedPossibilityMid+=UndefinedPossibility;

      if(UndefinedPossibilityCount!=0)

         UndefinedPossibilityMid/=UndefinedPossibilityCount;

      else

         UndefinedPossibilityMid=0;

      //--- 2KG8A;O5< A@54=85 25@>OB=>AB8 CA?5H=KE A>1KB89 // we calculate average probabilities of successful events

      if(BuyPossibility>Spread)

        {

         BuySucPossibilityMid*=BuySucPossibilityCount;

         BuySucPossibilityCount++;

         BuySucPossibilityMid+=BuyPossibility;

         if(BuySucPossibilityCount!=0)

            BuySucPossibilityMid/=BuySucPossibilityCount;

         else

            BuySucPossibilityMid=0;

        }

      if(SellPossibility>Spread)

        {

         SellSucPossibilityMid*=SellSucPossibilityCount;

         SellSucPossibilityCount++;

         SellSucPossibilityMid+=SellPossibility;

         if(SellSucPossibilityCount!=0)

            SellSucPossibilityMid/=SellSucPossibilityCount;

         else

            SellSucPossibilityMid=0;

        }

      if(UndefinedPossibility>Spread)

        {

         UndefinedSucPossibilityMid*=UndefinedSucPossibilityCount;

         UndefinedSucPossibilityCount++;

         UndefinedSucPossibilityMid+=UndefinedPossibility;

         if(UndefinedSucPossibilityCount!=0)

            UndefinedSucPossibilityMid/=UndefinedSucPossibilityCount;

         else

            UndefinedSucPossibilityMid=0;

        }

     }

   if((UndefinedPossibilityQuality+SellPossibilityQuality+BuyPossibilityQuality)!=0)

      PossibilityQuality=(SellPossibilityQuality+BuyPossibilityQuality)/

                         (UndefinedPossibilityQuality+SellPossibilityQuality+BuyPossibilityQuality);

   else

      PossibilityQuality=0;

//--- :0G5AB2> 4;O CA?5H=KE A8BC0F89 // quality for successful situations

   if((UndefinedSucPossibilityQuality+SellSucPossibilityQuality+

      BuySucPossibilityQuality)!=0)

      PossibilitySucQuality=(SellSucPossibilityQuality+BuySucPossibilityQuality)/

                            (UndefinedSucPossibilityQuality+SellSucPossibilityQuality+

                            BuySucPossibilityQuality);

   else

      PossibilitySucQuality=0;

   return (0);

  }

//+------------------------------------------------------------------+

//| Display Stats                                                    |

//+------------------------------------------------------------------+

int DisplayStat()

  {

   if(ShowStat==true)

     {

      Print("SellPossibilityMid*SellPossibilityQuality:",SellPossibilityMid*SellPossibilityQuality);

      Print("BuyPossibilityMid*BuyPossibilityQuality:",BuyPossibilityMid*BuyPossibilityQuality);

      Print("UndefinedPossibilityMid*UndefinedPossibilityQuality:",UndefinedPossibilityMid*UndefinedPossibilityQuality);

      Print("UndefinedSucPossibilityQuality:",UndefinedSucPossibilityQuality);

      Print("SellSucPossibilityQuality:",SellSucPossibilityQuality);

      Print("BuySucPossibilityQuality:",BuySucPossibilityQuality);

      Print("UndefinedPossibilityQuality:",UndefinedPossibilityQuality);

      Print("SellPossibilityQuality:",SellPossibilityQuality);

      Print("BuyPossibilityQuality:",BuyPossibilityQuality);

      Print("UndefinedSucPossibilityMid:",UndefinedSucPossibilityMid);

      Print("SellSucPossibilityMid:",SellSucPossibilityMid);

      Print("BuySucPossibilityMid:",BuySucPossibilityMid);

      Print("UndefinedPossibilityMid:",UndefinedPossibilityMid);

      Print("SellPossibilityMid:",SellPossibilityMid);

      Print("BuyPossibilityMid:",BuyPossibilityMid);

     }

   return (0);

  }   // 

//+------------------------------------------------------------------+

//| =0;878@C5< A>AB>O=85 4;O ?@8=OB8O @5H5=8O                       |

//| Analyze a state for decision-making                              |

//+------------------------------------------------------------------+

int CyberiaDecision()

  {

// KG8A;O5< AB0B8AB8:C ?5@8>40

   CalculatePossibilityStat();

// KG8A;O5< 25@>OB=>AB8 A>25@H5=8O A45;>:

   CalculatePossibility(0);

   DisplayStat();

   return(Decision);

  }

//+------------------------------------------------------------------+

//| Calculate Direction of Market                                    |

//+------------------------------------------------------------------+

int CalculateDirection()

  {

   DisableSellPipsator= false;

   DisableBuyPipsator = false;

   DisablePipsator=false;

   DisableSell= false;

   DisableBuy = false;

//----

   if(EnableCyberiaLogic==true)

     {

      AskCyberiaLogic();

     }

   if(EnableMACD==true)

      AskMACD();

   if(EnableMA==true)

      AskMA();

   if(EnableReverceDetector==true)

      ReverceDetector();

   if(EnableFractals==true)

      AskFractals();

   if(EnableCCI==true)

      AskCCI();

   if(EnableADX==true)

      AskADX();

   return (0);

  }

//+------------------------------------------------------------------+

//| Ask iADX                                                         |

//+------------------------------------------------------------------+

int AskADX()

  {

   if(iADXGet(MODE_PLUSDI,0)>iADXGet(MODE_MINUSDI,0))

     {

      DisableSell=true;

     }



   if(iADXGet(MODE_PLUSDI,0)<iADXGet(MODE_MINUSDI,0))

     {

      DisableBuy=true;

     }

   return (0);

  }

//+------------------------------------------------------------------+

//| Ask iCCI                                                         |

//+------------------------------------------------------------------+

int AskCCI()

  {

   if(iCCIGet(0)<-100)

      DisableSell=true;



   if(iCCIGet(0)>1000)

      DisableBuy=true;



   return (0);

  }

//+------------------------------------------------------------------+

//| $@0:B0;L=>5 B>@<>65=85                                           |

//| Fractal braking                                                  |

//+------------------------------------------------------------------+

int AskFractals()

  {

   int i=0;



   double F=0;

   while(iFractalsGet(MODE_UPPER,i)==0 && iFractalsGet(MODE_LOWER,i)==0)

     {

      i++;

     }



   if(iFractalsGet(MODE_UPPER,i)!=0)

     {

      ExtBlockBuy=true;

      ExtBlockSell=false;

     }



   if(iFractalsGet(MODE_LOWER,i)!=0)

     {

      ExtBlockSell= true;

      ExtBlockBuy = false;

     }



   return (0);

  }

//+------------------------------------------------------------------+

//| A;8 25@>OB=>AB8 ?@52KH0NB ?>@>38 8=25@B8@>20=8O @5H5=8O         |

//| If probabilities exceed thresholds of inverting of the decision  |

//+------------------------------------------------------------------+

int ReverceDetector()

  {

   if((BuyPossibility>BuyPossibilityMid*ReverceIndex && BuyPossibility!=0 && 

      BuyPossibilityMid!=0) || (SellPossibility>SellPossibilityMid*ReverceIndex && 

      SellPossibility!=0 && SellPossibilityMid!=0))

     {

      if(DisableSell==true)

         DisableSell=false;

      else

         DisableSell=true;

      if(DisableBuy==true)

         DisableBuy=false;

      else

         DisableBuy=true;

      //----

      if(DisableSellPipsator==true)

         DisableSellPipsator=false;

      else

         DisableSellPipsator=true;

      if(DisableBuyPipsator==true)

         DisableBuyPipsator=false;

      else

         DisableBuyPipsator=true;

     }

   return (0);

  }

//+------------------------------------------------------------------+

//| ?@0H8205< ;>38:C B>@3>2;8 CyberiaLogic(C)                       |

//| Interview logic of trade of CyberiaLogic (C)                     |

//+------------------------------------------------------------------+

int AskCyberiaLogic()

  {

//--- CAB0=02;8205< 1;>:8@>2:8 ?@8 ?045=8OE @K=:0 // we establish blocking when falling market

//--- 5A;8 @K=>: @02=><5@=> 42865BAO 2 7040==>< =0?@02;5=88 // if the market regularly moves in the set direction

   if(ValuePeriod>ValuePeriodPrev)

     {

      if(SellPossibilityMid*SellPossibilityQuality>BuyPossibilityMid*BuyPossibilityQuality)

        {

         DisableSell= false;

         DisableBuy = true;

         DisableBuyPipsator=true;

         if(SellSucPossibilityMid*SellSucPossibilityQuality>

            BuySucPossibilityMid*BuySucPossibilityQuality)

           {

            DisableSell=true;

           }

        }

      if(SellPossibilityMid*SellPossibilityQuality<BuyPossibilityMid*BuyPossibilityQuality)

        {

         DisableSell= true;

         DisableBuy = false;

         DisableSellPipsator=true;

         if(SellSucPossibilityMid*SellSucPossibilityQuality<

            BuySucPossibilityMid*BuySucPossibilityQuality)

           {

            DisableBuy=true;

           }

        }

     }

//--- 5A;8 @K=>: <5=O5B =0?@02;5=85 - =8:>340 =5 B>@3C9 ?@>B82 B@5=40!!! // if the market changes the direction - never trade against a trend!!!

   if(ValuePeriod<ValuePeriodPrev)

     {

      if(SellPossibilityMid*SellPossibilityQuality>BuyPossibilityMid*BuyPossibilityQuality)

        {

         DisableSell= true;

         DisableBuy = true;

        }

      if(SellPossibilityMid*SellPossibilityQuality<BuyPossibilityMid*BuyPossibilityQuality)

        {

         DisableSell= true;

         DisableBuy = true;

        }

     }

//--- 5A;8 @K=>: 3>@87>=B0;L=K9 // if market horizontal

   if(SellPossibilityMid*SellPossibilityQuality==BuyPossibilityMid*BuyPossibilityQuality)

     {

      DisableSell= true;

      DisableBuy = true;

      DisablePipsator=false;

     }

//--- 1;>:8@C5< 25@>OB=>ABL 2KE>40 87 @K=:0 // we block probability of an exit from the market

   if(SellPossibility>SellSucPossibilityMid*2 && SellSucPossibilityMid>0)

     {

      DisableSell=true;

      DisableSellPipsator=true;

     }

//--- 1;>:8@C5< 25@>OB=>ABL 2KE>40 87 @K=:0 // we block probability of an exit from the market

   if(BuyPossibility>BuySucPossibilityMid*2 && BuySucPossibilityMid>0)

     {

      DisableBuy=true;

      DisableBuyPipsator=true;

     }

   if(ShowDirection==true)

     {

      if(DisableSell==true)

        {

         Print("Sale is blocked: ",SellPossibilityMid*SellPossibilityQuality);

        }

      else

        {

         Print("Sale is allowed: ",SellPossibilityMid*SellPossibilityQuality);

        }

      //----

      if(DisableBuy==true)

        {

         Print("Purchase is blocked: ",BuyPossibilityMid*BuyPossibilityQuality);

        }

      else

        {

         Print("Purchase is allowed: ",BuyPossibilityMid*BuyPossibilityQuality);

        }

     }

   if(ShowDecision==true)

     {

      if(Decision==DECISION_SELL)

         Print("The decision - to sell: ",DecisionValue);

      if(Decision==DECISION_BUY)

         Print("The decision - to buy: ",DecisionValue);

      if(Decision==DECISION_UNKNOWN)

         Print("The decision - uncertainty: ",DecisionValue);

     }

   return (0);

  }

//+------------------------------------------------------------------+

//| Ask iMA                                                          |

//+------------------------------------------------------------------+

int AskMA()

  {

   if(iMAGet(0)>iMAGet(1))

     {

      DisableSell=true;

      DisableSellPipsator=true;

     }

   if(iMAGet(0)<iMAGet(1))

     {

      DisableBuy=true;

      DisableBuyPipsator=true;

     }

   return (0);

  }

//+------------------------------------------------------------------+

//| Ask iMACD                                                        |

//+------------------------------------------------------------------+

int AskMACD()

  {

   double DecisionIndex=0;

   double SellIndex= 0;

   double BuyIndex = 0;

   double BuyVector= 0;

   double SellVector= 0;

   double BuyResult = 0;

   double SellResult= 0;

   DisablePipsator=false;

   DisableSellPipsator= false;

   DisableBuyPipsator = false;

   DisableBuy=false;

   DisableSell=false;

   ExtDisableExitSell= false;

   ExtDisableExitBuy = false;

//--- 1;>:8@C5< >H81:8 // block mistakes

   if(iMACDGet(MODE_MAIN,0)<iMACDGet(MODE_MAIN,1))

     {

      SellIndex+=iMACDGet(MODE_MAIN,0);

     }

   if(iMACDGet(MODE_MAIN,0)>iMACDGet(MODE_MAIN,1))

     {

      BuyIndex+=iMACDGet(MODE_MAIN,0);

     }



   if(SellIndex>BuyIndex)

     {

      DisableBuy=true;

      DisableBuyPipsator=true;

     }

   if(SellIndex<BuyIndex)

     {

      DisableSell=true;

      DisableSellPipsator=true;

     }

   return (0);

  }

//+------------------------------------------------------------------------+

//| >28< @K=>G=K5 - - (2:;NG05BAO =5?>A@54AB25==> ?5@54 2KE>4>< =>2>AB59|

//| We catch market the GAP - (joins just before an exit of news           |

//+------------------------------------------------------------------------+

int MoneyTrain()

  {

   if(FoundOpenedPosition==false)

     {

      //--- AG8B05< 48A?5@A8N // we consider dispersion

      Disperce=(iHigh(Symbol(),0,0)-iLow(Symbol(),0,0));

      if(Decision==DECISION_SELL)

        {

         // *** ?@K38205< 2 ?0@>2>7 ?> =0?@02;5=8N 42865=8O E0>A0 @K=:0 ***

         // *** We jump into a steam locomotive in the direction of movement of chaos of the market ***

         if((iClose(Symbol(),0,0)-iClose(Symbol(),0,ValuePeriod))/

            MoneyTrainLevel >= SellSucPossibilityMid && SellSucPossibilityMid != 0 &&

            EnableMoneyTrain == true)

           {

            ModeSpread=ModeSpread+1;

            //--- @0AG5B AB>?-;>AA // calculation stop loss

            if((ModeBid-SellSucPossibilityMid*ExtStopLossIndex-ModeSpread*ModePoint)>

               (ModeBid-ModeStopLevel *ModePoint-ModeSpread*ModePoint))

              {

               ExtStopLoss=ModeBid-ModeStopLevel *ModePoint-ModeSpread*ModePoint-Disperce;

              }

            else

              {

               if(SellSucPossibilityMid!=0)

                  ExtStopLoss=ModeBid-SellSucPossibilityMid*ExtStopLossIndex-

                              ModeSpread*ModePoint-Disperce;

               else

                  ExtStopLoss=ModeBid-ModeStopLevel *ModePoint-ModeSpread*ModePoint-Disperce;

              }



            if(ExtBlockBuy==true)

              {

               return(0);

              }

            ExtStopLevel=ExtStopLoss;

            Print("StopLevel:",ExtStopLevel);

            //--- 1;>:8@>2:0 AB>?;>A>2 // blocking of stoplos

            if(BlockStopLoss==true)

               ExtStopLoss=0;

            if(m_trade.Buy(ExtLots,Symbol(),ModeAsk,ExtStopLoss,TakeProfit,"NeuroCluster-testing-AI-HB1"))

              {

               m_ticket=m_trade.ResultDeal();

               Print("Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),

                     ", description of result: ",m_trade.ResultRetcodeDescription(),

                     ", ticket of deal: ",m_trade.ResultDeal());

              }

            else

              {

               Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),

                     ", description of result: ",m_trade.ResultRetcodeDescription(),

                     ", ticket of deal: ",m_trade.ResultDeal());

               PrintErrorValues();

              }

            return (0);

           }

        }

      if(Decision==DECISION_BUY)

        {

         // *** ?@K38205< 2 ?0@>2>7 ?> =0?@02;5=8N 42865=8O E0>A0 @K=:0 ***

         // *** We jump into a steam locomotive in the direction of movement of chaos of the market ***

         if((iClose(Symbol(),0,ValuePeriod)-iClose(Symbol(),0,0))/

            MoneyTrainLevel >= BuySucPossibilityMid && BuySucPossibilityMid != 0 &&

            EnableMoneyTrain == true)

           {

            ModeSpread=ModeSpread+1;

            //--- @0AG5B AB>?-;>AAca // calculation stop loss

            if((ModeAsk+BuySucPossibilityMid*ExtStopLossIndex+ModeSpread *ModePoint)<

               (ModeAsk+ModeStopLevel *ModePoint+ModeSpread*ModePoint))

              {

               ExtStopLoss=ModeAsk+ModeStopLevel *ModePoint+ModeSpread*ModePoint+Disperce;

              }

            else

              {

               if(BuySucPossibilityMid!=0)

                  ExtStopLoss=ModeAsk+BuySucPossibilityMid*ExtStopLossIndex+ModeSpread*ModePoint+

                              Disperce;

               else

                  ExtStopLoss=ModeAsk+ModeStopLevel *ModePoint+ModeSpread*ModePoint+Disperce;

              }

            //--- 5A;8 2:;NG5=0 @CG=0O 1;>:8@>2:0 ?@>406 // if manual blocking of sales is included

            if(ExtBlockSell==true)

              {

               return(0);

              }

            ExtStopLevel=ExtStopLoss;

            Print("StopLevel:",ExtStopLevel);

            //--- 1;>:8@>2:0 AB>?;>A>2 // blocking of stoploss

            if(BlockStopLoss==true)

               ExtStopLoss=0;

            if(m_trade.Sell(ExtLots,Symbol(),ModeBid,ExtStopLoss,TakeProfit,"NeuroCluster-testing-AI-HS1"))

              {

               m_ticket=m_trade.ResultDeal();

               Print("Sell -> true. Result Retcode: ",m_trade.ResultRetcode(),

                     ", description of result: ",m_trade.ResultRetcodeDescription(),

                     ", ticket of deal: ",m_trade.ResultDeal());

              }

            else

              {

               Print("Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),

                     ", description of result: ",m_trade.ResultRetcodeDescription(),

                     ", ticket of deal: ",m_trade.ResultDeal());

               PrintErrorValues();

              }

            return (0);

           }

        }

     }

   return (0);

  }

//+------------------------------------------------------------------+

//| Entrance to the market                                           |

//+------------------------------------------------------------------+

int EnterMarket()

  {

//--- 5A;8 =5B A@54AB2, 2KE>48< // if there are no means, then leave

   if(ExtLots==0)

     {

      return (0);

     }

//--- 2E>48< 2 @K=>: 5A;8 =5B :><0=4K 2KE>40 87 @K=:0 // we enter the market if there is no team of an exit from the market

   if(ExitMarket==false)

     {

      // ------- A;8 =5B >B:@KBKE >@45@>2 - 2E>48< 2 @K=>: ------------

      // ------- If there are no open orders - enter the market ------------

      if(FoundOpenedPosition==false)

        {

         //--- AG8B05< 48A?5@A8N // we consider dispersion

         Disperce=(iHigh(Symbol(),0,0)-iLow(Symbol(),0,0));

         if(Decision==DECISION_SELL)

           {

            //--- 5A;8 F5=0 ?>:C?:8 1>;LH5 A@54=59 25;8G8=K ?>:C?:8 =0 <>45;8@C5<>< 8=B5@20;5

            //--- if the buying price is more than average size of purchase on the modelled interval

            if(SellPossibility>=SellSucPossibilityMid)

              {

               //--- @0AG5B AB>?-;>AA // calculation stop loss

               if((ModeAsk+BuySucPossibilityMid*ExtStopLossIndex+ModeSpread*ModePoint)<

                  (ModeAsk+ModeStopLevel *ModePoint+ModeSpread*ModePoint))

                 {

                  ExtStopLoss=ModeAsk+ModeStopLevel *ModePoint+ModeSpread*ModePoint+Disperce;

                 }

               else

                 {

                  if(BuySucPossibilityMid!=0)

                     ExtStopLoss=ModeAsk+BuySucPossibilityMid*ExtStopLossIndex+

                                 ModeSpread*ModePoint+Disperce;

                  else

                  ExtStopLoss=ModeAsk+ModeStopLevel *ModePoint+ModeSpread*ModePoint+

                              Disperce;

                 }

               //--- 5A;8 2:;NG5=0 @CG=0O 1;>:8@>2:0 ?@>406 // if manual blocking of sales is included

               if(DisableSell==true)

                 {

                  return(0);

                 }

               if(ExtBlockSell==true)

                 {

                  return(0);

                 }

               if(StaticStopLoss!=0)

                 {

                  ExtStopLoss=ModeAsk+StaticStopLoss*ModePoint;

                 }

               ExtStopLevel=ExtStopLoss;

               Print("StopLevel:",ExtStopLevel);

               //--- 1;>:8@>2:0 AB>?;>A>2 // blocking of stoploss

               if(BlockStopLoss==true)

                  ExtStopLoss=0;

               if(m_trade.Sell(ExtLots,Symbol(),ModeBid,ExtStopLoss,TakeProfit,"NeuroCluster-testing-AI-LS1"))

                 {

                  m_ticket=m_trade.ResultDeal();

                  Print("Sell -> true. Result Retcode: ",m_trade.ResultRetcode(),

                        ", description of result: ",m_trade.ResultRetcodeDescription(),

                        ", ticket of deal: ",m_trade.ResultDeal());

                 }

               else

                 {

                  Print("Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),

                        ", description of result: ",m_trade.ResultRetcodeDescription(),

                        ", ticket of deal: ",m_trade.ResultDeal());

                  PrintErrorValues();

                 }

               return (0);

              }

           }

         if(Decision==DECISION_BUY)

           {

            //--- 5A;8 F5=0 ?>:C?:8 1>;LH5 A@54=59 25;8G8=K ?>:C?:8 =0 <>45;8@C5<>< 8=B5@20;5

            //--- if the buying price is more than average size of purchase on the modelled interval

            if(BuyPossibility>=BuySucPossibilityMid)

              {

               //--- @0AG5B AB>?-;>AA // calculation stop loss

               if((ModeBid-SellSucPossibilityMid*ExtStopLossIndex-ModeSpread *ModePoint)>

                  (ModeBid-ModeStopLevel *ModePoint-ModeSpread *ModePoint))

                 {

                  ExtStopLoss=ModeBid-ModeStopLevel *ModePoint-ModeSpread *ModePoint-Disperce;

                 }

               else

                 {

                  if(SellSucPossibilityMid!=0)

                     ExtStopLoss=ModeBid-SellSucPossibilityMid*ExtStopLossIndex-

                                 ModeSpread *ModePoint-Disperce;

                  else

                  ExtStopLoss=ModeBid-ModeStopLevel *ModePoint-ModeSpread *ModePoint-

                              Disperce;

                 }

               //--- 5A;8 2:;NG5=0 @CG=0O 1;>:8@>2:0 ?>:C?>: // if manual blocking of purchases is included

               if(DisableBuy==true)

                 {

                  return(0);

                 }

               if(ExtBlockBuy==true)

                 {

                  return(0);

                 }

               if(StaticStopLoss!=0)

                 {

                  ExtStopLoss=ModeBid-StaticStopLoss*ModePoint;

                 }

               ExtStopLevel=ExtStopLoss;

               Print("StopLevel:",ExtStopLevel);

               //--- 1;>:8@>2:0 AB>?;>A>2 // blocking of stoploss

               if(BlockStopLoss==true)

                  ExtStopLoss=0;

               if(m_trade.Buy(ExtLots,Symbol(),ModeAsk,ExtStopLoss,TakeProfit,"NeuroCluster-testing-AI-LB1"))

                 {

                  m_ticket=m_trade.ResultDeal();

                  Print("Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),

                        ", description of result: ",m_trade.ResultRetcodeDescription(),

                        ", ticket of deal: ",m_trade.ResultDeal());

                 }

               else

                 {

                  Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),

                        ", description of result: ",m_trade.ResultRetcodeDescription(),

                        ", ticket of deal: ",m_trade.ResultDeal());

                  PrintErrorValues();

                 }

               return (0);

              }

           }

        }

      // ---------------- >=5F 2E>40 2 @K=>: ----------------------    

      // ---------------- The end of an entrance to the market ----------------------    

     }

   return (0);

  }

//+------------------------------------------------------------------+

//| >8A: >B:@KBKE ?>87F89                                           |

//| Search of open positions                                         |

//+------------------------------------------------------------------+

int FindSymbolPosition()

  {

   FoundOpenedPosition=false;

   pos_total=PositionsTotal();

   for(cnt=0; cnt<pos_total; cnt++)

     {

      m_position.SelectByIndex(cnt);

      //--- 8I5< ?>78F8N ?> =0H59 20;NB5 // we look for a position on our currency

      if(m_position.Symbol()==Symbol())

        {

         FoundOpenedPosition=true;

         break;

        }

      else

        {

         ExtStopLevel= 0;

         ExtStopLoss = 0;

        }

     }

   return (0);

  }

//+------------------------------------------------------------------+

//| Run Pipsator                                                     |

//+------------------------------------------------------------------+

int RunPipsator()

  {

   int i=0;

   FindSymbolPosition();

//--- 2E>48< 2 @K=>: 5A;8 =5B :><0=4K 2KE>40 87 @K=:0 // we enter the market if there is no team of an exit from the market

//--- AG8B05< 48A?5@A8N // we consider dispersion

   if(ExtLots==0)

      return (0);

   Disperce=0;

   if(ExitMarket==false)

     {

      // ---------- A;8 =5B >B:@KBKE ?>78F89 - 2E>48< 2 @K=>: ----------

      // ---------- If there are no open Positions - enter the market ----------

      if(FoundOpenedPosition==false)

        {

         Disperce=0;

         DisperceMax=0;

         //--- AG8B05< <0:A8<0;L=CN 48A?5@A8N // we consider the maximum dispersion

         for(i=0; i<ValuePeriod; i++)

           {

            Disperce=(iHigh(Symbol(),0,i+1) -

                      iLow(Symbol(),0,i+1));

            if(Disperce>DisperceMax)

               DisperceMax=Disperce;

           }

         Disperce=DisperceMax *ExtStopLossIndex;

         if(Disperce==0)

           {

            Disperce=ModeStopLevel*ModePoint;

           }

         for(i=0; i<ValuePeriod; i++)

           {

            //--- ?8?A0B>@ <8=CB=>3> 8=B5@20;0 ?> ?@>4065 pipsator of a minute interval on sale

            if((ModeBid-iClose(Symbol(),0,i+1))>

               SellSucPossibilityMid *(i+1) && 

               SellSucPossibilityMid!=0 && DisablePipsator==false && 

               DisableSellPipsator==false)

              {

               //--- @0AG5B AB>?-;>AA // calculation stop loss

               if((ModeAsk+ModeSpread*ModePoint+Disperce)<

                  (ModeAsk+ModeStopLevel *ModePoint+ModeSpread*ModePoint))

                 {

                  ExtStopLoss=ModeAsk+ModeStopLevel *ModePoint+ModeSpread*ModePoint+ModePoint;

                 }

               else

                 {

                  if(BuySucPossibilityMid!=0)

                     ExtStopLoss=ModeAsk+ModeSpread*ModePoint+Disperce+ModePoint;

                  else

                     ExtStopLoss=ModeAsk+ModeStopLevel *ModePoint+ModeSpread*ModePoint+ModePoint;

                 }

               //--- 5A;8 2:;NG5=0 @CG=0O 1;>:8@>2:0 ?@>406 // if manual blocking of sales is included

               if(ExtBlockSell==true)

                 {

                  return(0);

                 }

               //--- 5A;8 2:;NG5=0 @CG=0O 1;>:8@>2:0 ?@>406 // if manual blocking of sales is included

               if(DisableSell==true)

                 {

                  return(0);

                 }



               if(StaticStopLoss!=0)

                 {

                  ExtStopLoss=ModeAsk+StaticStopLoss*ModePoint;

                 }



               ExtStopLevel=ExtStopLoss;

               Print("StopLevel:",ExtStopLevel);

               //--- 1;>:8@>2:0 AB>?;>A>2 // blocking of stoploss

               if(BlockStopLoss==true)

                  ExtStopLoss=0;

               if(m_trade.Sell(ExtLots,Symbol(),ModeBid,ExtStopLoss,TakeProfit,"NeuroCluster-testing-AI-PS1"))

                 {

                  m_ticket=m_trade.ResultDeal();

                  Print("Sell -> true. Result Retcode: ",m_trade.ResultRetcode(),

                        ", description of result: ",m_trade.ResultRetcodeDescription(),

                        ", ticket of deal: ",m_trade.ResultDeal());

                 }

               else

                 {

                  Print("Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),

                        ", description of result: ",m_trade.ResultRetcodeDescription(),

                        ", ticket of deal: ",m_trade.ResultDeal());

                  PrintErrorValues();

                 }

               return (0);

              }

            //--- ?8?A0B>@ <8=CB=>3> 8=B5@20;0 ?> ?>:C?:5 // pipsator of a minute interval on purchase

            if((iClose(Symbol(),0,i+1)-ModeBid)>BuySucPossibilityMid *(i+1) && 

               BuySucPossibilityMid!=0 && DisablePipsator==false && 

               DisableBuyPipsator==false)

              {

               //--- @0AG5B AB>?-;>AAca // calculation stop loss

               if((ModeBid-ModeSpread*ModePoint-Disperce)>

                  (ModeBid-ModeStopLevel *ModePoint-ModeSpread*ModePoint))

                 {

                  ExtStopLoss=ModeBid-ModeStopLevel *ModePoint-ModeSpread*ModePoint-ModePoint;

                 }

               else

                 {

                  if(SellSucPossibilityMid!=0)

                     ExtStopLoss=ModeBid-ModeSpread*ModePoint-Disperce-ModePoint;

                  else

                     ExtStopLoss=ModeBid-ModeStopLevel *ModePoint-ModeSpread*ModePoint-ModePoint;

                 }

               //--- 5A;8 2:;NG5=0 @CG=0O 1;>:8@>2:0 // if manual blocking is included

               if(DisableBuy==true)

                 {

                  return(0);

                 }

               if(ExtBlockBuy==true)

                 {

                  return(0);

                 }

               if(StaticStopLoss!=0)

                 {

                  ExtStopLoss=ModeBid-StaticStopLoss*ModePoint;

                 }

               ExtStopLevel=ExtStopLoss;

               Print("StopLevel:",ExtStopLevel);

               //--- 1;>:8@>2:0 AB>?;>A>2 // blocking of stoploss

               if(BlockStopLoss==true)

                  ExtStopLoss=0;

               if(m_trade.Buy(ExtLots,Symbol(),ModeAsk,ExtStopLoss,TakeProfit,"NeuroCluster-testing-AI-PB1"))

                 {

                  m_ticket=m_trade.ResultDeal();

                  Print("Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),

                        ", description of result: ",m_trade.ResultRetcodeDescription(),

                        ", ticket of deal: ",m_trade.ResultDeal());

                 }

               else

                 {

                  Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),

                        ", description of result: ",m_trade.ResultRetcodeDescription(),

                        ", ticket of deal: ",m_trade.ResultDeal());

                  PrintErrorValues();

                 }

               return (0);

              }

           }  // :>=5F ?8?A0B>@=>3> F8:;0 // end of a pipsatorny cycle           

        }

     }

   return (0);

  }

//+------------------------------------------------------------------+

//| Exit from Market                                                 |

//+------------------------------------------------------------------+

int ExitMarket()

  {

// -------------------- 1@01>B:0 >B:@KBKE ?>78F89 ----------------

// -------------------- Processing of open positions ----------------

   if(FoundOpenedPosition==true)

     {

      if(m_position.PositionType()==POSITION_TYPE_BUY)

        {

         // 0:@KB85 >@45@0, 5A;8 >= 4>AB83 C@>2=O AB>?-;>AA

         if(ModeBid<=ExtStopLevel && DisableShadowStopLoss==false && ExtStopLevel!=0)

           {

            m_trade.PositionClose(m_position.Ticket());

            return(0);

           }



         if(ExtDisableExitBuy==true)

            return (0);



         //--- =5 2KE>48< 87 @K=:0, 5A;8 8<55< E0>A, @01>B0NI89 =0 ?@81K;L

         //--- we don't leave the market if we have the chaos working for profit

         if((iClose(Symbol(),0,0)-iClose(Symbol(),0,1))>=

            SellSucPossibilityMid*4 && SellSucPossibilityMid>0)

            return(0);



         //--- 70:@KB85 ?> ?@52KH5=8N 25@>OB=>AB8 CA?5H=>9 ?@>4068

         //--- closing on excess of probability of successful sale

         if((m_position.PriceOpen()<ModeBid) && ((ModeBid-m_position.PriceOpen())>=

            SellSucPossibilityMid) && (SellSucPossibilityMid>0))

           {

            m_trade.PositionClose(m_position.Ticket());

            return(0);

           }



         //--- 70:@KB85 ?> ?@52KH5=8N 25@>OB=>AB8 CA?5H=>9 ?>:C?:8

         //--- closing on excess of probability of successful purchase

         if((m_position.PriceOpen()<ModeBid) && (ModeBid-m_position.PriceOpen()>=

            BuySucPossibilityMid) && (BuySucPossibilityMid>0))

           {

            m_trade.PositionClose(m_position.Ticket());

            return(0);

           }



         //--- 70:@KB85 ?8?A0B>@0 // closing of a pipsator

         if((m_position.PriceOpen()<ModeBid) && BuySucPossibilityMid==0 && SellSucPossibilityMid==0)

           {

            m_trade.PositionClose(m_position.Ticket());

            return(0);

           }



        }

      if(m_position.PositionType()==POSITION_TYPE_SELL)

        {

         //--- 70:@KB85, 5A;8 4>AB83=CB C@>25=L AB>?-;>AA // closing if reach level stop loss

         if(ModeAsk>=ExtStopLevel && DisableShadowStopLoss==false && ExtStopLevel!=0)

           {

            m_trade.PositionClose(m_position.Ticket());

            return(0);

           }



         if(ExtDisableExitSell==true)

            return (0);



         //--- =5 2KE>48< 87 @K=:0, 5A;8 8<55< E0>A, @01>B0NI89 =0 ?@81K;L

         //--- we don't leave the market if we have the chaos working for profit

         if((iClose(Symbol(),0,1)-iClose(Symbol(),0,0))>=BuySucPossibilityMid*4 && BuySucPossibilityMid>0)

            return (0);



         //--- 70:@KB85 ?> D0:BC ?@52KH5=8O 25@>OB=>AB8 CA?5H=>9 ?>:C?:8

         //--- closing upon excess of probability of successful purchase

         if((m_position.PriceOpen()>ModeAsk) && (m_position.PriceOpen()-ModeAsk)>=

            BuySucPossibilityMid && BuySucPossibilityMid>0)

           {



            m_trade.PositionClose(m_position.Ticket()); //

           }



         //--- 70:@KB85 ?> D0:BC ?@52KI5=8O 25@>OB=>AB8 CA?5H=>9 ?@>4068

         //--- closing upon excess of probability of successful sale

         if((m_position.PriceOpen()>ModeAsk) && (m_position.PriceOpen()-ModeAsk)>=

            SellSucPossibilityMid && SellSucPossibilityMid>0)

           {

            m_trade.PositionClose(m_position.Ticket());

            return(0);

           }



         //--- 70:@KB85 ?8?A0B>@0 // closing of a pipsator

         if((m_position.PriceOpen()>ModeAsk) && BuySucPossibilityMid==0 && SellSucPossibilityMid==0)

           {

            m_trade.PositionClose(m_position.Ticket());

            return(0);

           }



        }

     }

// --------------------- >=5F >1@01>B:8 >B:@KBKE ?>78F89  -----------

//--------------------- The end of processing of open positions -----------

   return (0);

  }

//+--------------------------------------------------------------------------+

//| !>E@0=O5< 7=0G5=8O AB02>: 8 ?5@8>40 <>45;8@>20=8O 4;O A;54CNI59 8B5@@0F88|

//| Keep values of rates and the period of modeling for the following iteration |

//+--------------------------------------------------------------------------+

int SaveStat()

  {

   BidPrev = ModeBid;

   AskPrev = ModeAsk;

   ValuePeriodPrev=ValuePeriod;

   return (0);

  }

//+------------------------------------------------------------------+

//| Trade                                                            |

//+------------------------------------------------------------------+

int Trade()

  {

//--- =0G8=05< B>@3>20BL // we begin to trade

//--- 8I5< >B:@KBK5 ?>78F88 // we look for open positions

   FindSymbolPosition();

   CalculateDirection();

   AutoStopLossIndex();

//--- 5A;8 >B:@KBKE ?>78F89 ?> A8<2>;C =5B, 2>7<>65= 2E>4 2 @K=>:

//--- if there are no open line items on a symbol, the entrance to the market is possible

//--- 2=8<0=85 - 2065= 8<5==> MB>B ?>@O4>: @0AA<>B@5=8O B5E=>;>389 2E>40 2 @K=>: (MoneyTrain, LogicTrading, Pipsator)

//--- attention - this order of consideration of technologies of an entrance to the market is important (MoneyTrain, LogicTrading, Pipsator)

   if(FoundOpenedPosition==false)

     {

      if(EnableMoneyTrain==true)

         MoneyTrain();

      if(EnableLogicTrading==true)

         EnterMarket();

      if(DisablePipsator==false && BlockPipsator==false)

         RunPipsator();

     }

   else

     {

      ExitMarket();

     }

//--- :>=5F >1@01>B:8 2E>40/2KE>40 87 @K=:0 // the end of processing of an input and output from the market

   return(0);

  }

//+------------------------------------------------------------------+

//| Account Status                                                   |

//+------------------------------------------------------------------+

int AccountStatus()

  {

   if(ShowAccountStatus==true)

     {

      Print("AccountBalance:",m_account.Balance());

      Print("AccountCompany:",m_account.Company());

      Print("AccountCredit:",m_account.Credit());

      Print("AccountCurrency:",m_account.Currency());

      Print("AccountEquity:",m_account.Equity());

      Print("AccountFreeMargin:",m_account.FreeMargin());

      Print("AccountLeverage:",m_account.Leverage());

      Print("AccountMargin:",m_account.Margin());

      Print("AccountName:",m_account.Name());

      Print("AccountNumber:",m_account.Login());

      Print("AccountProfit:",m_account.Profit());

     }

   return ( 0 );

  }

//+------------------------------------------------------------------+

//| !0<0O 206=0O DC=:F8O - 2K1>@ ?5@8>40 <>45;8@>20=8O               |

//| Most important function - the choice of the period of modeling   |

//+------------------------------------------------------------------+

int FindSuitablePeriod()

  {

   double SuitablePeriodQuality=-1 *ValuesPeriodCountMax*ValuesPeriodCountMax;

   int SuitablePeriod=0;

   int i; // ?5@5<5==0O 4;O 0=0;870 ?5@8>4>2 // variable for the analysis of the periods

//--- :>;8G5AB2> 0=0;878@C5<KE ?5@8>4>2. i - @07<5@ ?5@8>40

//--- amount of the analyzed periods. i - period size

   for(i=0; i<ValuesPeriodCountMax; i++)

     {

      ValuePeriod=i+1;

      //--- 7=0G5=85 ?>4>1@0=> >?KB=K< ?CB5< 8 :0: =8 AB@0==> >=> A>2?0;> A G8A;>< 2 B5>@88 M;;8>B0

      //--- value is picked up by practical consideration and strangely enough it has coincided with number in Elliot's theory

      ExtValuesPeriodCount=ValuePeriod*5;

      Initialization();

      CalculatePossibilityStat();

      if(PossibilitySucQuality>SuitablePeriodQuality)

        {

         SuitablePeriodQuality=PossibilitySucQuality;

         //Print ("PossibilitySucQuality:", PossibilitySucQuality:);

         SuitablePeriod=i+1;

        }

     }

   ValuePeriod=SuitablePeriod;

   Initialization();



   if(ShowSuitablePeriod==true)

     {

      Print("Modeling period: ",SuitablePeriod," minutes with probability :",

            SuitablePeriodQuality);

     }

   return(SuitablePeriod);

  }

//+------------------------------------------------------------------+

//| 2B><0B8G5A:0O CAB0=>2:0 C@>2=O AB>?-;>AA                        |

//| Automatic installation of level stop loss                        |

//+------------------------------------------------------------------+

int AutoStopLossIndex()

  {

   if(AutoStopLossIndex==true)

     {

      ExtStopLossIndex=ModeSpread;

     }

   return(0);

  }

//+------------------------------------------------------------------+

//| K2>4 >H81>: ?@8 2E>45 2 @K=>:                                   |

//| Print of mistakes at an entrance to the market                   |

//+------------------------------------------------------------------+

int PrintErrorValues()

  {

   Print("ErrorValues:Symbol=",Symbol(),",Lots=",ExtLots,",Bid=",ModeBid,",Ask=",ModeAsk,

         ",SlipPage=",SlipPage,"StopLoss=",ExtStopLoss,",TakeProfit=",TakeProfit);

   return (0);

  }

//+------------------------------------------------------------------+

//| Expert new tick handling function                                |

//+------------------------------------------------------------------+

void OnTick(void)

  {

   GetMarketInfo();

   CyberiaLots();

   CalculateSpread();

   FindSuitablePeriod();

   CyberiaDecision();

   Trade();

   SaveStat();

   return;

  }

//+------------------------------------------------------------------+

//| Get value of buffers for the iADX                                |

//|  the buffer numbers are the following:                           |

//|   0 - iADXBuffer, 1 - DI_plusBuffer, 2 - DI_minusBuffer          |

//+------------------------------------------------------------------+

double iADXGet(const int buffer,const int index)

  {

   double ADX[];

   ArraySetAsSeries(ADX,true);

//--- reset error code 

   ResetLastError();

//--- fill a part of the iADXBuffer array with values from the indicator buffer that has 0 index 

   if(CopyBuffer(handle_iADX,buffer,0,index+1,ADX)<0)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the iADX indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(0.0);

     }

   return(ADX[index]);

  }

//+------------------------------------------------------------------+

//| Get value of buffers for the iCCI                                |

//+------------------------------------------------------------------+

double iCCIGet(const int index)

  {

   double CCI[];

   ArraySetAsSeries(CCI,true);

//--- reset error code 

   ResetLastError();

//--- fill a part of the iCCIBuffer array with values from the indicator buffer that has 0 index 

   if(CopyBuffer(handle_iCCI,0,0,index+1,CCI)<0)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the iCCI indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(0.0);

     }

   return(CCI[index]);

  }

//+------------------------------------------------------------------+

//| Get value of buffers for the iFractals                           |

//|  the buffer numbers are the following:                           |

//|   0 - UPPER_LINE, 1 - LOWER_LINE                                 |

//+------------------------------------------------------------------+

double iFractalsGet(const int buffer,const int index)

  {

   double Fractals[];

   ArraySetAsSeries(Fractals,true);

//--- reset error code 

   ResetLastError();

//--- fill a part of the iADXBuffer array with values from the indicator buffer that has 0 index 

   if(CopyBuffer(handle_iFractals,buffer,0,index+1,Fractals)<0)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the iFractals indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(0.0);

     }

   return(Fractals[index]);

  }

//+------------------------------------------------------------------+

//| Get value of buffers for the iMA                                 |

//+------------------------------------------------------------------+

double iMAGet(const int index)

  {

   double MA[];

   ArraySetAsSeries(MA,true);

//--- reset error code 

   ResetLastError();

//--- fill a part of the iCCIBuffer array with values from the indicator buffer that has 0 index 

   if(CopyBuffer(handle_iMA,0,0,index+1,MA)<0)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(0.0);

     }

   return(MA[index]);

  }

//+------------------------------------------------------------------+

//| Get value of buffers for the iMACD                               |

//|  the buffer numbers are the following:                           |

//|   0 - MAIN_LINE, 1 - SIGNAL_LINE                                 |

//+------------------------------------------------------------------+

double iMACDGet(const int buffer,const int index)

  {

   double MACD[];

   ArraySetAsSeries(MACD,true);

//--- reset error code 

   ResetLastError();

//--- fill a part of the iMACDBuffer array with values from the indicator buffer that has 0 index 

   if(CopyBuffer(handle_iMACD,buffer,0,index+1,MACD)<0)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the iMACD indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(0.0);

     }

   return(MACD[index]);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int Initialization()

  {

   AccountStatus();

   GetMarketInfo();

   ModelingPeriod=ValuePeriod*ExtValuesPeriodCount; // 5@8>4 <>45;8@>20=8O 2 <8=CB0E

   if(ValuePeriod!=0)

      ModelingBars=ModelingPeriod/ValuePeriod; // >;8G5AB2> H03>2 2 ?5@8>45

   CalculateSpread();

   return(0);

  }

//+------------------------------------------------------------------+

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 ---