//+------------------------------------------------------------------+ //| vfx_demo.mq4 | //| Alexandr M | //| http://vfxlab.net/ | //+------------------------------------------------------------------+ #property copyright "Alexandr M" #property link "http://vfxlab.net/" #property version "1.05" int _Sell = -1; int _Buy = 1; extern int TakeProfit = 250; extern int StopLoss = 150; int Lots = 1; int nMagic = 369853; int LastOpenTime = 0; int OnInit(){ return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { int signal = signal_cci(); if (!CheckFilters(signal) && isUseFilters) return; if (isTradeAllowed()){ if(signal== _Buy) { buy(); } if(signal== _Sell){ sell(); } } } int signal_cci() { // ---------------------------------- CCI crossing 100 level - buy; crossing -100 level - sell double x1,x2; x1 = iCCI(Symbol(),_Period,50,PRICE_TYPICAL,0); x2 = iCCI(Symbol(),_Period,50,PRICE_TYPICAL,1); if(x1>-100 && x2<=-100) return _Sell; if(x1<100 && x2>=100) return _Buy; return 0; } extern bool isUseFilters = true; bool CheckFilters (int signal) { //true - you can trade if(signal==_Buy) { return iATR(NULL,_Period,14,0)<0.0002; } if(signal==_Sell) { return iATR(NULL,_Period,14,0)<0.0002; } return true; } //--------------------------------isTradenAllowed-------------------------------- bool isTradeAllowed() { if (LastOpenTime>=Time[0] - Period()*60) return false; // Do not open order twice on the same bar return true; } bool sell() {//------------------------------sell---------------------------------- string comment =""; int ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,nMagic); if(ticket<0){ printf("Open SELL order error (%i) | Ask = %g, sl=%g, tp=%g", GetLastError(),Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point); return false; } else { LastOpenTime = Time[0]; } return true; } bool buy( ){ // ---------------------------buy-------------------------------------- string comment = ""; int ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,nMagic); if(ticket<0) { printf("Open BUY order error(%i) | Ask = %i, sl=%g, tp=%g", GetLastError(),Ask,Ask-StopLoss*Point,Ask+TakeProfit*Point); return false; } else { LastOpenTime = Time[0]; } return true; }