//+------------------------------------------------------------------+ //| HedgExpert_v1.1.mq4 | //| Copyright © 2006, Forex-TSD.com | //| Written by IgorAD,igorad2003@yahoo.co.uk | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Forex-TSD.com " #property link "http://www.forex-tsd.com/" #include //#include //---- input parameters extern string Expert_Name = "---- HedgExpert_v1.1 ----"; extern int Magic = 10000; extern int Slippage = 6; extern bool Trace = false; // Trace Switch extern string Main_Parameters = " Trade Volume & Trade Method"; extern double Lots = 0.1; // Lot size extern int OrdersMode = 2; // 1- Limit Orders; 2 - Stop Orders extern string Data = " Input Data "; extern string TimeFrame = "H1"; // Working period (M1,M5...H1...D1...W1) for Orders Opening extern double NetProfit = 50; // Net Profit in pips extern double NetLoss = 50; // Net Loss in pips extern double InitialStop = 0; // Initial Stop Value in pips extern double TrailingStop = 10; // Trailing Stop Value in pips extern double TakeProfit = 0; // Take Profit Value in pips extern double FirstOrdGap = 10; // Gap for Pending Orders from Open[0] in pips extern int NumberOrds = 2; // Number of orders to place extern double StepSize = 10; // Pips between orders extern string MM_Parameters = " MoneyManagement by L.Williams "; extern bool MM=false; // ΜΜ Switch extern double MMRisk=0.15; // Risk Factor extern double LossMax=1000; // Maximum Loss by 1 Lot int i=0, cnt=0, ticket, mode=0, digit=0, numords, PeriodName, MagicNum ; double open=0, low=0, spread=0, SellProfit=0,BuyProfit=0, point; double smin=0, smax=0, BuyStop=0, SellStop=0, Lotsi=0; bool BuyInTrade=false, SellInTrade=false; datetime Previous_bar; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- if (TimeFrame=="M1" || TimeFrame=="1" ) PeriodName=PERIOD_M1; else if (TimeFrame=="M5" || TimeFrame=="5" ) PeriodName=PERIOD_M5; else if (TimeFrame=="M15" || TimeFrame=="15" )PeriodName=PERIOD_M15; else if (TimeFrame=="M30" || TimeFrame=="30" )PeriodName=PERIOD_M30; else if (TimeFrame=="H1" || TimeFrame=="60" ) PeriodName=PERIOD_H1; else if (TimeFrame=="H4" || TimeFrame=="240" ) PeriodName=PERIOD_H4; else if (TimeFrame=="D1" || TimeFrame=="1440" ) PeriodName=PERIOD_D1; else if (TimeFrame=="W1" || TimeFrame=="10080" ) PeriodName=PERIOD_W1; else if (TimeFrame=="MN" || TimeFrame=="43200" ) PeriodName=PERIOD_MN1; else { PeriodName=Period(); return(0); } Previous_bar=iTime(Symbol(),PeriodName,0); //---- return(0); } // ---- Money Management double MoneyManagement ( bool flag, double Lots, double risk, double maxloss) { Lotsi=Lots; if ( flag ) Lotsi=NormalizeDouble(Lots*AccountFreeMargin()*risk/maxloss,1); if (Lotsi<0.1) Lotsi=0.1; return(Lotsi); } // ---- Trailing Stops void TrailStops() { int total=OrdersTotal(); for (cnt=0;cnt 0 && Bid-OrderOpenPrice()>Point*ProfitLock ) smin = OrderOpenPrice(); BuyProfit=OrderTakeProfit(); if( BuyStop > OrderStopLoss()) { OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(BuyStop, digit), BuyProfit,0,LightGreen); return(0); } } if ( OrderMagicNumber() == Magic+NumberOrds+i && mode==OP_SELL ) { SellStop = Ask + TrailingStop*Point; //if ( ProfitLock > 0 && OrderOpenPrice()-Ask>Point*ProfitLock ) smax = OrderOpenPrice(); SellProfit=OrderTakeProfit(); if( SellStop < OrderStopLoss() || OrderStopLoss()==0) { OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(SellStop, digit), SellProfit,0,Yellow); return(0); } } } } } } // ---- Open Sell Orders void SellOrdOpen() { if (OrdersMode == 1) { double SellPrice=open + FirstOrdGap*Point+(i-1)*StepSize*Point; int Type = OP_SELLLIMIT; } else if (OrdersMode == 2) { SellPrice=open - FirstOrdGap*Point-(i-1)*StepSize*Point; Type = OP_SELLSTOP; } if (InitialStop > 0) SellStop=SellPrice + InitialStop*Point; else SellStop=0; if (TakeProfit > 0) SellProfit=SellPrice - TakeProfit*Point; else SellProfit=0; ticket = OrderSend( Symbol(),Type,Lotsi, NormalizeDouble(SellPrice, digit), Slippage, NormalizeDouble(SellStop , digit), NormalizeDouble(SellProfit , digit), "sell",MagicNum,0,Red); SellInTrade=false; if(ticket<0) { Print("SELL Order: OrderSend failed with error #",GetLastError()); // } } // ---- Open Buy Orders void BuyOrdOpen() { if (OrdersMode == 1) { double BuyPrice =open - FirstOrdGap*Point - (i-1)*StepSize*Point; int Type = OP_BUYLIMIT; } else if (OrdersMode == 2) { BuyPrice =open + FirstOrdGap*Point + (i-1)*StepSize*Point; Type = OP_BUYSTOP; } if (InitialStop >0) BuyStop = BuyPrice - InitialStop*Point; else BuyStop=0; if (TakeProfit >0) BuyProfit=BuyPrice + TakeProfit*Point; else BuyProfit=0; ticket = OrderSend(Symbol(),Type, Lotsi, NormalizeDouble(BuyPrice, digit), Slippage, NormalizeDouble(BuyStop , digit), NormalizeDouble(BuyProfit , digit), "buy",MagicNum,0,Blue); BuyInTrade=false; if(ticket<0) { Print("BUY Order: OrderSend failed with error #",GetLastError()); //return(0); } } // ---- Delete Extra Orders void AllOrdClose() { int total = OrdersTotal(); for (cnt=0;cnt=OP_BUY && OrderMagicNumber() == Magic+i) numords++; } } return(numords); } double ScanProfit() { int total = OrdersTotal(); double profit,sprofit,bprofit,bval,sval; for(cnt=0; cnt