Author: Copyright � 2005, Chris Visser
Price Data Components
Series array that contains open time of each bar
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Commodity channel indexMoving average indicator
0 Views
0 Downloads
0 Favorites
FidgetExp
//+------------------------------------------------------------------+
//|                                                    FidgetExp.mq4 |
//|                                   Copyright © 2005, Chris Visser |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Chris Visser"
#property link      "http://www.metaquotes.net"

/*[[
	Name := FidgetExp
	Author := Copyright © 2004, MetaQuotes Software Corp.
	Link := http://www.metaquotes.net/
	Lots := 1.0
	Stop Loss := 1000
	Take Profit := 1000
	Trailing Stop := 0
]]*/

extern int     mgod = 2006;
extern int     test=0;
extern int     auto=1;
extern int     tper=24;
extern int     cper=14;
extern int     del=20;
extern int     cbars=300;
extern int     depth=15;
extern int     deviation=5;
extern int     backstep=3;
extern int     hsum=-300;
extern int     kh=2;
extern double  Lots = 1;
extern int     TrailingStop = 0;
extern int     StopLoss = 1000;
extern int     MagicNumber = 300;
extern int     TakeProfit = 1000;

bool        ft=true;
int         cnt = 0;
int         x = 0;
double      HMax = 0;
double      LMin = 0;
double      fhzz=0;
double      nhzz=0;
double      zzold=0;
double      mlot=0;
double      s=0;
double      b=0;
double      os=0;
double      ob=0;
double      summa=0;
double      bsum=0;
double      ssum=0;

double      j=0;
double      step=0;
double      ccinul=0;
double      ccione=0;
double      hblok=0;
double      pr=4;
double      MidL=0;
double      pl=0;
double      LastTradeTime = 0;

int         totalorders = 0;

