Navigation:Home > Content >

Tica_(e2).mq4

Time: 2010-05-06 | Download file:Tica_(e2).mq4

#property copyright "eevviill" 
#property link "itisallillusion@gmail.com"


extern string os = "Настройки лота и стопов";
extern double Lot = 0.1;
extern bool use_percent_of_deposit = false;
extern double Risk = 1;
extern int StopLoss = 50;
extern int TakeProfit = 50;

extern string pus1 = "";
extern string V_S_T = "Virtual_SL_TP";
extern bool use_Virtual_Stops = true;
extern int v_StopLoss = 50;
extern int v_TakeProfit = 50;

extern string pus2 = "";
extern string slug = "Дополнительные настройки";
extern int Candle_size = 8;
extern bool use_transform_4_dig = false; //перевод на 4-знак
extern bool use_revers = false; //открывать вместо бай-сел и наоборот
extern bool use_oposite_exit = false; //использовать выход по обратному сигналу
extern bool use_custom_exit = false; //использовать собственное условие для выхода
extern int slippage = 2; //проскальзывание
extern int magic = 433144; //номер присваиваемый для ордера
extern string comment = "Tica"; //коментарий к ордеру
extern int MaxAttempts = 4; //макс количество попыток открыть или закрыть ордер
extern double pause_if_busy = 0.3; //количество секунд паузы перед повторной попыткой модифицировать, закрыть или открыть ордер если торговый поток занят

extern string pus3 = "";
extern string V_R = "Время работы";
extern bool use_work_time = false;
extern int Start = 0;
extern int Stop = 24;

extern string pus4 = "";
extern string ind1 = "RSI";
extern int RSI_period = 14;
extern int open_level = 30; //30=70
extern int close_level = 20; //30=70

extern string pus5 = "";
extern string tre_st = "Трейлинг стоп";
extern bool use_traling_stop = false;
extern int TrailingStart =0;
extern int TrailingStop = 20;
extern int TrailingStep =10;


      
int buy,sell,Orders_Total,Sig_p,Sig_ex,Sig_rev1,Sig_ex_rev1,Sig_rev2,Sig_ex_rev2;

double point;
int dig_koef;


//////////////////////////////////////////////////////////////
int init()
{  
point=Point;
dig_koef=1;
if(use_transform_4_dig && (Digits==3 || Digits==5))
{point*=10;dig_koef=10;}





return;
}




////////////////////////////////////////////////////////////
int start()
{
//трейлинг стоп 
 if(use_traling_stop) Traling_Stop_f();

 //SL && TP 
 if(StopLoss!=0 || TakeProfit!=0)
 {
 SL_TP(); 
 }
 
 //виртуальные стопы
 if(use_Virtual_Stops) Virtual_stops_chek();
 
 //расчёт лота от % депозита
 if(use_percent_of_deposit) Lot=GetLot();
 

   
 //Сигнал на вход
 Sig_p =Sig_f();
 
 //Сигнал на выход
 if(use_custom_exit) 
 Sig_ex = Sig_ex_f();
 
 
 //реверс
 rev();
 
 
 //Выход
 if(Sig_p!=0 || Sig_ex!=0) close();

//фильтр время
 if(use_work_time)
 {
  if(Start>Stop)
 {
 if(Hour()>=Stop && Hour()=Stop) return;
 }
 }

 //Вход
 if(Sig_p!=0) open();
 
 


   return(0);
  }






//расчёт функций
/////////////////////////////////////////////////////////////////////////////////////////////
int Sig_f()
{
//объявление индикаторов
double ind1 = iRSI(Symbol(),0,RSI_period,PRICE_CLOSE,0);
double ind11 = iRSI(Symbol(),0,RSI_period,PRICE_CLOSE,1);







//////////////////////////
//сигнал для бай
if(ind11<=open_level && ind1>open_level && Close[0]-Open[0]>=Candle_size*Point) 
return(1);



//сел
if(ind11>=100-open_level && ind1<100-open_level && Open[0]-Close[0]>=Candle_size*Point) 
return(-1);


return(0);
}

