//+------------------------------------------------------------------+ //| TTS.mq4 | //| Copyright © 2011, AM2 | //| http://www.forexsystems.biz | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, AM2" #property link "http://www.forexsystems.biz" #define MAGIC 20110316 extern double MAOpenPer1 = 16; extern double MAOpenPer2 = 60; extern double MAOpenPer3 = 100; extern double MAClosePer1 = 10; extern double MAClosePer2 = 40; extern double MovingShift = 6; extern int ADXPer = 14; extern int ADXLevel = 30; extern int ZeroLevel = 500; extern double Lots = 1; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //---- for(int i=0;i0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { int res; //---- go trading only for first tiks of new bar if(Volume[0]>1) return; //---- get Moving Average double ma1=iMA(NULL,0,MAOpenPer1,MovingShift,MODE_SMA,PRICE_CLOSE,0); double ma2=iMA(NULL,0,MAOpenPer2,MovingShift,MODE_SMA,PRICE_CLOSE,0); double ma3=iMA(NULL,0,MAOpenPer3,MovingShift,MODE_SMA,PRICE_CLOSE,0); double adx1=iADX(NULL,0,ADXPer,PRICE_CLOSE,MODE_MAIN,0); double adx2=iADX(NULL,0,ADXPer,PRICE_CLOSE,MODE_MAIN,1); double adx3=iADX(NULL,0,ADXPer,PRICE_CLOSE,MODE_MAIN,2); //---- buy conditions if(ma1>ma2 && Open[0]>ma3 && adx1>adx2 && adx2>adx3 && adx3adx2 && adx2>adx3 && adx31) return; //---- get Moving Average double ma1=iMA(NULL,0,MAClosePer1,MovingShift,MODE_SMA,PRICE_CLOSE,0); double ma2=iMA(NULL,0,MAClosePer2,MovingShift,MODE_SMA,PRICE_CLOSE,0); //---- for(int i=0;ima2) OrderClose(OrderTicket(),OrderLots(),Ask,3,White); break; } } //---- } //+------------------------------------------------------------------+ //| Zero | //+------------------------------------------------------------------+ int Zero() { if (OrderType() == OP_BUY) { if (OrderOpenPrice() <= (Bid - ZeroLevel * Point) && OrderOpenPrice() > OrderStopLoss()) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green); } } if (OrderType() == OP_SELL) { if (OrderOpenPrice() >=(Ask + ZeroLevel * Point) && OrderOpenPrice() < OrderStopLoss()) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red); } } } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //---- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); //---- for (int i=0; i