
Originally Posted by
civfan
Hey funyoo.
In order to avoid always asking for basic functions, could you enlight me how to add basketpercent function to a code?
(I am not a programmer, so it will be on a copy-past base).
thank you.
Hi civfan,
Extern parameters :
Code:
extern bool basketpercent=false; // enable the basket percent
extern double profit=10; // close all orders if a profit of 10 percents has been reached
extern double loss=30; // close all orders if a loss of 30 percents has been reached
Start body :
Code:
if(basketpercent){
if(closebasket==false)closebasket=closebasketpercent(profit,loss);
if(closebasket){closebuy();closesell();delete(OP_BUYSTOP);delete(OP_SELLSTOP);delete(OP_BUYLIMIT);delete(OP_SELLLIMIT);}
if(closebasket && count(OP_BUY)+count(OP_SELL)+count(OP_BUYLIMIT)+count(OP_SELLLIMIT)+count(OP_BUYSTOP)+count(OP_SELLSTOP)==0)closebasket=false;
}
Functions :
Code:
//|---------basket
bool closebasketpercent(double profit,double loss){
double ipf,ilo;
ipf=profit*(0.01*AccountBalance());
ilo=loss*(0.01*AccountBalance());
cb=AccountEquity()-AccountBalance();
if(cb>=ipf || cb<=(ilo*(-1)))return(1);
return(0);
}
//|---------delete
void delete(int type){
if(OrdersTotal()>0){
for(i=OrdersTotal();i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==type){
OrderDelete(OrderTicket());
}
}
}
}