//+------------------------------------------------------------------+ //| SMC Autotrader Momentum.mq4 | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ extern double TakeProfit = 50; extern double LockProfit = 3; extern double Lots = 0.1; extern double InitialStop = 30; extern double TrailingStop = 10; datetime BarTime; double BUYat; double SELLat; //##################################################################### int init() { //---- //---- return(0); } //##################################################################### int start() { int cnt,total,ticket,MinDist,tmp; double Spread; //############################################################################ if(Bars<100){ Print("bars less than 100"); return(0); } //exit if not new bar if(BarTime == Time[0]) {return(0);} //new bar, update bartime BarTime = Time[0]; //######################################################################################### //~~~~~~~~~~~~~~~~Miscellaneous setup stuff~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MinDist=MarketInfo(Symbol(),MODE_STOPLEVEL); Spread=(Ask-Bid); double ATR = iATR(NULL,0,10,1); //######################################################################################### double MAP1 = iMA(NULL,0,8,5,MODE_SMMA,PRICE_MEDIAN,1); double MAP2 = iMA(NULL,0,8,5,MODE_SMMA,PRICE_MEDIAN,2); //####################################################################################### bool BUY = false; bool SELL = false; if (Close[0] > High[1] && Low[1] < MAP1 && High[1] > MAP1 && Close[2] > Open[2] && Close[3] > Open[3] ) BUY = true; if (Close[0] < Low[1] && High[1] > MAP1 && Low[1] < MAP1 && Close[2] < Open[2] && Close[3] < Open[3] ) SELL = true; //######################################################################################## //~~~~~~~~~~~~~~~~~~~LOCK IN PROFIT~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if(0==0) //This is used to turn the trailing stop on & off { total=OrdersTotal(); if(total>0) { for(cnt=0;cnt OrderOpenPrice()+ ((MinDist+2+ATR)*Point) ) {OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(MinDist+ATR*Point),OrderTakeProfit(),0,White); return(0);} }} total=OrdersTotal(); if(total>0) { for(cnt=0;cnt0) { for(cnt=0;cnt0) { for(cnt=0;cnt (Point*TrailingStop) && OrderStopLoss()0) { for(cnt=0;cnt (Point*TrailingStop) && OrderStopLoss() > Ask+(Point*TrailingStop) ) {OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Point*TrailingStop),OrderTakeProfit(),0,Yellow); return(0);} }} } // end bracket for on/off switch //########################################################################################## //~~~~~~~~~~~ END OF ORDER Closure routines & Stoploss changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~ //########################################################################################## //~~~~~~~~~~~~START of NEW ORDERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //######################### NEW POSITIONS ? ###################################### //Possibly add in timer to stop multiple entries within Period // Check Margin available // ONLY ONE ORDER per SYMBOL // Loop around orders to check symbol doesn't appear more than once // Check for elapsed time from last entry to stop multiple entries on same bar if (0==1) // switch to turn ON/OFF history check { total=HistoryTotal(); if(total>0) { for(cnt=0;cnt0) { for(cnt=0;cnt0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //ENTRY RULES: SHORT //################################ if(SELL == true) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,High[2]+ATR,0,"MACD System Short",16384,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } //#################################################################################### //############ End of PROGRAM ######################### return(0); }