11//+------------------------------------------------------------------+
22//| Position Size Calculator.mq4 |
3- //| Copyright © 2015 - 2016, Leonardo Ciaccio |
3+ //| Copyright © 2015 - 2016, Leonardo Ciaccio |
44//| https://github.com/LeonardoCiaccio/Position-Size-Calculator |
55//| |
66//| Donate Bitcoins : 1KHSR2S58y8WV6o3zRYeD5fBApvfTMtj8B |
@@ -23,7 +23,7 @@ enum __position{
2323
2424};
2525
26- #property copyright " Copyright © 2015-2016, Leonardo Ciaccio"
26+ #property copyright " Copyright © 2015-2016, Leonardo Ciaccio"
2727#property link " https://github.com/LeonardoCiaccio/Position-Size-Calculator"
2828#property indicator_chart_window
2929
@@ -36,7 +36,7 @@ extern string Donate_Bitcoins = "1KHSR2S58y8WV6o3zRYeD5fBApvfTMtj8B";
3636extern string Donate_PayPal = " microlabs@altervista.org" ;
3737
3838extern string Setup = " [ App Setup ]" ;
39- extern __money AccountMoney = FreeMargin ;
39+ extern __money AccountMoney = Balance ;
4040extern double StopLossPips = 30 ;
4141extern double Risk = 5 ;
4242
@@ -84,8 +84,9 @@ int deinit(){
8484//+------------------------------------------------------------------+
8585int start (){
8686
87- create_box ();
87+ create_box ();
8888 return ( 0 );
89+
8990}
9091
9192//+------------------------------------------------------------------+
@@ -112,7 +113,7 @@ double current_spread(){
112113//+------------------------------------------------------------------+
113114//| Create a box information |
114115//+------------------------------------------------------------------+
115- void create_box (){
116+ int create_box (){
116117
117118 string txtBG = " g" ;
118119 string aName = " Account" ;
@@ -145,6 +146,10 @@ void create_box(){
145146 double riskMoney = ( size / 100 ) * Risk ;
146147 double unitCost = MarketInfo ( Symbol (), MODE_TICKVALUE );
147148 double tickSize = MarketInfo ( Symbol (), MODE_TICKSIZE );
149+
150+ // Important for startup MT4, without generate an error
151+ if ( unitCost == 0 )return ( 0 );
152+
148153 double positionSize = riskMoney / ( ( ( NormalizeDouble ( StopLossPips * MyPoint , Digits ) ) * unitCost ) / tickSize );
149154
150155
@@ -217,6 +222,8 @@ void create_box(){
217222 ObjectSet ( " Profit" , OBJPROP_YDISTANCE , Distance_Y * 13 );
218223 ObjectSetText ( " Profit" , " Profit : " + DoubleToStr ( total_profit (), 2 ) , Font_Size , Font_Face , Color_Profit );
219224
225+ return ( 0 );
226+
220227}
221228
222229//+------------------------------------------------------------------+
@@ -247,15 +254,17 @@ double total_profit(){
247254
248255 for ( int x = 0 ; x < OrdersTotal (); x ++ ){
249256
250- OrderSelect ( x , SELECT_BY_POS , MODE_TRADES );
257+ if ( OrderSelect ( x , SELECT_BY_POS , MODE_TRADES ) ){
251258
252- if ( OrderSymbol () == MySymbol ){
259+ if ( OrderSymbol () == MySymbol ){
253260
254- tt_profit += OrderProfit ();
261+ tt_profit += OrderProfit ();
262+
263+ }
255264
256265 }
257-
266+
258267 }
259268
260269 return (tt_profit );
261- }
270+ }
0 commit comments