//+------------------------------------------------------------------+ //| PipsLandEA.mq4 | //| Copyright © 2007, PipsLandGroups | //| http://PipsLand.co.nr | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, PipsLand" #property link "http://PipsLand.co.nr" extern int MaxTrades = 7; extern int Pips = 10; extern double TakeProfit = 40; extern double TrailingStop = 15; extern double InitialStop = 90; extern bool Mini = false; extern bool MM = false; extern double Risk = 5; string Note1 = "Valid TimeFrames: 1, 5, 15, 30, 60, 240, 1440, 10080, 43200"; int MACDTimeFrame = 0; extern int SecureProfit = 10; int AccountProtection = 1; extern int OrdersToProtect = 5; int ReverseCondition = 0; extern double FirstOrderLots=0.1; extern bool UseHourTrade = true; // Time filter extern int FromHourTrade = 4; // start trading on this hour extern int ToHourTrade = 10; // end trading on this hour int OrdersOpened = 0; int cnt = 0; double lots = 0.1; int slippage = 5; double stoploss = 0; double takeprofit = 0; double bprice = 0; double sprice = 0; double lotsi = 0; int type = 0; int state = 0; bool EnableTrading = true; double openprice = 0; int PreviousOrders = 0; double Profit = 0; int LastTicket = 0; int LastType = 0; double LastClosePrice = 0; double LastLots = 0; double PipValue = 0; string text2 = ""; string text = ""; double lotstmp; int Price = 0; //Apply to Price(0-Close;1-Open;2-High;3-Low;4-Median price;5-Typical price;6-Weighted Close) int Length = 30; //Period of NonLagMA int Displace = 0; //DispLace or Shift double PctFilter = 0; //Dynamic filter in decimal int Color = 1; //Switch of Color mode (1-color) int ColorBarBack = 0; //Bar back for color mode double Deviation = 0; //Up/down deviation int SoundAlertMode = 0; //Sound Alert switch //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ int deinit() { return(0); } double NonLag(double TFnonlag,int buffer, int iBar) { double mLag, mLag0, mLag1, mLag2; mLag = iCustom(Symbol(), TFnonlag, "NonLagMA_v6", Price, Length, Displace, PctFilter, Color, ColorBarBack, Deviation, SoundAlertMode, buffer, iBar); return(mLag); } double LotSize(){ if(Mini==true) { double lotMM = MathCeil(AccountFreeMargin() * Risk / 10000); } else { lotMM = MathCeil(AccountFreeMargin() * Risk / 10000) / 10; } if (lotMM < 0.1) lotMM = FirstOrderLots; if (lotMM > 1.0) lotMM = MathCeil(lotMM); if (lotMM > 1000) lotMM = 1000; return (lotMM); } //+------------------------------------------------------------------+ int start() { lotsi = FirstOrderLots; if(MM==true) lotsi = LotSize(); OrdersOpened = 0; for (cnt = 0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderSymbol() == Symbol()) OrdersOpened++; } PipValue=MarketInfo(Symbol(),MODE_TICKVALUE); if (PipValue == 0.0) PipValue = 5; if (PreviousOrders > OrdersOpened) { for (cnt = OrdersTotal(); cnt >= 0; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); type = OrderType(); if (OrderSymbol() == Symbol()) { if (type == OP_BUY) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Blue); if (type == OP_SELL) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red); //return(0); } } } PreviousOrders = OrdersOpened; if (OrdersOpened >= MaxTrades) EnableTrading = false; else EnableTrading = true; if (openprice == 0.0) { for (cnt = 0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); type = OrderType(); if (OrderSymbol() == Symbol()) { openprice = OrderOpenPrice(); if (type == OP_BUY) state = 2; if (type == OP_SELL) state = 1; } } } if (OrdersOpened < 1) { state = 3; double RMI=iCustom(NULL,0,"RMI",14,5,PRICE_CLOSE,1); double mLag = NonLag(15,1, 1); double mLag2 = NonLag(15,2, 1); double mLagbuy = NonLag(60,1, 1); double mLagsell = NonLag(60,2, 1); double barhim15=iHigh(Symbol(),15,1); double barlom15=iLow(Symbol(),15,1); double Stoch1=iStochastic(Symbol(),60,5,3,3,MODE_SMA,0,MODE_MAIN,1); double Stoch2=iStochastic(Symbol(),60,5,3,3,MODE_SMA,0,MODE_SIGNAL,1); if ((mLag > 0) && (mLag < 1000) && (mLagbuy > 0) && (mLagbuy < 1000) && ((barhim15-barlom15)<30*Point) && Bid>barhim15) state = 2; if ((mLag2 > 0) && (mLag2 < 1000) && (mLagsell > 0) && (mLagsell < 1000) && ((barhim15-barlom15)<30*Point) && Bid= 0; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderSymbol() == Symbol()) { if (OrderType() == OP_SELL) { if (TrailingStop > 0.0) { if (OrderOpenPrice() - Ask >= (TrailingStop + Pips) * Point) { if (OrderStopLoss() > Ask + Point * TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask + Point * TrailingStop,OrderClosePrice() - TakeProfit * Point - TrailingStop * Point,800,Purple); return(0); } } } } if (OrderType() == OP_BUY) { if (TrailingStop > 0.0) { if (Bid - OrderOpenPrice() >= (TrailingStop + Pips) * Point) { if (OrderStopLoss() < Bid - Point * TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid - Point * TrailingStop,OrderClosePrice() + TakeProfit * Point + TrailingStop * Point,800,Yellow); return(0); } } } } } } Profit = 0; LastTicket = 0; LastType = 0; LastClosePrice = 0; LastLots = 0; for (cnt = 0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderSymbol() == Symbol()) { LastTicket = OrderTicket(); if (OrderType() == OP_BUY) LastType = 0; if (OrderType() == OP_SELL) LastType = 1; LastClosePrice = OrderClosePrice(); LastLots = OrderLots(); if (LastType == 0) { if (OrderClosePrice() < OrderOpenPrice()) Profit -= (OrderOpenPrice() - OrderClosePrice()) * OrderLots() / Point; if (OrderClosePrice() > OrderOpenPrice()) Profit += (OrderClosePrice() - OrderOpenPrice()) * OrderLots() / Point; } if (LastType == 1) { if (OrderClosePrice() > OrderOpenPrice()) Profit -= (OrderClosePrice() - OrderOpenPrice()) * OrderLots() / Point; if (OrderClosePrice() < OrderOpenPrice()) Profit += (OrderOpenPrice() - OrderClosePrice()) * OrderLots() / Point; } } } Profit = Profit * PipValue; text = "Profit: $" + DoubleToStr(Profit,2) + " +/-"; double Profit2=0; for (int cnt=0;cnt= MaxTrades - OrdersToProtect) && (AccountProtection == 1)) { double TotProfit=((Profit2/PipValue)/lotsi); if (TotProfit >= SecureProfit) { OrderClose(LastTicket,LastLots,LastClosePrice,slippage,Yellow); EnableTrading = false; return(0); } } if (!IsTesting()) { if (state == 3) text2 = "No conditions to open trades"; else text2 = " "; } if (UseHourTrade){ if(!(Hour()>=FromHourTrade&&Hour()<=ToHourTrade)&&(OrdersOpened<1)){ // Comment("Non-Trading Hours!"); return(0); } if(!(Hour()>=FromHourTrade&&Hour()<=ToHourTrade)&&(OrdersOpened>1)){ // Comment("Non-Trading Hours!"); if(AccountProfit()>10) { for(cnt=OrdersTotal();cnt>=0;cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if ((OrderType()==OP_BUY||OrderType()==OP_SELL)) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,Blue); } } return(0); } } } if((Month()==12) && (Day()>22&&Day()<=31) &&(OrdersOpened<1)) { return(0); } if((Month()==1) && (Day()>=1&&Day()<3) &&(OrdersOpened<1)) { return(0); } if ((state == 1) && EnableTrading) { if ((Bid - openprice >= Pips * Point) || (OrdersOpened < 1)) { sprice = Bid; openprice = 0; if (TakeProfit == 0.0) takeprofit = 0; else takeprofit = sprice - TakeProfit * Point; if (InitialStop == 0.0) stoploss = 0; else stoploss = sprice + InitialStop * Point; if (OrdersOpened != 0) { lots = lotsi; for (cnt = 1; cnt <= OrdersOpened; cnt++) { if (MaxTrades>12) { lots=NormalizeDouble(lots*1.5,2); } else { lots=NormalizeDouble(lots*2,2); } } } else { lots = lotsi; } if (lots > 100.0) lots = 100; OrderSend(Symbol(),OP_SELL,lots,sprice,slippage,stoploss,takeprofit,0,0,0,Red); return(0); } } if ((state == 2) && EnableTrading) { if ((openprice - Ask >= Pips * Point) || (OrdersOpened < 1)) { bprice = Ask; openprice = 0; if (TakeProfit == 0.0) takeprofit = 0; else takeprofit = bprice + TakeProfit * Point; if (InitialStop == 0.0) stoploss = 0; else stoploss = bprice - InitialStop * Point; if (OrdersOpened != 0) { lots = lotsi; for (cnt = 1; cnt <= OrdersOpened; cnt++) { if (MaxTrades>12) { lots=NormalizeDouble(lots*1.5,2); } else { lots=NormalizeDouble(lots*2,2); } } } else { lots = lotsi; } if (lots > 100.0) lots = 100; OrderSend(Symbol(),OP_BUY,lots,bprice,slippage,stoploss,takeprofit,0,0,0,Blue); return(0); } } Comment("PipsLand EA","\nBy PipsLand Groups","\nProfit=",text); return(0); }