hello just some very easy help with this ea here (fix the martingale)

 

Hello everybody on this very useful and interisting forum . I think here are the most powerfull people in programming mql4 . I hope everybody understand my english . ok here we go


So maybe someone can give me some tips with this one here . First of all - the ea works fine . the only problem is that the trades of the martingale function belong to the account balance. so if the acoount balance is rising no martingale function is needed. but when te account balance decrease a multipicator (here it is 1.5) come to increase the lot size.

All fine. The problem : if I trade on 2 or more charts or on different timeframes or manually the martingale function is incorrect because the account balance chanched.

At tis time i use a fix stoploss. so if it come to a stoploss the martingale function must be set to true. I tried it to change but everything ends up in an error.

Here is a kind of this code -


//martingale
if(Balance!=0.0&&Martingale==True){if(Balance>AccountBalance())Lots=Multiplier*Lots;else if((Balance+MinProfit)<AccountBalance())Lots=0.01;
else if((Balance+MinProfit)>=AccountBalance()&&Balance<=AccountBalance())Lots=Lots;}Balance=AccountBalance();if(Lots<0.01)Lots=0.01;if(Lots>100)Lots=100;



The best thing is if we can use the magic number to control the martingale. because if you use it on more timeframes it increases sometimes the double multiplier.

Another thing on this ea is that it works very good on 4 digits broker and even on 5 digits broker. but on 5 digits broker it only worked on backtesting. i don't know why

this is the ea . I think it is possible to chanche this code .if someone could help i would be very thanksful

it is a free ea from tradingsystemforex forum. i changed something so I post it here and hope someone can help my on the other hand with this little problem.

Files:
 

Hi


i have just got a glance at your code... SCARY!!! i'm suprised you can read it.


just one big pointer is that extern variables is read only, so:

Lots=Multiplier*Lots


is a bad idea, this often gets unwanted results,


i believe this:

if(Balance>AccountBalance())

is your way to see if last position where a loosing one, but it's not a good way if you use multiple EA's at same account. another ea makes a loss and you'r multiplying when you dont want to.


so a magicnumber and some checks in orderhistory is what you need,


i'll even throw in a function for martingale

//-----------------------------------------------------------------
// Multiplier Function
//-----------------------------------------------------------------
// Lts = startlots, Losses = amount of losses, multsize = multiplier 
//
//----------------------------------------------------------------- 
double MM_Multiplier(double Lts, int Losses, double MultSize){
   if(Losses == 0)
      return(Lts);
   for(int mult=0; mult < Losses; mult++){
      Lts=Lts*MultSize;
   }
   return(Lts);      
}
 

yes you are right enotrek. That is exactly what happend. if Any ea has a loosing Trade an other ea will increase the lot size . that ends in a chaos .


If we can solve this problem I can share some profitable settings . There is a good potential on the right currency


the best idea is with the History mode. magic number is also in this ea but i do not know exactly how to use it.


int fnHistoryCheck()

 {

  iOrders = OrdersHistoryTotal()-1;

  for (i = iOrders; i>=0; i--)

   {

    OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);

    if (OrderSymbol() == Symbol())

     {  

      if ((TimeDayOfYear(OrderOpenTime()) == DayOfYear()) && (TimeYear(OrderOpenTime()) == Year()))

       {

        if (OrderProfit() >= 0)

          sResult = "PROFIT";

        else

          sResult = "LOSS";

        ---Do stuff here dependent upon sResult---

       }

     }

   }

  return(0);

 }  

i found this one for history but it will get an failure if i implement it.


Thanks for your answer :-)

 

  1. for (i = iOrders; i>=0; i--)
    
       {
    
        OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
    
        if (OrderSymbol() == Symbol())
    Always test return code. Filter by magic number
        for(int pos=0; pos < HistoryTotal(); pos++) if (
            OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        &&  OrderType()         <= OP_SELL){    // Avoid cr/bal forum.mql4.com/32363
    

  2. if(Lots<0.01)Lots=0.01;
    Don't hard code broker specific constants
        double  minLot  = MarketInfo(Symbol(), MODE_MINLOT),  //IBFX was 0.1 now 0.01
        double  lotStep         = MarketInfo(Symbol(), MODE_LOTSTEP),   //IBFX= 0.01
                maxLot          = MarketInfo(Symbol(), MODE_MAXLOT );   //IBFX=50.00
    

 

Hello again, I tried to implement some codes but it ends up in errors.


Can someone of you try to beat it :-)


I work on it on . But it is just to hard for me now.


Thanks for the answer WHRroeder

 

Think of magicnumber as a creditcard number, the magicnumber belongs to the EA as the creditcard number number belongs to you,


you can se all transactions you've made with your creditcard as you can filter all orders you've made with a specific magicnumber.


when you trade manually you have a magicnumber too, but you can't change it. Its always 0 (Zero).



the historycheck you've found is a good start, you'll just to filter the magicnumber,

FYI:

 if ((TimeDayOfYear(OrderOpenTime()) == DayOfYear()) && (TimeYear(OrderOpenTime()) == Year()))
this makes sure you'll only get history results for the current day