/////////////////////////////////////////////////////////////////////////////////////////////
int Sig_ex_f()
{
//объявление индикаторов
double ind1 = iRSI(Symbol(),0,RSI_period,PRICE_CLOSE,0);




//сигнал для выход бай
if(ind1>=100-close_level) return(1);

//сигнал для выход сел
if(ind1<=close_level)  return(-1);


return(0);
}

///////////////////////////////////////////////////////////////////////////////////////////////
void open()
{
 //подсчёт открытых позиций
 CountOpenPositions();

  
 int ticket_op=-1;
 for (int j_op = 0; j_op < MaxAttempts; j_op++)
 {
 while(IsTradeContextBusy()) Sleep(pause_if_busy*1000);
                             
 if(Sig_rev1>0 && buy==0 && sell==0)  ticket_op=OrderSend(Symbol(),OP_BUY,Lot,Ask,slippage,0,0,comment,magic,0,Green);
 if(Sig_rev2<0 && sell==0 && buy==0) ticket_op=OrderSend(Symbol(),OP_SELL,Lot,Bid,slippage,0,0,comment,magic,0,OrangeRed);
 if(ticket_op>-1)break;
 }
 
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 void close()
 {
  //Выход
 for(int i=OrdersTotal()-1; i>=0; i--)
 {
 OrderSelect(i,SELECT_BY_POS);
 {
 if(OrderMagicNumber()==magic)
 {
 if(OrderSymbol()==Symbol())
 {
 bool ticket_ex=false;
 for (int j_ex = 0;j_ex < MaxAttempts; j_ex++)
 {
 while(IsTradeContextBusy()) Sleep(pause_if_busy*1000);
 
 if(OrderType()==OP_BUY && ((use_oposite_exit && Sig_rev2<0) || (use_custom_exit && Sig_ex_rev1>0))) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Yellow); 
 if(OrderType()==OP_SELL && ((use_oposite_exit && Sig_rev1>0) ||(use_custom_exit && Sig_ex_rev2<0))) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Yellow);
 if(ticket_ex==true)break;
 }
 }
 }
 }   
 }
 
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double GetLot()
{
 double Free    =AccountFreeMargin();
 double One_Lot =MarketInfo(Symbol(),MODE_MARGINREQUIRED);
 double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT);
 double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT);
 double Step    =MarketInfo(Symbol(),MODE_LOTSTEP);
 double Lot     =MathFloor(Free*Risk/100/One_Lot/Step)*Step;
 if(LotMax_Lot) Lot=Max_Lot;
 if(Lot*One_Lot>Free) return(0.0);
 
return(Lot);
}

////////////////////////////////////////////////////////////////////////////////////
void CountOpenPositions()
{
buy=0;
sell=0;
Orders_Total=0;

for (int i=OrdersTotal()-1; i>=0; i--)
 {
   OrderSelect(i,SELECT_BY_POS);
   {
   if(OrderMagicNumber()==magic)
   { 
   if(OrderSymbol()==Symbol())
   {        
   if(OrderType()==OP_BUY)      buy++;
   if(OrderType()==OP_SELL)     sell++; 
   } 
   }             
   }
 }

Orders_Total=buy+sell;
}

///////////////////////////////////////////////////////////////////////////
void SL_TP()
{

if(StopLoss!=0)
{
if(StopLoss=0; i--)
 {
   if(OrderSelect(i,SELECT_BY_POS))
   {
   if(OrderMagicNumber()==magic)
   {
   if(OrderSymbol()==Symbol())
   {    
   
   /////////////////////////////////////////////////
   if(OrderType()==OP_BUY || OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)
   {     
   //OrderSelect(i,SELECT_BY_POS);
   if(StopLoss>0 && OrderStopLoss()==0)
   { 
   while(IsTradeContextBusy()) Sleep(pause_if_busy*1000);
   OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-StopLoss*point,Digits),OrderTakeProfit(),0,CLR_NONE); 
   }
   OrderSelect(i,SELECT_BY_POS);
   if(TakeProfit>0 && OrderTakeProfit()==0) 
   {
   while(IsTradeContextBusy()) Sleep(pause_if_busy*1000);
   OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()+TakeProfit*point,Digits),0,CLR_NONE);
   }
   }
   
   /////////////////////////
   if(OrderType()==OP_SELL || OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT)
   {   
   //OrderSelect(i,SELECT_BY_POS);
   if(StopLoss>0 && OrderStopLoss()==0) 
   {
   while(IsTradeContextBusy()) Sleep(pause_if_busy*1000);
   OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+StopLoss*point,Digits),OrderTakeProfit(),0,CLR_NONE);   
   } 
   OrderSelect(i,SELECT_BY_POS);
   if(TakeProfit>0 && OrderTakeProfit()==0) 
   {
   while(IsTradeContextBusy()) Sleep(pause_if_busy*1000);
   OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()-TakeProfit*point,Digits),0,CLR_NONE);   
   } 
   }
   
   //////////////////////////////////////////////// 
   } 
   }
   }
 }
 
 
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Virtual_stops_chek()
{
for(int i=OrdersTotal()-1; i>=0; i--)
 {
 OrderSelect(i,SELECT_BY_POS);
 {
 if(OrderMagicNumber()==magic)
 {
 if(OrderSymbol()==Symbol())
 {
 bool ticket_ex=false;
 for (int j_ex = 0;j_ex < MaxAttempts; j_ex++)
 {
 while(IsTradeContextBusy()) Sleep(pause_if_busy*1000);
 
 
 if(OrderType()==OP_BUY && (Bid>=OrderOpenPrice()+v_TakeProfit*point || Bid<=OrderOpenPrice()-v_StopLoss*point)) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Yellow);  
 if(OrderType()==OP_SELL && (Ask<=OrderOpenPrice()-v_TakeProfit*point || Ask>=OrderOpenPrice()+v_StopLoss*point)) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Yellow);
 if(ticket_ex==true)break;
 }
 }
 }
 }
 }




}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
void rev()
 {
 Sig_rev1=0;
 Sig_rev2=0;
 Sig_ex_rev1=0;
 Sig_ex_rev2=0;

 
 if(!use_revers)
 {
 if(Sig_p==1) {Sig_rev1=1;Sig_rev2=0;}
 if(Sig_p==-1) {Sig_rev2=-1;Sig_rev1=0;}
 if(Sig_ex==1) {Sig_ex_rev1=1;Sig_ex_rev2=0;}
 if(Sig_ex==-1) {Sig_ex_rev2=-1;Sig_ex_rev1=0;}
 }
 
 if(use_revers)
 {
 if(Sig_p==1) {Sig_rev2=-1;Sig_rev1=0;}
 if(Sig_p==-1) {Sig_rev1=1;Sig_rev2=0;}
 if(Sig_ex==1) {Sig_ex_rev2=-1;Sig_ex_rev1=0;}
 if(Sig_ex==-1) {Sig_ex_rev1=1;Sig_ex_rev2=0;}
 }
 
 }
 
 ///////////////////////////////////////////////////////////////////////////
void Traling_Stop_f()
{
  for(int i=0; iNormalizeDouble(TrailingStop*point,Digits) && Bid>=NormalizeDouble(OrderOpenPrice()+TrailingStart*point,Digits)) { 
        if(OrderStopLoss()NormalizeDouble(TrailingStop*point,Digits) && Ask<=NormalizeDouble(OrderOpenPrice()-TrailingStart*point,Digits)) { 
        if((OrderStopLoss()>NormalizeDouble(Ask+(TrailingStop+TrailingStep-1)*point,Digits)) || OrderStopLoss()==0) 
          OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits), OrderTakeProfit(), 0, CLR_NONE); 
      }
    } 
  } 
  
}

Recommend