Compound code really need help

 

Hey guys can any one help me on code for compound in my ea 

lets say base trade amount

 10USD

 So its our 1st trade

 and it won

 so we have now 17USD total

 2nd trade:

 last base trade = 10USD + X %of profit of last trade

 so 2nd trade lets say 12USD

 3rd trade is last trade =  12USD + Profit of last trade

 and we compound until we lose then we go back to original base trade = 1USD

 10USD

 We can define how many times we want compound

 and if we want compound based on fixed amount 10usd 5usd 1usd or based on %% of account 

 

Hey Byron

Not a simple question and would need more info mate. MT4 or MT5? Is the EA controlling the order closing (ie virtual SL/TP) or is the SL & TP set on the order?  

 
Stuart Browne:

Hey Byron

Not a simple question and would need more info mate. MT4 or MT5? Is the EA controlling the order closing (ie virtual SL/TP) or is the SL & TP set on the order?  

 sorry its for MT4 and it for Binary options ea  i will show you the code

extern string note1 = "% of your account balance";
input double Risk=5;
extern string note2 = "Expiry time";
input int ExpireSeconds=3600;
extern string note3 = "How long the ADX has to open a trade in the BAR";
input int SecondsForOpening=5;
extern string note4 = "Indicator settings";
input int SignalGap=5;
input int ADXPeriod=5;

extern string note5 = "How Long The EA must Run For? (Brokers Time)";
input int HourBegin=0;
input int HourEnd=24;
int MagicNumber=100;

double Lot[];
bool sel,mod,cl;
int tic;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {int total=0;
   bool newb=NewBar();
   int tip=-1;
   for(int z=OrdersTotal()-1;z>=0;z--)
      {sel=OrderSelect(z,SELECT_BY_POS);
       if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
         {total++;
         }
      }
      
 
   datetime lastcl=0;   
   for(int z=OrdersHistoryTotal()-1;z>=0;z--)
      {sel=OrderSelect(z,SELECT_BY_POS,MODE_HISTORY);
       if((OrderType()==OP_SELL||OrderType()==OP_BUY)&&OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
            {
             if(OrderCloseTime()>lastcl)
               {lastcl=OrderOpenTime();
                
               }
            }
         
      }   
 if(TimeHour(TimeCurrent())>=HourBegin&&TimeHour(TimeCurrent())<HourEnd&&iBarShift(Symbol(),0,lastcl)!=0&&total==0)
   {
      OpenOrder(tip);
   }  
//---
   
  }
//+------------------------------------------------------------------+
bool NewBar()
{
static datetime lastbar = 0;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else return(false);
}

void BuyOrder()
{RefreshRates();
GetLot();
for(int z=0;z<ArraySize(Lot);z++)
   { 
   tic=OrderSend (Symbol(),OP_BUY,Lot[z],Close[0],0,0,0,"BO exp:"+string(ExpireSeconds),MagicNumber,0,Red);
     if(tic==-1){Print("eror=",GetLastError());return;}
   }

}

void SellOrder()
{RefreshRates();
GetLot();

for(int z=0;z<ArraySize(Lot);z++)
   { 
    tic=OrderSend (Symbol(),OP_SELL,Lot[z],Close[0],0,0,0,"BO exp:"+string(ExpireSeconds),MagicNumber,0,Red);
    if(tic==-1){Print("eror=",GetLastError());return;}
   }
}



void OpenOrder(int tip)
{
 int adx1=Adx(0);
 
 double arrowdown=iCustom(NULL,0,"BB_Alert Arrows",SignalGap,0,0,0,1);
 double arrowup=iCustom(NULL,0,"BB_Alert Arrows",SignalGap,0,0,1,1);


if(arrowup!=2147483647)
   {
    if (ExpireCandle()&&adx1==1)
     {

       BuyOrder();
       return;
     }
   } 
   
if(arrowdown!=2147483647)
   {
    if (ExpireCandle()&&adx1==-1)
    {

       SellOrder();
       return;
    } 
   } 
   
     
}
bool ExpireCandle()
{
if(TimeCurrent()<SecondsForOpening+Time[0])
return(true);
return(false);
}
int Adx(int i)
{double plus1=iADX(NULL,0,ADXPeriod,PRICE_CLOSE,MODE_PLUSDI,i+1);
 double plus0=iADX(NULL,0,ADXPeriod,PRICE_CLOSE,MODE_PLUSDI,i);
 
 double minus1=iADX(NULL,0,ADXPeriod,PRICE_CLOSE,MODE_MINUSDI,i+1);
 double minus0=iADX(NULL,0,ADXPeriod,PRICE_CLOSE,MODE_MINUSDI,i);
 if(plus1<minus1&&plus0>minus0)
   {return(1);
   }
 if(plus1>minus1&&plus0<minus0)
   {return(-1);
   }
   
 
 return(0);
}


void GetLot()
{

double lot=NormalizeDouble(AccountBalance()*Risk/100,0);
double maxlot= 250;
double minlot= MarketInfo(NULL,MODE_MINLOT);

int size=int(lot/maxlot);
if(lot>maxlot*size)
   {size++;
   } 
ArrayResize(Lot,size);
for(int z=0;z<size;z++)
   {if(z!=size-1)Lot[z]=maxlot;
    else
      {if(lot==maxlot*size)
         {       
         Lot[z]=maxlot;
         }
       else
         {
          Lot[z]=lot-maxlot*(size-1);
         }  
      }
   }
 
if(lot<minlot)
   {ArrayResize(Lot,1);
    Lot[0]=minlot;
   }
}
 
byron88:

 sorry its for MT4 and it for Binary options ea  i will show you the code

Thanks mate. Unfortunately I don't have time tonight to take a look and I'm off on 2 weeks holiday tomorrow. If someone else can't help you out here please send me a message and I'll take a look when I get back.

Cheers
Stu
 
Stuart Browne:
Thanks mate. Unfortunately I don't have time tonight to take a look and I'm off on 2 weeks holiday tomorrow. If someone else can't help you out here please send me a message and I'll take a look when I get back.

Cheers
Stu

thanks stuart

Reason: