#property copyright "Richard Cloyd" #property link "Richard Cloyd" //---- extern bool UseFiveDigits = true; // You can use 5 or 4 digit brokers. If UseFiveDigits = true, your broker uses 5 digits int FiveDMultiplier = 1; // Manages the 5 digit fix extern int Positions = 1; // Max open positions extern int Slippage = 3; // Minimum slippage to trade extern int Sl,Tp,Tral=0,magic = 5432101; //EA's magic number extern double lot=0.1; #include int init() { Print(" Starting EA "); Print(": Broker Information : Symbol=",Symbol(),". MIN LOT=",MarketInfo(Symbol(), MODE_MINLOT),". MAX LOT=",MarketInfo(Symbol(), MODE_MAXLOT),". LOT SIZE IN BASE CURRENCY=",MarketInfo(Symbol(), MODE_LOTSIZE)); Print(": Min Stops= ",MarketInfo(Symbol(), MODE_STOPLEVEL), " pips."); if (UseFiveDigits) { FiveDMultiplier = 10; } Slippage = Slippage*FiveDMultiplier; Sl*=FiveDMultiplier; Tp*=FiveDMultiplier; if( (Digits==5 || Digits==3) && (!UseFiveDigits) ) { Print(":",Symbol()," Your setup is 4 digits but you seem to use a 5 digits broker. Please change UseFiveDigits to true"); MessageBox(": Your setup is 4 digits but you seem to use a 5 digits broker. Please change UseFiveDigits to true","5 Digits management"); } if( (Digits==4 || Digits==2) && (UseFiveDigits) ) { Print(":",Symbol()," Your setup is 5 digits but you seem to use a 4 digits broker. Please change UseFiveDigits to false"); MessageBox(": Your setup is 5 digits but you seem to use a 4 digits broker. Please change UseFiveDigits to false","5 Digits management"); } if(OrdersTotal()>0) { Print(":",Symbol()," Warning! There are existing positions. You may want to close them before running this EA."); MessageBox(": Warning! There are existing positions. You may want to close them before running this EA.","Warning: There are existing positions"); } if(IsTradeAllowed()==false) { Print(": Trading is not allowed! Make sure the checkbox Allow Live Trading is checked."); MessageBox("Trading is not allowed! Make sure the checkbox Allow Live Trading is checked.","Warning"); } } //************Stop EA int deinit() { Print(":",Symbol()," Stopping EA."); return(0); } //************EA Execution int start() { static int ss,bar,bar2; int b,s; if(bar!=Bars) { ss=ss(); bar=Bars; } for(int i=OrdersTotal()-1;i>=0;i--) if(OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderMagicNumber()==magic) { if(OrderType()==0) {b++; if(ss==1){close();continue;} if(Tral>0&&Bid-OrderOpenPrice()>Point*Tral && (OrderStopLoss()0&&OrderOpenPrice()-Ask>Point*Tral && (OrderStopLoss()>Ask+Point*(Tral+2) || OrderStopLoss()==0)) OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*Tral,OrderTakeProfit(),0,Red); } } if(bar2!=Bars&&b+s b1 && y2 > b2) { Print("yellow line crossed blue line, trending up; buy"); return (buy); } if (y1 > b1 && y2 < b2) { Print("yellow line crossed blue line, trending down; sell"); return (sell); } Print("lines are essentially parallel"); return (0); //no crossing } //---- bool buy() {int m; double x=MarketInfo(Symbol(),14),SL,TP;RefreshRates(); if(Sl<=0)SL=0;else{if(Sl0) { OrderSelect(tt,SELECT_BY_TICKET); if(SL==0&&TP==0)return(1); while(!OrderModify(OrderTicket(),0,SL,TP,0,Red)) {m++; Sleep(200);RefreshRates();if(Sl>0)SL-=1*Point;if(Tp>0)TP+=1*Point; if(m>=80||GetLastError()==1)break; } return(1); } else Print("Sell error open ",GetLastError()); return(0); } //---- bool sell() {int m; double x=MarketInfo(Symbol(),14),SL,TP;RefreshRates(); if(Sl<=0)SL=0;else{if(Sl0) { OrderSelect(tt,SELECT_BY_TICKET); if(SL==0&&TP==0)return(1); while(!OrderModify(OrderTicket(),0,SL,TP,0,Red)) {m++; Sleep(200);RefreshRates();if(Sl>0)SL+=1*Point;if(Tp>0)TP-=1*Point; if(m>=80||GetLastError()==1)break; } return(2); } else Print("Sell error open ",GetLastError()); return(0); } //---- bool close() { double pr;RefreshRates();if(OrderType()==0)pr=Bid;if(OrderType()==1)pr=Ask; if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(pr,Digits),100,Red)||GetLastError()==1){Print("Order was closed.");return(1);} else Print("Close Error ",GetLastError()); return(0); } //----