//+------------------------------------------------------------------+ //| Demarker_RSI_EA.mq4 | //| Copyright © 2019, Gehtsoft USA LLC | //| http://fxcodebase.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2019, Gehtsoft USA LLC" #property link "http://fxcodebase.com" #property version "1.00" #property strict #define MAGICMA 33457236 enum SignalTypes { Direct, Reverse }; enum AllowedSides { Both, Buy, Sell }; input int RSI_Length=14; input ENUM_APPLIED_PRICE RSI_Price=PRICE_CLOSE; input int Demarker_Length=14; input double Long_RSI_Level=50.; input double Long_Demarker_Level=0.5; input double Short_RSI_Level=50.; input double Short_Demarker_Level=0.5; input SignalTypes Signal_Type=Direct; input AllowedSides 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; datetime LastBar; double Dist; 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;iLong_RSI_Level && Dem0>Long_Demarker_Level)) || (Signal_Type==Reverse && (RSI0Long_RSI_Level && Dem0>Long_Demarker_Level)) || (Signal_Type==Direct && (RSI0=0) { if (Allow_Trade) { CloseAll(); 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); } } } } } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { }