← Назад к списку файлов

eq.mq5

Поиск по коду файла

#property version   "111.008"
#property description "D'Alembert betting system :"
#property description "The stake should be decreasing after the winning bet,"
#property description "... and increasing after the loosing one."

input string   WARNING="NOT all Input is check to be correct !";
input datetime LastRiskDate=D'2012.12.17 23:59:59'; // Do NOT take risk after this date ! (COMPETITION)
input double   MinMargin=200.1;                     // Don't increase risk below this MARGIN_LEVEL !
input double   KTP=0.0025;                          // TakeProfit as part of price ( 0.01=1.0% ) same to all Symbol
input double   Limit_Position_Lot=2.5;              // Maximal Position_volume per Symbol
input double   Limit_Exposure_Lot=1.25;             // Maximal Exposure per Value ( total from all symbols )
input double   LotAtRisk=1.75;                      // Maximal Exposure at send +/-(Valu1-Valu2) = Accepted Risk
input bool     Inverse = false;                     // Change position direction
input bool     ManageTP = true;                     // Quickly close profitable position
input bool     ManageLOSS=true;                     // Lower open price for loosing position
input int      NoWorkTime=9;                        // Time betwen two executions (seconds) = accelerate tests
input int      LotMX=3;                             // Multiply minimal order volume. Work only if 0.01
input int      KStart=7;                            // Multiply Start volume

enum SymbolPosition {PNon,PBuy,PSell}; // This is a enum TYPE declaration !
/*

const int Nmax = 10;      // Used Symbol (valu-pair) ; max=10
const int Vmax=5;         // index of last used Value +1 , first index=0 !
double V[5];              // Value exposure ; 0=EUR,1=USD,2=JPY,3=CHF,4=GBP,5=CAD ... no other for now.
string S[10] = {"EURUSD","USDJPY","EURJPY","GBPJPY","GBPCHF","EURCHF","GBPUSD","EURGBP","USDCHF","CHFJPY"};
SymbolPosition A[10] = {PSell,PSell,PBuy,PBuy,PSell,PSell,PBuy,PBuy,PBuy,PSell}; // What is action for each symbol
SymbolPosition SPos[10]; // What is position for each symbol
*/
/*
const int Vmax=7;          // index of last used Value +1 , first index=0 !
double V[7];               // Value exposure ; 0=EUR,1=USD,2=JPY,3=CHF,4=GBP,5=CAD,6=AUD.

 const int Nmax = 12;      // Used Symbol (valu-pair) ;
 string S[12] = {"USDCHF","GBPUSD","EURUSD","USDJPY","USDCAD","AUDUSD","EURGBP","EURAUD","EURCHF","EURJPY","GBPJPY","GBPCHF"};
 SymbolPosition A[12] = {PBuy,PSell,PBuy,PSell,PSell,PSell,PSell,PSell,PSell,PBuy,PBuy,PSell}; // What is action for each symbol
 SymbolPosition SPos[12]; // What is position for each symbol
*/

const int Vmax=5;       // index of last used Value +1 , first index=0 !
double V[5];            // Value exposure ; 0=EUR,1=USD,2=JPY,3=CHF,4=GBP,5=CAD ... no other for now.
const int Nmax=3;       // Used Symbol (valu-pair) ;
string S[3]={"EURUSD","EURGBP","GBPUSD"};
SymbolPosition A[3]={PBuy,PSell,PSell}; // What is action for each symbol
SymbolPosition SPos[3];                 // What is position for each symbol . ==> MUST BE a HAMMILTON settings !
double LotV;              // Sum all lots : EXPOSURE
double LotP;              // Sum all lots : POSITION
string Val1,Val2;         // Current Symbol ( valu-pair == Val1/Val2 )
datetime LastMessageTime; // When Last Message was print
int I,J;                  // main program index
uchar SDig;               // Current symbol digits
string Out;               // Text on the screen
MqlTick T;                // Tick value
MqlTradeRequest R;        // Request - order
MqlTradeResult D;         // Deal = result of Request
double LotMin;            // Server setting
double NLots;             // Current symbol : Position volume
double Take;              // TakeProfit for open position (price).
double TP;                // TakeProfit for each order (delta_price)
double SStop;             // Market stop for current Symbol
datetime LastWorkTime;    // Used to accelerate tests , with "NoWorkTime"
double BestBallance;      // Used to protect from too much close with loss
bool   CloseOne;          // Used to stop manual close after firt one
double LotAtSend;         // varible : Same as "LotAtRisk"
string Reason;            // Why make Close_With_Loss
double FreeBalance;       // Available money for correction
double TPMove;

string MaxExpSym;         // Symbol with maximal position ( 1-"worst" position )
double MaxExpPos;         // Volume of maximal existing position
string MaxLosSym;         // Symbol with maximal loss ( 2-"worst" position )
double MaxLosPos;         // Profit(Loss) of most loosing position.
string MaxProSym;         // Symbol with maximal profit
double MaxProPos;         // Value of maximal profit

void PrintNM(int NMTLimit,string NMS) // Print NMS with minimum interval NMTLimit seconds
  {
   if(LastMessageTime+NMTLimit<TimeCurrent())
     { LastMessageTime=TimeCurrent(); Print(NMS); }
  }

int ValueToIndex(string SIndex) // in=Value_string; out=Index_of_Value;
  {
   if( SIndex=="EUR" ) return(0);
   if( SIndex=="USD" ) return(1);
   if( SIndex=="JPY" ) return(2);
   if( SIndex=="CHF" ) return(3);
   if( SIndex=="GBP" ) return(4);
   if( SIndex=="CAD" ) return(5);
   if( SIndex=="AUD" ) return(6);
   return(-1);
  }

string IndexToValue(int VIndex) // in=Index_of_Value; out=Value_string;
  {
   if( VIndex==0 ) return("EUR");
   if( VIndex==1 ) return("USD");
   if( VIndex==2 ) return("JPY");
   if( VIndex==3 ) return("CHF");
   if( VIndex==4 ) return("GBP");
   if( VIndex==5 ) return("CAD");
   if( VIndex==6 ) return("AUD");
   return("ANY");
  }

void Exposure() // result is : V[] , LotV , LotP, MaxExpSym - global
  {
   int EI,EJ; // index - local
   double ELotP; // Position_Lot for current symbol in base EUR - local
   for(EI=0;EI<Vmax;EI++) V[EI]=0.0; LotP=0.0;
   for(EI=0;EI<PositionsTotal();EI++)
     {
      Val1=StringSubstr(PositionGetSymbol(EI),0,3); Val2=StringSubstr(PositionGetSymbol(EI),3,3); // here position is selected !!!
      EJ=ValueToIndex(Val1);
      switch(PositionGetInteger(POSITION_TYPE))
        {
         case POSITION_TYPE_BUY :
           {
            if(Val1=="EUR") ELotP=PositionGetDouble(POSITION_VOLUME);
            else            ELotP=PositionGetDouble(POSITION_VOLUME)/SymbolInfoDouble("EUR"+Val1,SYMBOL_ASK);
            V[EJ]=V[EJ]+ELotP;
            LotP=LotP+ELotP;
            break;
           }
         case POSITION_TYPE_SELL :
           {
            if(Val1=="EUR") ELotP=PositionGetDouble(POSITION_VOLUME);
            else            ELotP=PositionGetDouble(POSITION_VOLUME)/SymbolInfoDouble("EUR"+Val1,SYMBOL_ASK);
            V[EJ]=V[EJ]-ELotP; LotP=LotP+ELotP; break;
           }
        } // end : swich Val1
      EJ=ValueToIndex(Val2);
      switch(PositionGetInteger(POSITION_TYPE))
        {
         case POSITION_TYPE_SELL :
           {
            if(Val1=="EUR") ELotP=PositionGetDouble(POSITION_VOLUME);
            else            ELotP=PositionGetDouble(POSITION_VOLUME)/SymbolInfoDouble("EUR"+Val1,SYMBOL_ASK);
            V[EJ]=V[EJ]+ELotP;
            LotP=LotP+ELotP;
            break;
           }
         case POSITION_TYPE_BUY :
           {
            if(Val1=="EUR") ELotP=PositionGetDouble(POSITION_VOLUME);
            else            ELotP=PositionGetDouble(POSITION_VOLUME)/SymbolInfoDouble("EUR"+Val1,SYMBOL_ASK);
            V[EJ]=V[EJ]-ELotP;
            LotP=LotP+ELotP;
           }
        } // end : swich Val2
     } // end : for all symbol
   LotP=LotP/2.0;
   LotV=0.0; for(EI=0;EI<Vmax;EI++) LotV=LotV+MathAbs(V[EI]);
  }

void Extreme()
  {
   int EI;
   MaxExpPos=0.0; MaxLosPos=0.0; MaxProPos=0.0;
   for(EI=0;EI<PositionsTotal();EI++)
     {
      PositionGetSymbol(EI);
      if(MaxExpPos<PositionGetDouble(POSITION_VOLUME)) // Maximal Position Volume and Symbol
        { MaxExpPos=PositionGetDouble(POSITION_VOLUME); MaxExpSym=PositionGetSymbol(EI); }
      if(MaxLosPos>PositionGetDouble(POSITION_PROFIT)) // Maximal LOSS position and Symbol
        { MaxLosPos=PositionGetDouble(POSITION_PROFIT); MaxLosSym=PositionGetSymbol(EI); }
      if(MaxProPos<PositionGetDouble(POSITION_PROFIT))
        { MaxProPos=PositionGetDouble(POSITION_PROFIT); MaxProSym=PositionGetSymbol(EI); }
     }

  }

void BUY() //  // send order is BUY, Position can be ANY !!!
  {
   R.action=TRADE_ACTION_DEAL;
   R.symbol=S[I];
   R.price=T.ask;
   R.sl=0.0;
   R.deviation=99;
   R.type=ORDER_TYPE_BUY;
   R.type_filling=ORDER_FILLING_AON; // or ORDER_FILLING_RETURN
   switch(SPos[I])
     {
      case PNon  :
        {
         R.tp=NormalizeDouble(T.ask+KStart*TP,(uchar)SymbolInfoInteger(S[I],SYMBOL_DIGITS));
         R.volume=KStart*LotMin;
         R.comment="OPEN_BUY "+DoubleToString(V[ValueToIndex(Val1)],3)+" : "+
                   DoubleToString(V[ValueToIndex(Val2)],3);
         break;
        }                         // New position
      case PSell :
        {
         R.tp=PositionGetDouble(POSITION_TP);
         R.volume=LotMin;
         if(CloseOne) R.comment=Reason;                                                   // Losing close
         else R.comment="PART_CLOSE "+DoubleToString(PositionGetDouble(POSITION_PROFIT),2)+" / "+
                        DoubleToString(PositionGetDouble(POSITION_VOLUME),2);       // Part close
         break;
        }
      case PBuy  :
        {
         R.tp=PositionGetDouble(POSITION_TP);
         R.volume=LotMin;
         if(CloseOne) R.comment=Reason;
         else
         R.comment="ADD_BUY "+DoubleToString(V[ValueToIndex(Val1)],3)+" : "+
                   DoubleToString(V[ValueToIndex(Val2)],3);
         break;
        }                         // Increase
     } // end :switch
   Exposure();
   Out=" POSITIONS [EUR-lot] = "+DoubleToString(LotP,2)+"  FreeBalance="+DoubleToString(FreeBalance,2)+
       "\n EXPOSURE [EUR-lot] = "+DoubleToString(LotV,2)+" :";
   for(J=0;J<Vmax;J++) Out=Out+"  "+IndexToValue(J)+"="+DoubleToString(V[J],3);
   Print(Out);
   OrderSend(R,D);
   Print("1->","OrderSend_BUY_",S[I],"@_",DoubleToString(R.price,SDig)," RetCode=",D.retcode);
  }

void SELL() //  // send order is SELL, Position can be ANY !!!
  {
   R.action=TRADE_ACTION_DEAL;
   R.symbol=S[I];
   R.price=T.bid;
   R.sl=0.0;
   R.deviation=99;
   R.type=ORDER_TYPE_SELL;
   R.type_filling=ORDER_FILLING_AON; // or ORDER_FILLING_RETURN
   switch(SPos[I])
     {
      case PNon  :
        {
         R.tp=NormalizeDouble(T.bid-KStart*TP,(uchar)SymbolInfoInteger(S[I],SYMBOL_DIGITS));
         R.volume=KStart*LotMin;
         R.comment="OPEN_SELL "+DoubleToString(V[ValueToIndex(Val1)],3)+" : "+
                   DoubleToString(V[ValueToIndex(Val2)],3);
         break;
        }                    // New position
      case PBuy  :
        {
         R.tp=PositionGetDouble(POSITION_TP);
         R.volume=LotMin;
         if(CloseOne) R.comment=Reason;                                                        // Losing close
         else R.comment="PART_CLOSE "+DoubleToString(PositionGetDouble(POSITION_PROFIT),2)+" / "+
                        DoubleToString(PositionGetDouble(POSITION_VOLUME),2);    

Показано первые 50% кода (символов: 16044)

Как получить полную версию?

Введите ваш email и нажмите кнопку, чтобы перейти к оплате.