7 Day Extension Fade

include
extern double Lots=0.1;
string pairs[] = { "EURUSDm","USDJPYm","GBPUSDm","USDCHFm","EURCHFm","AUDUSDm","USDCADm",
"NZDUSDm","EURGBPm","EURJPYm","GBPJPYm","CHFJPYm","GBPCHFm","EURAUDm",
"EURCADm","AUDCADm","AUDJPYm","NZDJPYm","AUDNZDm" };
string TradeSymbol;
int Pair = -1;
int b1,b2,s1,s2;
double bSL1,bSL2,sSL1,sSL2,btp1,btp2,stp1,stp2;
int init(){
if ( IsTesting() ) { if ( ArrayResize(pairs,1) != 0 ) pairs[0] = Symbol(); }
return(0); }
int deinit(){return(0);}
int start(){
Pair = (Pair+1) % ArraySize(pairs);
TradeSymbol = pairs[Pair];
int cnt, ticket,total=OrdersTotal();
if(TotalTradesThisSymbol(TradeSymbol)==0) { b1=0;b2=0;s1=0;s2=0; }
if(TotalTradesThisSymbol(TradeSymbol)>0) {
for(cnt=0;cntPoint); btp1=Ask+(Ask-(iLow(TradeSymbol,1440,1)-(Ask-Bid)-(10Point))); ticket=OrderSend(TradeSymbol, OP_BUY, Lots, Ask, 0,//slippage bSL1, btp1, "7 DEF 1st Long", 21, 0,//timedelete(), Aqua); if(ticket>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) {
bSL2=iLow(TradeSymbol,1440,1)-(Ask-Bid)-(10Point); btp2=Ask + NormalizeDouble( ((Ask-(iLow(TradeSymbol,1440,1)-(Ask-Bid)-(10Point))3)) , Digits); ticket=OrderSend(TradeSymbol, OP_BUY, Lots, Ask, 0,//slippage bSL2, btp2, "7 DEF 2nd Long", 41, 0,//timedelete(), Aqua); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { b2=ticket; Print(ticket); } else Print("Error Opening BuyStop Order: ",GetLastError()); return(0); } } } //Sell Setup if( iClose(TradeSymbol,1440,1)>iClose(TradeSymbol,1440,2) && iClose(TradeSymbol,1440,2)>iClose(TradeSymbol,1440,3) && iClose(TradeSymbol,1440,3)>iClose(TradeSymbol,1440,4) && iClose(TradeSymbol,1440,4)>iClose(TradeSymbol,1440,5) && iClose(TradeSymbol,1440,5)>iClose(TradeSymbol,1440,6) && iClose(TradeSymbol,1440,6)>iClose(TradeSymbol,1440,7) ) { //Sell Execution if(s1==0) { sSL1=iHigh(TradeSymbol,1440,1)+(Ask-Bid)+(10Point);
stp1=Bid-(iHigh(TradeSymbol,1440,1)+(Ask-Bid)+(10Point)-Bid); ticket=OrderSend(TradeSymbol, OP_SELL, Lots, Bid, 0, sSL1, stp1, "7 DEF 1st Short", 11, 0,//timedelete(), HotPink); if(ticket>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) { sSL2=iHigh(TradeSymbol,1440,1)+(Ask-Bid)+(10Point);
stp2=Bid-NormalizeDouble( (iHigh(TradeSymbol,1440,1)+(Ask-Bid)+(10Point)-Bid)3,Digits);
ticket=OrderSend(TradeSymbol,
OP_SELL,
Lots,
Bid,
0,
sSL2,
stp2,
"7 DEF 2nd Short",
31,
0,//timedelete(),
HotPink);
if(ticket>0) {
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{ s2=ticket; Print(ticket); }
else Print("Error Opening SellStop Order: ",GetLastError());
return(0); } } }
//Order Modify
OrderSelect(b1,SELECT_BY_TICKET); if(OrderCloseTime()>0) {
b1=0; SendMail(Symbol()+" "+OrderComment(),"$"+DoubleToStr(OrderProfit(),2));
OrderSelect(b2,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(1*Point),OrderTakeProfit(),0,Blue); }
OrderSelect(b2,SELECT_BY_TICKET); if(OrderCloseTime()>0) {b2=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);
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(1*Point),OrderTakeProfit(),0,Red); }
OrderSelect(s2,SELECT_BY_TICKET); if(OrderCloseTime()>0) {s2=0; SendMail(Symbol()+" "+OrderComment(),"$"+DoubleToStr(OrderProfit(),2)); }
//end
return(0);}
//+------------------------------------------------------------------+
int TotalTradesThisSymbol(string TradeSymbol) {
int i, TradesThisSymbol=0;
for(i=0;i<OrdersTotal();i++) {
OrderSelect(i,SELECT_BY_POS);
if(OrderSymbol()==TradeSymbol &&
(OrderMagicNumber()==11 ||
OrderMagicNumber()==21 ||
OrderMagicNumber()==41 ||
OrderMagicNumber()==51)) { TradesThisSymbol++; } }
return(TradesThisSymbol); }//end TotalTradesThisSymbol