#
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Home
Forex Forum
+ Add Script
Metastock
Expert Advisors
Explorations
Indicators
Trading Systems
Metatrader
MQL Experts
MQL Indicators
MQ4 Experts
MQ4 Indicators
MQ4 Scripts
Tradestation
Functions
Indicators
PaintBars
ShowMe
Trading Systems
Amibroker
Commentaries
Explorations
Functions
Indicators
Trading Systems
Contact us
Newsletter
Group: Metatrader MQ4 Experts
Title: Envelope breakout system
Description:
Envelope breakout system
//+------------------------------------------------------------------+ //| Envelope.mq4 | //| Copyright © 2005,tageiger aka fxid10t@yahoo.com | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005,tageiger aka fxid10t@yahoo.com" #property link "http://www.metaquotes.net" extern int EnvTimeFrame =5; //envelope time frame: 0=chart,60=1hr,240=4hr, etc. extern int EnvelopePeriod =144; //moving average length extern int EnvMaMethod =1; //0=sma,1=ema,2=smma,3=lwma. extern int MaShift =0; //shift relative to current bar indicator data is posted extern double EnvelopeDeviation =0.4; //envelope width extern bool UseMaElineTSL? =true; //enable moving average or Opposite Envelope line trailing SL extern int MaElineTSL =0; //see notes below /*0=iMA trailing SL 1=Opposite Envelope line trailing SL 2=Near Envelope line trailing SL (for 15m or greater periods, when price breaks out of the envelopes)*/ extern bool BreakEvenTSL? =false; //enable break even trailing stoploss extern int BreakEvenPips =1; //pips above/below OrderOpenPrice for breakeven SL extern bool FastMaTSL? =false; //enable fast ma trailing stoploss extern int FastMaPeriod =55; //FastMaTSL moving average length extern int FastMaMethod =0; //0=sma,1=ema,2=smma,3=lwma. extern int FastMaShift =0; //shift relative to current bar indicator data is posted extern bool FixedPipTSL? =false; //enable fixed pip trailing stoploss extern int FixedPipTSLPips =0; //pips to trail extern int FixedPipTSLTrigger=0; //pips in profit before trailing stoploss is triggered extern int TimeBegin =0; //server time order placement begins extern int TimeEnd =18; //server time order placement ends extern double TimeDelete =23; //server time unexecuted orders deleted extern double FirstTP =21.0; //1st TP in pips extern double SecondTP =34.0; //2nd TP in pips extern double ThirdTP =55.0; //3rd TP in pips extern int Lot.Margin =1000; //Margin for 1 lot traded extern double MaximumRisk =0.02; //%account balance to risk per position extern double DecreaseFactor =3; //lot size divisor(reducer) during loss streak extern bool DeleteOrders? =false; //deletes pending stop orders if true extern bool CloseOrders? =false; //closes open orders if true, regardless of profit status. extern int Slippage =2; //applies to closeorders() int b1,b2,b3,s1,s2,s3; double ssl,bsl,TSL; string comment ="m e.3.03"; string TradeSymbol; TradeSymbol=Symbol(); int init(){return(0);} int deinit(){return(0);} int start() { double btp1,btp2,btp3,stp1,stp2,stp3; double bline=0,sline=0,ma=0; int cnt, ticket,total=OrdersTotal(); ma=iMA(NULL,EnvTimeFrame,EnvelopePeriod,MaShift,EnvMaMethod,PRICE_CLOSE,0); bline=iEnvelopes(NULL,EnvTimeFrame,EnvelopePeriod,EnvMaMethod,0,PRICE_CLOSE,EnvelopeDeviation,MODE_UPPER,0); sline=iEnvelopes(NULL,EnvTimeFrame,EnvelopePeriod,EnvMaMethod,0,PRICE_CLOSE,EnvelopeDeviation,MODE_LOWER,0); if(TotalTradesThisSymbol(TradeSymbol)==0) { b1=0;b2=0;b3=0;s1=0;s2=0;s3=0; } if(TotalTradesThisSymbol(TradeSymbol)>0) { for(cnt=0;cnt
=TimeBegin && Hour()
Close[0] && sline
0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { b1=ticket; Print(ticket); } else Print("Error Opening BuyStop Order: ",GetLastError()); return(0); } } } } if(b2==0) { if(Hour()>=TimeBegin && Hour()
Close[0] && sline
0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { b2=ticket; Print(ticket); } else Print("Error Opening BuyStop Order: ",GetLastError()); return(0); } } } } if(b3==0) { if(Hour()>=TimeBegin && Hour()
Close[0] && sline
0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { b3=ticket; Print(ticket); } else Print("Error Opening BuyStop Order: ",GetLastError()); return(0); } } } } if(s1==0) { if(Hour()>=TimeBegin && Hour()
Close[0] && sline
0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { s1=ticket; Print(ticket); } else Print("Error Opening SellStop Order: ",GetLastError()); return(0); } } } } if(s2==0) { if(Hour()>=TimeBegin && Hour()
Close[0] && sline
0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { s2=ticket; Print(ticket); } else Print("Error Opening SellStop Order: ",GetLastError()); return(0); } } } } if(s3==0) { if(Hour()>=TimeBegin && Hour()
Close[0] && sline
0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { s3=ticket; Print(ticket); } else Print("Error Opening SellStop Order: ",GetLastError()); return(0); } } } } for(cnt=0;cnt
OrderOpenPrice() && TSL>OrderStopLoss()) { bsl=TSL; if(bsl==0 || bsl
OrderStopLoss()) {return(0);} OrderModify(OrderTicket(), OrderOpenPrice(), ssl, OrderTakeProfit(), OrderExpiration(), Red); } } OrderSelect(b1,SELECT_BY_TICKET); if(OrderCloseTime()>0) {b1=0; SendMail(Symbol()+" "+OrderComment(),"$"+DoubleToStr(OrderProfit(),2)); } OrderSelect(b2,SELECT_BY_TICKET); if(OrderCloseTime()>0) {b2=0; SendMail(Symbol()+" "+OrderComment(),"$"+DoubleToStr(OrderProfit(),2)); } OrderSelect(b3,SELECT_BY_TICKET); if(OrderCloseTime()>0) {b3=0; SendMail(Symbol()+" "+OrderComment(),"$"+DoubleToStr(OrderProfit(),2)); } OrderSelect(s1,SELECT_BY_TICKET); if(OrderCloseTime()>0) {s1=0; SendMail(Symbol()+" "+OrderComment(),"$"+DoubleToStr(OrderProfit(),2)); } OrderSelect(s2,SELECT_BY_TICKET); if(OrderCloseTime()>0) {s2=0; SendMail(Symbol()+" "+OrderComment(),"$"+DoubleToStr(OrderProfit(),2)); } OrderSelect(s3,SELECT_BY_TICKET); if(OrderCloseTime()>0) {s3=0; SendMail(Symbol()+" "+OrderComment(),"$"+DoubleToStr(OrderProfit(),2)); } } if(!IsTesting()) { PrintComments(); } return(0); } //Functions double LotsOptimized() { double lot; int orders=HistoryTotal(); int losses=0; lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/Lot.Margin,2); if(DecreaseFactor>0) { for(int i=orders-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; } if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue; if(OrderProfit()>0) break; if(OrderProfit()<0) losses++; } if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,2); } if(lot<0.05) lot=0.05; return(lot); }//end LotsOptimized int TotalTradesThisSymbol(string TradeSymbol) { int i, TradesThisSymbol=0; for(i=0;i
=Point*FirstTP) { beTSL=OrderOpenPrice()+(BreakEvenPips*Point);}} if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && (OrderMagicNumber()==11 || OrderMagicNumber()==31 || OrderMagicNumber()==51)) { if(OrderOpenPrice()-Ask>=Point*FirstTP) { beTSL=OrderOpenPrice()-(BreakEvenPips*Point);}}} return(beTSL);} double fastmaTSL() { double fmaTSL; fmaTSL=iMA(Symbol(),EnvTimeFrame,FastMaPeriod,FastMaShift,FastMaMethod,PRICE_CLOSE,0); return(NormalizeDouble(fmaTSL,Digits));} double fixedpipTSL() { double fpTSL; for(int cnt=0;cnt
(FixedPipTSLTrigger*Point) && OrderStopLoss()
(FixedPipTSLTrigger*Point) && OrderStopLoss()>Ask+Point*FixedPipTSLPips) { fpTSL=Ask+Point*FixedPipTSLPips;}}} return(fpTSL);}
Author/Source:
tageiger aka
Forex Directory
|
Forex Trading Systems
|
Privacy
|
Disclaimer
|
Contact