a_MA_vs_Fractal

Author: Copyright � 2010, dmmikl86
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
Indicators Used
Moving average indicatorFractals
0 Views
0 Downloads
0 Favorites
a_MA_vs_Fractal
//+------------------------------------------------------------------+
//|                                             a_MA_vs_Fractal1.mq4 |
//|                                       Copyright © 2010, dmmikl86 |
//|                                                   mhs_86@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, dmmikl86"
#property link      "mhs_86@mail.ru"

extern int Fast_MA=12;
extern int Slow_MA=26;
extern int offset=2;
extern double lots=0.1;
extern double kr = 6; //êðàòíîñòü  - îòíîøåíèå ïðèûáëè ê óáûòêó.
int magic=68351;
double ma_fast, ma_slow, FrUp, FrDw, SL_b, SL_s, TP_b, TP_s;
int spread;
datetime new_time;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   spread   =MarketInfo(Symbol(), MODE_SPREAD);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
if(new_time!=Time[0])
{
//----
   // îïðåäåëåíèå ìóâèíãîâ -------------------------------------------
   ma_fast = NormalizeDouble(iMA(Symbol(), 0, Fast_MA, 0, MODE_EMA, PRICE_CLOSE, 1), Digits);
   ma_slow = NormalizeDouble(iMA(Symbol(), 0, Slow_MA, 0, MODE_EMA, PRICE_CLOSE, 1), Digits);
   //Comment("fast_ma=", ma_fast, " slow_ma=", ma_slow);
   //-----------------------------------------------------------------
   // îïðåäåëåíèå ôðàêòàëîâ ------------------------------------------
   FrUp=NormalizeDouble(iFractals(Symbol(), 0, MODE_UPPER, 2), Digits);
   FrDw=NormalizeDouble(iFractals(Symbol(), 0, MODE_LOWER, 2), Digits);
   //Comment ("FrUp=", FrUp, " FrDw=", FrDw);
   //-----------------------------------------------------------------
 
      // îòêðûòèå BUY--------------------------------------------------
      if (ma_fast > ma_slow)
         {
          //Comment ("trend UP");
          if (FrDw != 0)
            {
             //Comment("open BUY");
             SL_b = FrDw-(offset*Point);
             OrderSend(Symbol(), OP_BUY, lots, NormalizeDouble(Ask, Digits), 3, SL_b, 0, "ma_vs_fractal BUY", magic, 0, Blue);
            }
         }
      //---------------------------------------------------------------
      // îòêðûòèå SELL ------------------------------------------------
      if (ma_fast < ma_slow)
         {
          //Comment("trend DOWN");
          if (FrUp != 0)
            {
             //Comment("open SELL");
             SL_s = FrUp+((offset+spread)*Point);
             OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 3, SL_s, 0, "ma_vs_fractal SELL", magic, 0, Red);
            }
         }
      //---------------------------------------------------------------
   //------------------------------------------------------------------
   new_time=Time[0];
}
   // óñòàíàâëèâàåì òåéê ïðîôèò ---------------------------------------
      int order_type, order_magic;
      int b_orders, s_orders; 
      
      for (int i=1; i<=OrdersTotal(); i++)                    //Öèêë ïî âñåì îðäåðàì,..     
         {                                                  //îòðàæ¸ííûì â òåðìèíàëå      
          if(OrderSelect(i-1,SELECT_BY_POS)==true)           //Åñëè åñòü ñëåäóþùèé        
            {                                               // Çäåñü äîëæåí âûïîëíÿòüñÿ àíàëèç õàðàêòåðèñòèê îðäåðîâ   
             //--------------------
             order_type=OrderType();
             order_magic=OrderMagicNumber();
             // ìîäèôèöèðóåì îðäåð áàé----------------------------------------
             if(order_type==OP_BUY && order_magic==magic && OrderTakeProfit()==0)             // âûáðàí îðäåð buy 
                {
                 TP_b = OrderOpenPrice()+(OrderOpenPrice()-OrderStopLoss())*kr;
                 OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(),TP_b, 0, CLR_NONE);
                 //Comment("TP_b = ", TP_b);
                } 
             //---------------------------------------------------------------   
             // ìîäèôèöèðóåì îðäå ñåëë ---------------------------------------
             if(order_type==OP_SELL && order_magic==magic && OrderTakeProfit()==0)             // âûáðàí îðäåð sell 
                {
                 TP_s = OrderOpenPrice()- (OrderStopLoss()-OrderOpenPrice())*kr;
                 OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), TP_s, 0, CLR_NONE);
                 //Comment("TP_s = ", TP_s);
                }
             //---------------------------------------------------------------   
            //--------------------
             }     
         }
   //------------------------------------------------------------------
//----

   return(0);
  }
//+------------------------------------------------------------------+


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 ---