//+------------------------------------------------------------------+ //| test12.mq4 | //| Copyright 2014, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, LX Trading" #property version "1.00" #property strict int TradeType,Ticket,Breakout_Flag,OrderFree; double SL,TP,TP_Trade,SL_Size; double Stop_Diff,Lots; double PointIsPIP=(1/(Point*10000)); extern int Slippage=4; extern int Percent=5; //percent risked per trade extern double Breakout_Factor=15; bool CanTrade; //flag. true if conditions are true and there are no open orders by this EA. False otherwise int Slip=int(Slippage*PointIsPIP); string Symb=Symbol(); double BreakoutFactor; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Breakout_Flag=1; //only allows one trade per break out. Flag is set so that no late entry trades will be made when terminal opens OrderFree=1; //a flag that is set to 1 if no orders by this EA are open, and 0 if there is an order open that was made by this EA. Determined by order accounting BreakoutFactor=NormalizeDouble((Breakout_Factor/10000),4); //width of bollinger bands before a "break out" is identified //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { // Preliminary processing Prelim(); //------------------------------------------------------------------------------------------------- double Middle=NormalizeDouble(iBands(NULL,0,18,2,0,PRICE_CLOSE,MODE_MAIN,0),Digits); double MinStop=NormalizeDouble(MarketInfo(Symbol(),MODE_STOPLEVEL),Digits); OrderAcc(); if(OrderFree == 0 || Breakout_Flag == 1) {CanTrade = False;} if(OrderFree == 1 && Breakout_Flag == 0) {CanTrade = True;} //trading criteria + SL and TP calculations. Not opening orders until lot sizes are calculated SL=Middle; // if (SL < MinStop) {Alert("Stop distance too small to trade");} TradeType = Trade_Criteria(); Stop_Diff = MathAbs(NormalizeDouble((NormalizeDouble((Ask - SL), 4)*10000), 2)); Print("Stop",Stop_Diff); if(TradeType==01) { TP=NormalizeDouble((Bid+(100*Point)),Digits); } if(TradeType==02) { TP=NormalizeDouble((Ask -(100*Point)),Digits); } //------------------------------------------------------ if(CanTrade==True) { Open_Order(); } //Stop loss modify if(OrderFree==0) { SL=Middle; if(SL=BreakoutFactor) && (Macd>0) && (RSI>50) && (EMA>Middle)) { if(Close[1]>=Top) { Stop_Diff=MathAbs(NormalizeDouble((NormalizeDouble((Ask-SL),4)*10000),2)); return(01); } } //Sell criteria if((Diff>=BreakoutFactor) && (Macd<0) && (RSI<50) && (EMA