//+------------------------------------------------------------------+ //| FT_BB+MA.mq4.mq4 //| Copyright © 2009, FORTRADER.RU. Стратегия на пробой болленджера //| http://www.fortrader.ru | http://forexsystems.ru/sistemy-ozhidayuschie-realizacii/11095-ochen-nuzhen-sovetnik-po-bollindzheru.html | Исследование для 56 выпуска журнала FORTRADER.RU //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, FORTRADER.RU. Стратегия на пробой болленджера" #property link "http://www.fortrader.ru | http://forexsystems.ru/sistemy-ozhidayuschie-realizacii/11095-ochen-nuzhen-sovetnik-po-bollindzheru.html | Исследование для 56 выпуска журнала FORTRADER.RU" extern int periodH1=5; extern int periodD=7; int bars; int start() { if(Bars!=bars) {bars=Bars; if(OpenPattern1()!=0){Print("Остановлен по ошибке"); return(0);} PosManager(); } return(0); } extern int bb=20; extern int otc=1; extern int sma=20; extern int SL=50; extern int TP=80; int MG=564651; double Lots=0.1; int mn=1; extern int startpipsclose=30; double startup,startdw;int err; int OpenPattern1() { int perh1=GetPeriod(periodH1); int perd=GetPeriod(periodD); if(perdbb1 && startup==1 && iClose(NULL,perd,1)>ma && ChPos(1)==0) { if(OpenOrderOnMarket(0,SL,TP)!=0) return(-1); } if(iClose(NULL,perh1,1)>bb1){startup=0;} /*продажа*/ if(iClose(NULL,perh1,1)>bb2){startdw=1;} if(iClose(NULL,perh1,1)0){sl=op-slpips*Point*mn;}if(tppips>0){tp=op+tppips*Point*mn;} err=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(op,Digits),3,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),"56 FORTRADER.RU",MG,0,Red); if(err<0){Print("OrderSend()- Ошибка OP_BUY. op "+op+" sl "+sl+" tp "+tp+" "+GetLastError());return(-1);} } if(type==1) { op=Bid;if(slpips>0){sl=op+slpips*Point*mn;}if(tppips>0){tp=op-tppips*Point*mn;} err=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(op,Digits),3,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),"56 FORTRADER.RU",MG,0,Red); if(err<0){Print("OrderSend()- Ошибка OP_SELL. op "+op+" sl "+sl+" tp "+tp+" "+GetLastError());return(-1);} } return(0); } int PosManager() { if(ProfitPos(1)>startpipsclose*Point*mn) { _OrderCloseBy(1,Lots,Lots/2); } if(ProfitPos(0)>startpipsclose*Point*mn) { _OrderCloseBy(0,Lots,Lots/2); } return(0); } //Результат позиции прибыли в пунктах double ProfitPos(int type) {int i; for( i=1; i<=OrdersTotal(); i++) { if(OrderSelect(i-1,SELECT_BY_POS)==true) { if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && type==1 && OrderMagicNumber()==MG) {return(Ask-OrderOpenPrice());} if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && type==0 && OrderMagicNumber()==MG){return(OrderOpenPrice()-Ask);} } } return(0); } //Закрывает часть позиции int _OrderCloseBy(int type, double curlot, double closelot) {//http://fxnow.ru/blog.php?user=Yuriy&blogentry_id=99 int err; for(int i=1; i<=OrdersTotal(); i++) { if (OrderSelect(i-1,SELECT_BY_POS)==true) { if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && type==1 && OrderMagicNumber()==MG && OrderLots()>closelot) { err=OrderClose(OrderTicket(),closelot,Bid,3,Violet); if(err<0){Print("OrderClose()- Ошибка закрытия OP_BUY. OrderTicket "+OrderTicket()+" OrderLots() "+OrderLots()+" Bid "+Bid+" "+GetLastError());return(-1);} _OrderModifyBy(1,Lots,Lots/2); } if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && type==0 && OrderMagicNumber()==MG && OrderLots()>closelot) { err=OrderClose(OrderTicket(),closelot,Ask,3,Violet); if(err<0){Print("OrderClose()- Ошибка закрытия OP_SELL. OrderTicket "+OrderTicket()+" OrderLots() "+OrderLots()+" Ask "+Ask+" "+GetLastError());return(-1);} _OrderModifyBy(0,Lots,Lots/2); } } } return(0); } extern int mewstoploss=20; int _OrderModifyBy(int type, double curlot, double closelot) {int i;bool err; for( i=1; i<=OrdersTotal(); i++) { if(type==1) { if(OrderSelect(i-1,SELECT_BY_POS)==true) { if(OrderType()==OP_BUY && OrderLots()==closelot && OrderStopLoss()!=(OrderOpenPrice()-mewstoploss*Point*mn)) { err=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-mewstoploss*Point*mn,OrderTakeProfit(),0,Red); if(err==false){return(-1);} return(0); }//if(BBUSize>0 }//if(OrderSelect(i }//if(type==1) if(type==0) { if(OrderSelect(i-1,SELECT_BY_POS)==true) { if(OrderType()==OP_SELL && OrderLots()==closelot && OrderStopLoss()!=(OrderOpenPrice()+mewstoploss*Point*mn)) { err=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+mewstoploss*Point*mn,OrderTakeProfit(),0,Red); if(err==false){return(-1);} return(0); }//if(BBUSize>0 }// if(OrderSelect } }// for( i=1; return(0); }