Navigation:Home > Content >

StochCCIV2.mq4

Time: 2015-06-12 | Download file:StochCCIV2.mq4

//+------------------------------------------------------------------+
//|                                           ТРАЛОМАРТИН v 1.00.mq4 |
//|                                                         Cemen4yk |
//|                                          https://vk.com/cemen4yk |
//+------------------------------------------------------------------+
#property copyright "Cemen4yk"
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict

//--- indicator parameters

extern double lotsize      = 0;    // автолот всегда
extern int    lot          = 5;    // множитель автолота
extern int    Magik        = 1234; // магик
extern int    slippage     = 9;    // проскальзывание цены
extern double per3         = 0.01; // % процент прибыли серии
extern double per4         = 0.0;  // % процент прибыли для трала
extern double  Step        = 4.0;  // множитель усреднения
extern int    Step2        = 20;   // шаг усреднения
extern  int   TrailingStop = 50;   // безумный трал
extern  int   TralStep     = 1;    // трал шаг
int    ticket, Otype, CountOT;

int  Mas_Tip[6];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  if(Digits == 3 || Digits == 5)
         {
          slippage     *= 10;
          Step2        *= 10;
          TrailingStop *= 10;
          TralStep     *= 10;
         }  
Terminal();           

return(INIT_SUCCEEDED); 
}
void OnTick()    
{
Terminal();
lotsize =(NormalizeDouble((AccountBalance()/250000)*lot,2));

if ((iCCI(Symbol(),0,12,PRICE_TYPICAL,0)<-50)&&(iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)50)&&(iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0)))
{

        if (Mas_Tip[0]==0)
        {
         ticket = OrderSend(Symbol(), OP_BUY, lotsize*(1+Step*CountOT), Ask, slippage, 0, 0 ,"", Magik, 0 ,clrGreen);
        }
}
Otype = findlasttype();
if (Otype ==(OP_SELL)&&((iCCI(Symbol(),0,12,PRICE_TYPICAL,0)<-50)&&(iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)= (findlastprise(OP_SELL)+Step2*Point))
{
ticket = OrderSend(Symbol(), OP_SELL, lotsize*(Step*CountOT), Ask, slippage, 0, 0 ,"", Magik, 0 ,clrGreen);
}
Otype = findlasttype();
if (Otype ==(OP_BUY)&&((iCCI(Symbol(),0,12,PRICE_TYPICAL,0)>50)&&(iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0))))
if (Ask <= (findlastprise(OP_BUY)-Step2*Point))
{
ticket = OrderSend(Symbol(), OP_BUY, lotsize*(Step*CountOT), Bid, slippage, 0, 0 ,"", Magik, 0 ,clrRed);
}
 if ((Mas_Tip[0]>=1)||(Mas_Tip[1]>=1))
Tral();


if (AccountEquity() > (AccountBalance()*(1+per3)))
{
if (((Mas_Tip[0])>=1)&&((Mas_Tip[1]>=1)))
Close_Delete();
}
if (AccountEquity() > (AccountBalance()*(1+per3)))
{
if (((Mas_Tip[0])==1)&&((Mas_Tip[1]==1)))
Close_Delete();
}
}
//---------------------------------------------------------------
int Terminal()
{
CountOT=0;        
   ArrayInitialize(Mas_Tip, 0);
   for(int i=0; i= 0 ; i--)
   {
     if(OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == _Symbol && OrderMagicNumber() == Magik)
     {
      if((OrderType() == OP_BUY)||(OrderType() == OP_SELL))
       res = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage);
      if((OrderType() == OP_BUYSTOP)||(OrderType() == OP_SELLSTOP))
       res = OrderDelete(OrderTicket());
     }
   }
}
//+----------------поиск последней цены ордера----------------------------------------+
double findlastprise(int otype)
{
int oldticket;
double oldopenprise;
ticket = 0;
for (int i = OrdersTotal()-1; i>=0; i--)
      {
       if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
          if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magik && OrderType() == otype)
               oldticket = OrderTicket();
                 if (oldticket > ticket)
                   oldopenprise = OrderOpenPrice();
                   ticket = oldticket;
        }    
      }
      return(oldopenprise);
}
//+----------------траление ордеров-----------------------------------------------+
void Tral()
{
  for (int i = OrdersTotal()-1; i>=0; i--)
      {
       if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if (TrailingStop != 0) {
            if (OrderType() == OP_BUY && Bid > MathMax(OrderOpenPrice(), OrderStopLoss()) + (TrailingStop + TralStep) * Point) {
               if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * Point, 0, 0)){
               }
            }
            
         if (TrailingStop != 0) {   
            if (OrderType() == OP_SELL  && ((Ask < MathMin(OrderOpenPrice(), OrderStopLoss()) - (TrailingStop + TralStep) * Point && OrderStopLoss() != 0.0) || (Ask < OrderOpenPrice() - (TrailingStop +
               TralStep) * Point && OrderStopLoss() == 0.0))) {
               if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop * Point, 0, 0)){
               }
            }
            }
            }
}
} 
}             
//+----------------поиск последнего типа ордера--------------------------------------+
int findlasttype()
{
for (int i = OrdersTotal()-1; i>=0; i--)
      {
       if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
          if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magik)
               return(OrderType());
        }    
      }
      return(-1);
}

Recommend