//+------------------------------------------------------------------+ //| CCI_RSI_Str.mq4 | //| Copyright © 2019, Gehtsoft USA LLC | //| http://fxcodebase.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2019, Gehtsoft USA LLC" #property link "http://fxcodebase.com" #property version "1.1" #property strict #define MAGICMA 3454363 enum Side_Types{Both, Buy, Sell}; input ENUM_APPLIED_PRICE Price=PRICE_CLOSE; input int CCI1_Period=100; input int CCI2_Period=50; input int RSI_Period=30; input double CCI1_Buy_Level=70.; input double CCI1_Sell_Level=30.; input double CCI2_Buy_Level=70.; input double CCI2_Sell_Level=30.; input double RSI_Buy_Level=50.; input double RSI_Sell_Level=50.; input Side_Types Allowed_Side=Both; input bool Allow_Trade=true; input double Lots=0.1; input bool Set_Stop=true; input int Stop=50; input bool Set_Limit=true; input int Limit=100; input bool Show_Alert=true; input bool Play_Sound=false; input string Sound_File=""; input bool Send_Email=false; input int ADXLength = 10; // ADX Length input double ADXExitLevel1 = 70; // ADX Exit Level 1 input double ADXExitLevel2 = 50; // ADX Exit Level 2 datetime LastBar; int OnInit() { LastBar=0; return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void CloseAll() { bool res; int OT=OrdersTotal(); for (int i=OT-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA) { if(OrderType()==OP_BUY) res=OrderClose(OrderTicket(), OrderLots(), Bid, 5); if(OrderType()==OP_SELL) res=OrderClose(OrderTicket(), OrderLots(), Ask, 5); } } } void _Alert(string op) { if (Show_Alert) { Alert(Symbol()+" :"+op); } if (Play_Sound) { PlaySound(Sound_File); } if (Send_Email) { SendMail(Symbol()+" :", op); } } int CalculateOrders() { int Count=0; for(int i=0;iCCI1_Buy_Level && CCI11<=CCI1_Buy_Level && CCI2>CCI2_Buy_Level && RSI>RSI_Buy_Level) { if (CO<0) { _Alert("Close Sell"); CloseAll(); } _Alert("Buy"); if (Allow_Trade) { if (Allowed_Side!=Sell) { if (Set_Stop) { SL=NormalizeDouble(Bid-Stop*Point, Digits); } else { SL=0.; } if (Set_Limit) { TP=NormalizeDouble(Bid+Limit*Point, Digits); } else { TP=0.; } res=OrderSend(Symbol(), OP_BUY, Lots, Ask, 5, SL, TP, "", MAGICMA, 0, Blue); } } } if (CCI10=CCI1_Sell_Level && CCI20) { _Alert("Close Buy"); CloseAll(); } _Alert("Sell"); if (Allow_Trade) { if (Allowed_Side!=Buy) { if (Set_Stop) { SL=NormalizeDouble(Ask+Stop*Point, Digits); } else { SL=0.; } if (Set_Limit) { TP=NormalizeDouble(Ask-Limit*Point, Digits); } else { TP=0.; } res=OrderSend(Symbol(), OP_SELL, Lots, Bid, 5, SL, TP, "", MAGICMA, 0, Blue); } } } double adx0 = iADX(_Symbol, _Period, ADXLength, PRICE_CLOSE, MODE_MAIN, 0); double adx1 = iADX(_Symbol, _Period, ADXLength, PRICE_CLOSE, MODE_MAIN, 1); if ((adx0 < ADXExitLevel1 && adx1 >= ADXExitLevel1) || (adx0 < ADXExitLevel2 && adx1 >= ADXExitLevel2)) { _Alert("Close Sell"); CloseAll(); } } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { }