//+------------------------------------------------------------------+ //| SMC.mq4 //| + //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ extern double Lots = 0.1; extern int LotsMultiplier=2; extern int BreakEvenStart=25; extern int ProtectProfit = 5; extern int TrailingStop = 25; extern int TakeProfit = 100; extern double RiskPercent = 1; extern bool PositionManagement=false; extern bool OrderClosure=false; extern int AllowedPositions=5; string LastOrder; string Trend; datetime BarTime; //##################################################################### int init() { //---- Trend = "NONE"; LastOrder= " "; //---- return(0); } //############################################################################# int start() { double SL,TP,Spread,MinDist,MaxRisk; string MaxRiskStr; bool CloseLongs,CloseShorts; bool Buy,Sell; int total,ticket,err,tmp,cnt; int NumberofPositions; int BuyLots; if(Bars<100){Print("bars less than 100"); return(0); } //################################################################################ //~~~~~~~~~~~~~~~~Miscellaneous setup stuff~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MinDist=(MarketInfo(Symbol(),MODE_STOPLEVEL)*Point); Spread=(Ask-Bid); MaxRisk=(AccountFreeMargin()*RiskPercent/100)*Point; MaxRiskStr=DoubleToStr(MaxRisk,4); //############################################################################# //~~~~~~~~~~~~~~~~~~INDICATOR CALCULATIONS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double SMAP1,MMAP1,LMAP1,SMAP2,MMAP2,LMAP2; SMAP1=iMA(NULL,0,9,0,MODE_EMA,PRICE_CLOSE,1); SMAP2=iMA(NULL,0,9,0,MODE_EMA,PRICE_CLOSE,2); MMAP1=iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,1); MMAP2=iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,2); double MomP1; MomP1=iMomentum(NULL,0,21,PRICE_CLOSE,1); //############################################################################# tmp=0; err=0; tmp = ObjectGet("X"+Time[0],6); err = GetLastError(); if(err!=0) {ObjectCreate("X"+Time[0],22,0,Time[0],High[1]); ObjectSet("X"+Time[0],14,2); ObjectSetText("X"+Time[0],TimeToStr(Time[0])); ObjectSet("X"+Time[0],6,Gray); } ObjectDelete("X"+Time[3]); //############################################################################# Comment("SMC BB RR & Breakout Trend = ", Trend," ", Hour()," ",Minute()," ",Seconds(), "\n", "TRADING VALUES", "\n", "Spread ", Spread," MinDist ",MinDist," Max Risk ",MaxRiskStr, "\n", "Ask/Bid ",Ask," ",Bid, "\n", "SYSTEM PARAMETERS", "\n" ); //############################################################################## //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //BUY and SELL rules: Buy = false; Sell =false; tmp=0; tmp=ObjectGet("X"+Time[0],6); //add in tmp=gray check if(tmp!=Pink) { //################################################################################ //~~~~~~~~~~~~BUY~~~~~~~~~~~~~~~~~~~~~~~~ if(SMAP2MMAP1&& MomP1>100) { Buy=true; LastOrder = " Buy Breakout"; ObjectSet("X"+Time[0],6,Pink); SL=LMAP1; TP=0; } //################################################################################ //~~~~~~~~~~~SELL~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if(SMAP2>LMAP2 && SMAP1 MMAP1) CloseShorts=true; OrderClosure=true; //turn off MM //PositionManagement = false; //OrderClosure=false; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if(PositionManagement == true) { tmp=0; tmp = ObjectGet("X"+Time[0],6); if(tmp==Gray) { ObjectSet("X"+Time[0],6,Blue); total=OrdersTotal(); if(total>0) { for(cnt=0;cnt OrderOpenPrice() + (BreakEvenStart*Point)) SL= OrderOpenPrice(); // if(Bid > OrderStopLoss() + (TrailingStop*Point)) SL= Bid-(TrailingStop*Point); //####################################################################### if(SL > OrderStopLoss()) {OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Orange);} }}} //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ total=OrdersTotal(); if(total>0) { for(cnt=0;cnt0) { for(cnt=0;cnt0) { for(cnt=0;cnt0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {Print("SELL order opened : ",OrderOpenPrice()); Alert("Sell Order for ",Symbol()); SendMail("Sell Order "+Symbol()+" "+Bid,Bid); } } else Print("Error opening SELL order : ",GetLastError()); return(0); } //############ End of PROGRAM ######################### return(0); } //####################################################################################