//+------------------------------------------------------------------+ //| Scalping_Str.mq4 | //| Copyright © 2017, Gehtsoft USA LLC | //| http://fxcodebase.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2017, Gehtsoft USA LLC" #property link "http://fxcodebase.com" #property version "1.00" #property strict #define MAGICMA 33454436 input ENUM_TIMEFRAMES TF1=PERIOD_M1; input ENUM_TIMEFRAMES TF2=PERIOD_M30; input int K2=5; input int D2=3; input int Slowing2=3; input ENUM_MA_METHOD Method2=MODE_SMA; input ENUM_STO_PRICE Price_Field2=STO_CLOSECLOSE; input ENUM_TIMEFRAMES TF3=PERIOD_H1; input double Step3=0.02; input double Max3=0.2; input int RSI_Period3=14; input ENUM_APPLIED_PRICE RSI_Price3=PRICE_CLOSE; input ENUM_TIMEFRAMES TF4=PERIOD_H4; input double Step4=0.02; input double Max4=0.2; input ENUM_TIMEFRAMES TF5=PERIOD_D1; input string Signal_Type_Str="Signal type: 0 - Direct, 1 - Reverse"; input int Signal_Type=0; // 0 - Direct, 1 - Reverse input bool Close_On_Opposite=true; input int Max_Numbers_Any=10; // Max numbers of position in any direction input int Max_Numbers_One=10; // Max numbers of position in one direction input string Allowed_Side_Str="Allowed side: 0 - Both, 1 - Buy, 2 - Sell"; input int Allowed_Side=0; // 0 - Both, 1 - Buy, 2 - Sell 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(int Dir=0) { 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 && Dir>=0) res=OrderClose(OrderTicket(), OrderLots(), Bid, 5); if(OrderType()==OP_SELL && Dir<=0) 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 Dir=0) { int Count=0; for(int i=0;iiOpen(NULL, TF3, 1)) { if (iClose(NULL, TF4, 1)>iOpen(NULL, TF4, 1)) { if (iClose(NULL, TF5, 1)>iOpen(NULL, TF5, 1)) { if (iRSI(NULL, TF3, RSI_Period3, RSI_Price3, 1)>50.) { if (iStochastic(NULL, TF2, K2, D2, Slowing2, Method2, Price_Field2, MODE_MAIN, 1)>20. && iStochastic(NULL, TF2, K2, D2, Slowing2, Method2, Price_Field2, MODE_MAIN, 1)<50.) { if (iStochastic(NULL, TF2, K2, D2, Slowing2, Method2, Price_Field2, MODE_MAIN, 1)>iStochastic(NULL, TF2, K2, D2, Slowing2, Method2, Price_Field2, MODE_MAIN, 2)) { if (iSAR(NULL, TF3, Step3, Max3, 1)50.) { if (iStochastic(NULL, TF2, K2, D2, Slowing2, Method2, Price_Field2, MODE_MAIN, 1)iClose(NULL, TF3, 1)) { if (iSAR(NULL, TF4, Step4, Max4, 1)>iClose(NULL, TF4, 1)) { if (Signal_Type==0) { Action=-1; } else { Action=1; } } } } } } } } } if (Action==1 && Allowed_Side==2) Action=0; if (Action==-1 && Allowed_Side==1) Action=0; int CO_B=CalculateOrders(1); int CO_S=CalculateOrders(-1); if (Action!=0 && CO_B+CO_S>=Max_Numbers_Any) Action=0; if (Action==1 && CO_B>=Max_Numbers_One) Action=0; if (Action==-1 && CO_S>=Max_Numbers_One) Action=0; if (Action==1 && CO_S>0 && Close_On_Opposite) CloseAll(-1); if (Action==-1 && CO_B>0 && Close_On_Opposite) CloseAll(1); if (Action==1) { _Alert("Buy"); if (Allow_Trade) { 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 (Action==-1) { _Alert("Sell"); if (Allow_Trade) { 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) { }