Navigation:Home > Content >

TRO_DRAGON_MONEY_MGMT.mq4

Time: 2015-02-07 | Download file:TRO_DRAGON_MONEY_MGMT.mq4

//+------------------------------------------------------------------+ 
//|   TRO_DRAGON_MONEY_MGMT                                          | 
//|                                                                  | 
//|   Copyright © 2008, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|   All my indicators should be considered donationware. That is   |
//|   you are free to use them for your personal use, and are        |
//|   under no obligation to pay for them. However, if you do find   |
//|   this or any of my other indicators help you with your trading  |
//|   then any Gift or Donation as a show of appreciation is         |
//|   gratefully accepted.                                           |
//|                                                                  |
//|   Gifts or Donations also keep me motivated in producing more    |
//|   great free indicators. :-)                                     |
//|                                                                  |
//|   PayPal - [email protected]                               |  
//+------------------------------------------------------------------+  
 

//----
#property indicator_chart_window

extern int myChartX   = 500 ;
extern int myChartY   = 0 ;
extern int myCorner   = 0 ;
extern string myFont  = "Courier" ;
extern int myFontSize = 12 ;
extern color colorHead  = DarkGray ;
   
extern bool   use.actual.balance = false ; 
extern double myAccountSize           = 0 ;
extern int    myStopLossPips          = 20 ;
extern int    myMultiplier1           = 10 ;
extern int    myMultiplier2           = 2  ;
extern int    myLotValue              = 10000 ;
extern int    myRiskPct               = 5 ;

string symbol, tChartPeriod, ShortName ;  

int     digits, period, win, digits2, n, j, i, k ; 
 

double point, point2, value , AccountSize, PipValue,  LotSize, RiskPct, Risk ;
string lbl[15], lbl2[15];

 
//---- PipsToOpen
string Indicator_Name = "DRAGONMM:" ;
int Objs = 0;

//+------------------------------------------------------------------+ 
int     ind_bufferOp[] ;
string shortName ;
int    cpairsLenH;
int    cpairsLenV;
int    shortLength;
int    ctimesLen;
string cpairsh[];
string cpairsv[];
int    aTimes[];
string addition  = "";
string pArrow[5] ;
color  pColor[5] ;
 
string ArrowHeadRt =  "Ш" ; // 216 up arrow head
string ArrowHeadUp =  "Щ" ; // 217 up arrow head
string ArrowHeadDn =  "Ъ" ; // 218 up arrow head 
 

string ArrowN  = "с"; // NORTH
string ArrowNE = "ц";  // NORTHEAST
string ArrowE  = "р";  // EAST
string ArrowSE = "ш";  // SOUTHEAST
string ArrowS  = "т";  // SOUTH
 
string D1Arrow ; 
color  D1Color ; 


int ArrowNumber[5]; 
 
double open, close, diff, spread, DailyOpen, AmountPerPip ; 
 
color PriceColor ; 
 
double MODETICKVALUE , TICKVALUE, xvalue , yvalue;    
 
//+------------------------------------------------------------------+
int init()
  {
  
   period = Period() ; 
   
   tChartPeriod =  TimeFrameToString(period) ;
   symbol       =  Symbol() ;
   digits       =  Digits ;
   point        =  Point ;
   ShortName    =  tChartPeriod + " DragonMM"  ;
   win          =  0 ;

   if(digits == 5 || digits == 3) { digits2 = 0 ; point = point * 10 ; } else { digits2 = 0 ; }
 
   return(0);
  }
 
//+------------------------------------------------------------------+
int deinit()
  {
 
   ObjectsDeleteAll();
    
 
   return(0);
  }
 
//+------------------------------------------------------------------+
int start()
{

n       = 10;
 
j       = 0 ;


lbl[j]  = ShortName+j;
lbl2[j] = "DRAGON MONEY MANAGEMENT"   ;
DoShowHead(j, colorHead);
 
DoCalcs() ; 
 
j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = symbol + " " + DoubleToStr(Close[0],digits)  + " D1 " + DoubleToStr(diff,0) ;
DoShowHead(j, PriceColor);  
 

j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "TickValue $" + DoubleToStr(MODETICKVALUE,2) ;
DoShowHead(j, colorHead);  

j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "Lot Value $" + DoubleToStr(myLotValue,0) ;
DoShowHead(j, colorHead);   
  
j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "Acct Size " + DoubleToStr(AccountSize,2) ;
DoShowHead(j, Lime); 
   
j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "Stop Loss " + myStopLossPips ;
DoShowHead(j, Red); 
 
 
j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "Risk %    " + DoubleToStr(RiskPct,2) + "%" ;
DoShowHead(j, Red); 

 
j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "Risk      $" + DoubleToStr(Risk ,2) ;
DoShowHead(j, Red); 

j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "Lot Size  " + DoubleToStr(LotSize,2) ;
DoShowHead(j, Orange); 
 

j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "$/Pip     $" + DoubleToStr(AmountPerPip,2) ;
DoShowHead(j, Orange); 
 

WindowRedraw() ;   

   return(0);
}
//+------------------------------------------------------------------+
  
void DoShowHead( int u, color dsColor  )
{

ObjectCreate(lbl[u],23,0,Time[0],PRICE_CLOSE);
ObjectSet(lbl[u], OBJPROP_CORNER, myCorner );
ObjectSet(lbl[u],OBJPROP_XDISTANCE, myChartX);
ObjectSet(lbl[u],OBJPROP_YDISTANCE,n+myChartY);
ObjectSetText(lbl[u],lbl2[u],myFontSize,myFont,dsColor);


n = n+20;


  }  

//+------------------------------------------------------------------+
  
void DoCalcs()
{
RefreshRates();   

yvalue        =  MarketInfo(symbol,MODE_TICKVALUE) ;

TICKVALUE     =  ( myLotValue  / yvalue ) / 1000  ; 

xvalue        =  myLotValue / 100000.00 ;

MODETICKVALUE =  yvalue * xvalue ; 


if( use.actual.balance == true )  {AccountSize = AccountBalance() ; } 
else { if( myAccountSize == 0 ) { AccountSize = myStopLossPips * myMultiplier1 * myMultiplier2  ; } 
       else {AccountSize = myAccountSize  ;}
     }  


   close = iClose(symbol,PERIOD_D1,0);   
   open  = iOpen(symbol,PERIOD_D1,0);  
   diff  = (close - open) / point ;   
   
   if(close > open ) { PriceColor = Lime ;   } else {
   if(close < open ) { PriceColor = Red ;    } else { 
                       PriceColor = Yellow ; } } 

if( myRiskPct == 0 ) { RiskPct = 100 * ( myStopLossPips * LotSize * MODETICKVALUE ) / AccountSize ; } else { RiskPct = myRiskPct ; }

Risk    = (RiskPct * AccountSize) / 100  ;


// LotSize = AccountSize / (myStopLossPips * myMultiplier1 * myMultiplier2 ) ; 

LotSize = ( 1 / MODETICKVALUE ) * Risk / myStopLossPips ;

AmountPerPip = LotSize * MODETICKVALUE ;


} // void 

//+------------------------------------------------------------------+ 140 - 144
void drawLabel(string name,double lvl,color Color)
{
    if(ObjectFind(name) != 0)
    {
        ObjectCreate(name, OBJ_TEXT, 0, Time[10], lvl);
        ObjectSetText(name, name, myFontSize, myFont , EMPTY);
        ObjectSet(name, OBJPROP_COLOR, Color);
    }
    else
    {
        ObjectMove(name, 0, Time[10], lvl);
    }
}

     
  
//+------------------------------------------------------------------+
string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN";
   }
   return(tfs);
}

 

//+------------------------------------------------------------------+ 
/*

Comment(

"pair " , doSymbol , "\n" , 
"DailyOpen " , DoubleToStr(DailyOpen,Digits) , "\n" ,
 

"") ; 


j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "Pip Value " + DoubleToStr(PipValue,2) ;
DoShowHead(j, colorHead); 

*/

Recommend