int start()
{

   for (cnt = 0; cnt <= OrdersTotal(); cnt++)
   {
      if (OrderSelect(cnt, SELECT_BY_POS) == true)
      {
         if (OrderMagicNumber() == MagicNumber)
            totalorders++;
      }
   }

   if (mgod != TimeYear(CurTime())) 
      return(0);
   j=j+1;
   if (TimeMinute(CurTime()) == 0) 
      j=0;
   mlot=Lots;
   if (ft == true)
   {
      cnt=0;
      if (Point > 0.0002) 
         pr=2;
      while (fhzz == nhzz)
      {
         cnt=cnt+1;
         fhzz=iCustom(Symbol(), 0, "HistoFractalZZ",cbars,depth,deviation,backstep,0,cnt-1);
         nhzz=iCustom(Symbol(), 0, "HistoFractalZZ",cbars,depth,deviation,backstep,0,cnt); 
         if (fhzz != nhzz)
            zzold=fhzz;
      }
       ft=false;
   }

   if (TimeHour(CurTime()) == 23) 
   {
      Comment("NOW I DECLARE INTERRUPTION PRIOR TO THE BEGINNING ASIATIC SESSION.","\n",
               "IT WILL BEGIN Into 03.00 Moscow time.","\n",
               "TO 02.45 ME MUST BE COMPULSORILY OPENED FROM CHART");
   }

   if (TimeHour(CurTime()) == 23 && TimeMinute(CurTime()) == 1)
      Comment("  ");

//--------------------------------------------------Áëîê èíäèêàòîðîâ--------------------------------------------------

   ccinul=iCCI(Symbol(), 0, cper,PRICE_CLOSE, 0);
   ccione=iCCI(Symbol(), 0, cper,PRICE_CLOSE, 1);
   HMax=iMA(Symbol(), 0, tper, 0, MODE_EMA, PRICE_HIGH, tper);
   LMin=iMA(Symbol(), 0, tper, 0, MODE_EMA, PRICE_LOW, tper);
   MidL=NormalizeDouble(((HMax+LMin)/2),pr);
   fhzz=iCustom(Symbol(), 0, "HistoFractalZZ",cbars,depth,deviation,backstep,0,1);
   nhzz=iCustom(Symbol(), 0, "HistoFractalZZ",cbars,depth,deviation,backstep,0,0); 
   if (zzold < 0)zzold=0;
   if (fhzz != nhzz && fhzz != 0 && nhzz != 0 && zzold != fhzz)
      zzold=fhzz;
   
//----------------------------------------Ïîäñ÷¸ò àêòèâíûõ è ïàññèâíûõ îðäåðîâ----------------------------------------

   s=0;b=0;os=0;ob=0;ssum=0;bsum=0;summa=0;  
   for (cnt = 1; cnt <= OrdersTotal(); cnt++)
   {
      if (OrderSelect(cnt, SELECT_BY_POS) == true && OrderMagicNumber() == MagicNumber)
      {
         if  (OrderType() == OP_SELL && OrderSymbol() == Symbol())
         {
             s = s + 1;
             ssum = ssum + OrderTakeProfit();
         }
         if  (OrderType() == OP_BUY && OrderSymbol() == Symbol())
         {
            b = b + 1; 
            bsum = bsum + OrderTakeProfit();
         }
         if  (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol())
            os = os + 1;
         if  (OrderType() == OP_BUYSTOP && OrderSymbol() == Symbol())
            ob = ob + 1;
      }
   }
   summa=ssum+bsum;
    
   if (CurTime() - LastTradeTime < 20) return(0);

//--------------------------------------------Ìîäèôèêàöèÿ öåíû îðäåðà-----------------------------------------------

   if ( os + ob > 0)
   {
      for (cnt = 1;cnt <= OrdersTotal(); cnt++)
      {
         if (OrderSelect(cnt, SELECT_BY_POS) == true && OrderMagicNumber() == MagicNumber)
         {
            if   (OrderSymbol() == Symbol() && OrderType() == OP_SELLSTOP)
            {
               if ((( Close[0] - OrderOpenPrice()) / Point) > del && ccinul > 200)
               {
                  step=((Close[0]-OrderOpenPrice())/Point)-del;     
                  OrderModify(OrderTicket(), OrderOpenPrice()+step*Point ,OrderStopLoss()+step*Point,OrderTakeProfit()+step*Point,0,Gold);
                  return(0);
               }
            }
            if   (OrderSymbol() == Symbol() && OrderType() == OP_BUYSTOP)
            {
               if (((OrderOpenPrice()-Close[0])/Point) > del && ccinul < -200 )
               {
                  step=((OrderOpenPrice() - Close[0])/Point)-del;
                  OrderModify(OrderTicket(),OrderOpenPrice()-step*Point,OrderStopLoss()-step*Point,OrderTakeProfit()-step*Point,0,Gold);
                  return(0);
               }
            }
         }
      }
   }
                                                                                                  
//------------------------------------------------Òðåéëèíã-Ñòîï-----------------------------------------------------

   if ( TrailingStop > 0 && s+b > 0)
   {

      for (cnt = 1; cnt <= OrdersTotal(); cnt++)
      {
         if (OrderSelect(cnt, SELECT_BY_POS) == true && OrderMagicNumber() == MagicNumber)
         {
            if (OrderSymbol() == Symbol() && OrderTakeProfit() > 0)
            {
  
               if ((Bid-OrderOpenPrice()) > (Point*TrailingStop))
               {
                  if (OrderStopLoss() < (Bid-Point*TrailingStop))
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                  }
               }
      
               if ((OrderOpenPrice() - Ask) > (Point * TrailingStop))
               {
                  if (OrderStopLoss() > (Ask+Point*TrailingStop))
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),Red);
                     return(0);
                  }
               }
            }
         }
      }
   }

//----------------------------------------Õåäæèðîâàíèå óáûòî÷íûõ ïîçèöèé-------------------------------------------

   if  ( s + b == 0)
      hblok=0; 
   if (((s == 0 && b == 1) || (s == 1 && b == 0)) && summa < hsum && ccinul < 200 && ccione > 200 && hblok == 0 && Close[0] > HMax)
   {
      //SetArrow(Time[0],High,242,GreenYellow);
      hblok=1; 
      Comment("Advanced Hedge- warrant on sale on the price: ",Bid,"\n",
             "Established for the trade lead: ",kh*mlot,"\n","Acting in this case volume: ",Volume[0]);  
      for (x = 1; x <= kh; x++)
         OrderSend(Symbol(), OP_SELL, mlot, Bid, 3, Bid+StopLoss*Point, Bid-TakeProfit*Point, NULL, MagicNumber, 0, GreenYellow);
      LastTradeTime = CurTime();
      return(0);
   }

   if (((s == 1 && b == 0) || (s == 0 && b == 1)) && summa < hsum && ccione < -200 && ccinul > -200 && hblok == 0 && Close[0] < LMin)
   {
      //SetArrow(Time[0],Low,241,Red);
      hblok=1; 
      Comment("Advanced Hedge- warrant on sale on the price: ",Ask,"\n",
            "Established for the trade lead: ",kh*mlot,"\n","Acting in this case volume: ",Volume[0]);  
      for (x = 1; x <= kh; x++)
         OrderSend(Symbol(), OP_BUY, mlot, Ask, 3, Ask-StopLoss*Point, Ask+TakeProfit*Point, NULL, MagicNumber, 0, Red);
      LastTradeTime = CurTime();
      return(0);
   }

//------------------------------------------Çàêðûòèå îðäåðîâ ïî ïðîôèòó---------------------------------------------

   if  (s + b == 0)
      pl=0;

   if  (summa > 200)
      pl=1;

   if  (pl == 1)
   {

      for (cnt = 1;cnt <= OrdersTotal(); cnt++)
      {
 
         if (OrderSelect(cnt, SELECT_BY_POS) == true)
         {
            if (OrderType() == OP_SELL && OrderSymbol() == Symbol())
            {
               OrderClose(OrderTicket(),OrderLots(),Ask,5,Red);
               return(0);
            }
 
            if (OrderType() == OP_BUY && OrderSymbol() == Symbol())
            {
               OrderClose(OrderTicket(),OrderLots(),Bid,5,Red);
               return(0);
            }
         }
      }
   }
    
//----------------------------------------------Îòëàäî÷íàÿ èíôîðìàöèÿ-----------------------------------------------

   if (test == 0)
   {
      Comment("Data: ",Month()," ",Day()," ",Hour()," ",Minute(),"   Jind=",j,"  Auto=",auto,"  Vol=",Volume[0],"\n",
        "1CCI=",MathRound(ccione),"  0CCI=",MathRound(ccinul),"  ZZ1=",fhzz,"  ZZ0=",nhzz,"  ZZOld=",zzold,"  Apoz=",s+b,
        "  MidL=",MidL,"  Profit=",MathRound(summa));
   }
   else 
   {
      Print("Data: ",Month()," ",Day()," ",Hour()," ",Minute(),"   Jind=",j,"  Auto=",auto,"  Vol=",Volume[0],
      "  1CCI=",MathRound(ccione),"  0CCI=",MathRound(ccinul),"  ZZ1=",fhzz,"  ZZ0=",nhzz,"  ZZOld=",zzold,"  Apoz=",s+b,
      "  MidL=",MidL,"  Profit=",MathRound(summa));
   }
    
//--------------------------------------------------Áëîê òîðãîâëè----------------------------------------------------

   if (auto == 0 && s + b + os + ob == 0)
   {

      if (Close[0] > HMax && nhzz > Close[0])
      {
         Comment("It is possible to advance foot- warrant on sale on the price: ",MidL,"\n",
           "Established for the trade lead: ",Lots,"\n","Acting in this case volume: ",Volume[0]);
      }
           
      if (Close[0] < LMin && nhzz < Close[0])
      {
         Comment("It is possible to advance foot- warrant on the purchase on the price: ",MidL,"\n",
              "Established for the trade lead: ",Lots,"\n","Acting in this case volume: ",Volume[0]);
      }
   }
           
           
   if (auto == 1 && s + b + os + ob == 0)
   {

      if (Close[0] > HMax && nhzz > Close[0])
      {
         //SetArrow(Time[0],High[0]+5*Point,242,Gold);
         Comment("Advanced foot- warrant on sale on the price: ",Bid-del*Point,"\n",
           "Established for the trade lead: ",Lots,"\n","Acting in this case volume: ",Volume[0]);  
         OrderSend(Symbol(), OP_SELLSTOP, mlot, MidL, 3, MidL+StopLoss*Point, MidL-TakeProfit*Point,NULL, MagicNumber, 0, Gold);
         return(0);
      }
   }
   if (Close[0] < LMin && nhzz < Close[0])
   {
      //SetArrow(Time[0],Low[0]-5*Point,241,Aqua);      
      Comment("Advanced foot- warrant on the purchase on the price: ",Ask+del*Point,"\n",
           "Established for the trade lead: ",Lots,"\n","Acting in this case volume: ",Volume[0]); 
      OrderSend(Symbol(), OP_BUYSTOP, mlot, MidL, 3, MidL-StopLoss*Point, MidL+TakeProfit*Point, NULL, MagicNumber, 0, Aqua);
      return(0);
   }
}
                                                                                                                     
//--------------------------------------------------------End--------------------------------------------------------

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---