Last active
November 14, 2015 03:02
-
-
Save notmii/4205c586fc0ae33cffd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//---------declare external input | |
extern double RiskPercent=1; | |
extern double reward_ratio=2; | |
extern int PadAmount=0; | |
extern int CandlesBack=5; double pips; int Oninit() | |
{ // initialize 4digit or 5digit broker setup | |
pips = Point; | |
if (_DIGITS== 5 || _DIGITS == 3) | |
pips *=10; | |
return(INIT_SUCCEEDED); | |
} | |
//---------insert in OnTick() function | |
double LotSize=0; | |
double Equity=AccountEquity(); | |
double RiskedAmount=Equity*RiskPercent*0.01; | |
int buyStopCandle= iLowest(NULL,0,1,CandlesBack,1); | |
int sellStopCandle=iHighest(NULL,0,2,CandlesBack,1); | |
double buy_stop_price =Low[buyStopCandle]-PadAmount*pips; | |
double pips_to_bsl=Ask-buy_stop_price; | |
double buy_takeprofit_price=Ask+pips_to_bsl*reward_ratio; | |
double sell_stop_price=High[sellStopCandle]+PadAmount*pips; | |
double pips_to_ssl=sell_stop_price-Bid; | |
double sell_takeprofit_price=Bid-pips_to_ssl*reward_ratio; | |
if(direction==0) //if bias is more on the Buy side | |
{ | |
double bsl=buy_stop_price; | |
double btp=buy_takeprofit_price; | |
//LotSize=(100/(0.00500/0.00010)/10; | |
LotSize=(RiskedAmount/ (pips_to_bsl/pips) )/10; | |
if(OpenOrdersThisPair(Symbol())==0)int buyticket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,NULL,MagicNumber,0,Green); | |
if(buyticket>0)OrderModify(buyticket,OrderOpenPrice(),bsl,btp,0,CLR_NONE); | |
} | |
if(direction==1) //if bias is more on the Sell side | |
{ | |
double ssl=sell_stop_price; | |
double stp=sell_takeprofit_price; | |
LotSize=(RiskedAmount/(pips_to_ssl/pips))/10; | |
if(OpenOrdersThisPair(Symbol())==0)int sellticket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,0,0,NULL,MagicNumber,0,Red); | |
if(sellticket>0)OrderModify(sellticket,OrderOpenPrice(),ssl,stp,0,CLR_NONE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment