//+------------------------------------------------------------------+ //| ULTRON-3.3.mq4 | //| Copyright 2018, Pawel.Gawron | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, Pawel.Gawron" #property version "3.3" #property strict static input string Input_Section_1 = ">>>>>>>>>> Magic Number <<<<<<<<<<"; // ------ Input Section 1 ------ input int MAGICMA = 20131111; static input string Input_Section_2 = ">>>>>>>>>> Trade Setting <<<<<<<<<<"; // ------ Input Section 2 ------ extern double lots =1.0; extern double AccountSize =10000.00; extern double TakeProfit = 68; extern double StopLoss = 55; input double ExponentialFactorIncrease = 1.1; input double ExponentialFactorDecrease = 0.9; static input string Input_Section_3 = ">>>>>>>>>> Trading Hours <<<<<<<<<<"; // ------ Input Section 3 ------ input double GMT = 3.5; input int hour1 = 6; input int hour2 = 21; static input string Input_Section_4 = ">>>>>>>>>> MA Periods <<<<<<<<<<"; // ------ Input Section 4 ------ input int PeriodMA1 = 9; input int PeriodMA2 = 9; input int PeriodMA3 = 50; input int PeriodMA4 = 1; int CountSymbolPositions=0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create timer EventSetTimer(60); ChartSetInteger(0,CHART_SHOW_GRID,False); if(Digits()==3 || Digits()==5) { TakeProfit *= 10; StopLoss *= 10; } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { LotOPtimizer(); CehckForOrder(); return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void LotOPtimizer() { CountSymbolPositions=0; for(int trade=OrdersTotal()-1;trade>=0;trade--) { if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()==Symbol()) { if((OrderType()==OP_SELL||OrderType()==OP_BUY) && OrderMagicNumber()==MAGICMA) CountSymbolPositions++; } } if(AccountBalance()>ExponentialFactorIncrease*AccountSize){ lots=lots*ExponentialFactorIncrease; AccountSize=AccountSize*ExponentialFactorIncrease; } if(AccountBalance()Close[2]) && (Close[2]>Open[2]) && (CountSymbolPositions<1) && (Hour()>hour1 + GMT) && (Hour()0.0004)){return(True);} else { return(False); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool SellSignal() { double ma1 = iMA(NULL,PERIOD_CURRENT,PeriodMA1,0,MODE_LWMA,PRICE_OPEN, 0); double ma2 = iMA(NULL,PERIOD_CURRENT,PeriodMA2,0,MODE_LWMA,PRICE_CLOSE,0); double ma3 = iMA(NULL,PERIOD_CURRENT,PeriodMA3,0,MODE_SMA, PRICE_CLOSE,0); double ma4 = iMA(NULL,PERIOD_CURRENT,PeriodMA4,0,MODE_SMA, PRICE_CLOSE,0); double ma1ma2 = ma1-ma2; double ma2ma1 = ma2-ma1; double ma3ma4 = ma3-ma4; double ma4ma3 = ma4-ma3; if((ma3ma4<0.0048) && (ma3>ma1) && (ma3>ma2) && (Close[1]hour1 + GMT) && (Hour()0.0004)) { return(True);} else { return(False); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckForSell(double dStopLoss, double dTakeProfit) { if(Volume[0]>25) return; int res=OrderSend(Symbol(),OP_SELL,lots,Bid,20 /*slippage*/,dStopLoss,dTakeProfit,"",MAGICMA,0,Red); return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckForBuy(double dStopLoss, double dTakeProfit) { if(Volume[0]>25) return; int res=OrderSend(Symbol(),OP_BUY,lots,Ask,20 /*slippage*/,dStopLoss,dTakeProfit,"",MAGICMA,0,Blue); return; }