//+------------------------------------------------------------------+ //| 10point3.mq4 | //| Copyright © 2005, Alejandro Galindo | //| Revised version from davidke20 | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, Alejandro Galindo" #property link "http://www.forex-tsd.com" extern int Magic = 772188; extern double TakeProfit = 10; extern double Lots = 0.01; extern double InitialStop = 160; extern double TrailingStop = 0; extern int MaxTrades = 5; extern double Multiplier = 2; extern int Pips = 5; extern bool AutoPipStep = true; extern int PipStepMTF = 0; extern int StandardDeviation = 90; extern bool Money_management = true; extern int AccountType = 2; //0: Standard account(NorthFinance,MiG,Alpari) 1: Normal account(FXLQ,FXDD) 2:InterbankFX's NANO Account extern double risk = 5; extern bool ReverseSignal = false; extern string MACD_Setup; extern int Fast_EMA = 12; extern int Slow_EMA = 26; extern int Signal_SMA = 9; extern int MACD_Price = 1; // 0:Close 1:Open 2:High 3:Low 4:Median 5:Typical 6:Weighted extern string Stochastics_Setup; extern int K = 5; extern int D = 3; extern int Slowing = 3; extern int Stoch_mode = 0; // 0:Simple 1:Exponential 2:Smoothed 3:Linear Weighted extern int Stoch_price = 0; // 0:High/Low 1:Close/Close extern int Shift = 1; extern bool UseTimeFilter=true; extern int StopTrade = 13; extern int StartTrade = 18; int OpenOrders=0, OtherSymbol=0, cnt=0; int slippage=5; double sl=0, tp=0; double BuyPrice=0, SellPrice=0; double lotsi=0, mylotsi=0; int mode=0; string myOrderType="No direction"; bool ContinueOpening=True; double LastPrice=0; int PreviousOpenOrders=0; double Profit=0; int LastTicket=0, LastType=0; double LastClosePrice=0, LastLots=0; double PipValue=0; string text="", text2=""; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //**************ADDED FOR ACCOUNT SENTRY *************** if (GlobalVariableGet("GV_CloseAllAndHalt") > 0){ return (0); } else //**************END ACCOUNT SENTRY HOOK **************** //--- Set Margin counter ---------------------------- WJ Begin --// //--- Init Code ---// string GlobValMargin = AccountNumber()+"_Stoch-Power-EA-5h_Margin"; if(!GlobalVariableCheck(GlobValMargin)) GlobalVariableSet(GlobValMargin,0); double AcctMargin = GlobalVariableGet(GlobValMargin); //--- Start Code ---// double AcctMarginCurr = AccountMargin(); if(AcctMargin < AcctMarginCurr){ AcctMargin = AcctMarginCurr; GlobalVariableSet(GlobValMargin,AcctMargin); } //--------------------------------------------------- WJ End ----// if(AutoPipStep) {Pips=DynamicPipStep(); InitialStop=0;} double MinLots = NormalizeDouble((MarketInfo(Symbol(), MODE_MINLOT)),2); double MaxLots = NormalizeDouble((MarketInfo(Symbol(), MODE_MAXLOT)),2); double LotSizeValue = NormalizeDouble((MarketInfo(Symbol(), MODE_LOTSIZE)),0); double PipValue=MarketInfo(Symbol(),16); if(Money_management) { switch(AccountType) { case 0:{lotsi=NormalizeDouble(MathCeil((risk*AccountBalance())/100000),1);}break; case 1:{lotsi=NormalizeDouble((risk*AccountBalance())/100000,2);}break; case 2:{lotsi=NormalizeDouble((risk*AccountBalance())/10000,2); }break; default :{lotsi=NormalizeDouble(MathCeil((risk*AccountBalance())/100000),1);}break; } } else { lotsi=Lots; } if(lotsiMaxLots){lotsi=MaxLots;} OpenOrders=0; OtherSymbol=0; Profit=0; for(cnt=0;cntOpenOrders) { for(cnt=OrdersTotal();cnt>=0;cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); mode=OrderType(); if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic) { if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Blue); } if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red); } return(0); } } } PreviousOpenOrders=OpenOrders; if (OpenOrders>=MaxTrades) { ContinueOpening=False; } else { ContinueOpening=True; } if (LastPrice==0) { for(cnt=0;cntStopTrade && Hour()=0;cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { if (OrderType()==OP_SELL) { if (TrailingStop>0) { if (OrderOpenPrice()-Ask>=(TrailingStop*Point+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) { if (Bid-OrderOpenPrice()>=(TrailingStop*Point+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;cntOrderOpenPrice()) { Profit=Profit+(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; } } if (LastType==OP_SELL) { //Profit=Profit+(Ord(cnt,VAL_OPENPRICE)-Ord(cnt,VAL_CLOSEPRICE))*PipValue*Ord(cnt,VAL_LOTS); if (OrderClosePrice()>OrderOpenPrice()) { Profit=Profit-(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; } if (OrderClosePrice()=(AccountBalance()*(risk/100) && Money_management)) || (Profit>=lotsi && !Money_management)) { OrderClose(LastTicket,LastLots,LastClosePrice,slippage,Yellow); myOrderType=3; ContinueOpening=False; Profit=0; return(0); } if (!IsTesting()) { if (myOrderType=="No direction") { text="No conditions to open trades"; } else { text=" "; } Comment("LastPrice=",LastPrice," Previous open orders=",PreviousOpenOrders,"\nContinue opening=",ContinueOpening, "\nOther orders=",OtherSymbol,"\nOrderType=",myOrderType,"\n",text2,"\nLots=",lotsi,"\n",text, "\nProperty of Alejandro Gallindo","\nhttp://elcactus.com\nhttp://www.forex-tsd.com"); } if (myOrderType=="Sell Only" && ContinueOpening && OtherSymbol==0) { if(AutoPipStep&& OpenOrders>0) {TakeProfit=0;InitialStop=0; if(PreviousOpenOrders>=MaxTrades-1)InitialStop=DynamicPipStep(); } if ((Bid-LastPrice)>=Pips*Point || OpenOrders<1) { SellPrice=Bid; LastPrice=0; if (TakeProfit==0) { tp=0; } else { tp=SellPrice-TakeProfit*Point; } if (InitialStop==0) { sl=0; } else { sl=NormalizeDouble(SellPrice+InitialStop*Point + (MaxTrades-OpenOrders)*Pips*Point, Digits); } if (OpenOrders!=0) { mylotsi=lotsi; for(cnt=1;cnt<=OpenOrders;cnt++) { if (MaxTrades>12) { mylotsi=NormalizeDouble(mylotsi*1.5,2); } else { mylotsi=NormalizeDouble(mylotsi*Multiplier,2); } } } else { mylotsi=lotsi; } if (mylotsi>100) { mylotsi=100; } OrderSend(Symbol(),OP_SELL,mylotsi,SellPrice,slippage,sl,tp,"10p3-Sell",Magic,0,Red); return(0); } } if (myOrderType=="Buy Only" && ContinueOpening && OtherSymbol==0) { if(AutoPipStep&& OpenOrders>0) {TakeProfit=0;InitialStop=0; if(PreviousOpenOrders>=MaxTrades-1)InitialStop=DynamicPipStep(); } if ((LastPrice-Ask)>=Pips*Point || OpenOrders<1) { BuyPrice=Ask; LastPrice=0; if (TakeProfit==0) { tp=0; } else { tp=BuyPrice+TakeProfit*Point; } if (InitialStop==0) { sl=0; } else { sl=NormalizeDouble(BuyPrice-InitialStop*Point - (MaxTrades-OpenOrders)*Pips*Point, Digits); } if (OpenOrders!=0) { mylotsi=lotsi; for(cnt=1;cnt<=OpenOrders;cnt++) { if (MaxTrades>12) { mylotsi=NormalizeDouble(mylotsi*1.5,2); } else { mylotsi=NormalizeDouble(mylotsi*Multiplier,2); } } } else { mylotsi=lotsi; } if (mylotsi>100) { mylotsi=100; } OrderSend(Symbol(),OP_BUY,mylotsi,BuyPrice,slippage,sl,tp,"10p3-Buy",Magic,0,Blue); return(0); } } //---- return(0); } //+------------------------------------------------------------------+ int DynamicPipStep() { int Pips=iStdDev(NULL,PipStepMTF,StandardDeviation,0,MODE_SMA,PRICE_CLOSE,Shift)/Point; return(Pips); } string MACD() { myOrderType="No direction"; double MACDMainCurr=iMACD(NULL,0,Fast_EMA,Slow_EMA,Signal_SMA,MACD_Price,MODE_MAIN,Shift); double MACDSigCurr=iMACD(NULL,0,Fast_EMA,Slow_EMA,Signal_SMA,MACD_Price,MODE_SIGNAL,Shift); double MACDMainPre=iMACD(NULL,0,Fast_EMA,Slow_EMA,Signal_SMA,MACD_Price,MODE_MAIN,Shift+1); double MACDSigPre=iMACD(NULL,0,Fast_EMA,Slow_EMA,Signal_SMA,MACD_Price,MODE_SIGNAL,Shift+1); double StocMainCurr=iStochastic(NULL,0,K,D,Slowing,Stoch_mode,Stoch_price,MODE_MAIN,0); if(MACDMainCurr>MACDSigCurr && MACDMainPreMACDSigPre && MACDMainCurr>0 && StocMainCurr>20) {myOrderType="Sell Only";} return(myOrderType); }