Metod_Puria

Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open orders
Indicators Used
Moving average indicatorMACD Histogram
0 Views
0 Downloads
0 Favorites
Metod_Puria
//+------------------------------------------------------------------+
//| strategy method Puria                            Metod_Puria.mq4 |
//|                                                                  |
//| YouTube http://youtu.be/JjnrPl7CGVI                              |
//|         http://youtu.be/6BhXDplcd9k                              |
//+------------------------------------------------------------------+
//| Ñorrected and finalized vicas@robotrading.com.ua         m00002  |
//+------------------------------------------------------------------+
#define MagicNumber  122122
//+------------------------------------------------------------------+
extern string s1                = "Trading options";
extern double Lot               = 0;  // lot calculations 0
extern double StopLoss          = 30; // stoploss
extern double TakeProfit        = 70; // takeprofit
//+------------------------------------------------------------------+
extern string s2                = "Parametr Crossing MA";
extern int    InitOrder         = 0;  // contact-0 crossing=1
//+------------------------------------------------------------------+
int MovingPeriodS1    = 75;
int MovingPeriodS2    = 85;
int maS_metod         = 3; // MODE_LWMA
int maS_price         = 3; // PRICE_LOW
//+------------------------------------------------------------------+
int MovingPeriodLw    = 5;
int maLw_metod        = 1; // MODE_EXT
int maLw_price        = 0; // PRICE_CLOSE
//+------------------------------------------------------------------+
int macd_ima_fast     = 15;
int macd_ima_slow     = 26;
int macd_ima_signal   = 1;
int macd_metod        = 0; // PRICE_CLOSE
//+------------------------------------------------------------------+
bool Order=false, UpZone=true, DnZone=true ;
int timeprev = 0, Slip = 3.0;

//+------------------------------------------------------------------+
//| Init function                                                    |
//+------------------------------------------------------------------+
void OnInit()
{
   if (Digits == 3 || Digits == 5) {                                                    
      TakeProfit *= 10;
      StopLoss *=10;
      Slip *=10;
   } 
   return; 
}
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
{
   if(timeprev == Time[0]){
      CheckClear();
      return;
   }
   timeprev = Time[0];
   if (CountTrades() == 0) CheckForOpen();
}
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
{
   double malw,mas1,mas2,macd;
   int    res;  
   malw=iMA(NULL,0,MovingPeriodLw,0,maLw_metod,maLw_price,1);
   mas1=iMA(NULL,0,MovingPeriodS1,0,maS_metod,maS_price,1);
   mas2=iMA(NULL,0,MovingPeriodS2,0,maS_metod,maS_price,1);
   macd=iMACD(NULL,0,macd_ima_fast,macd_ima_slow,macd_ima_signal,macd_metod,MODE_MAIN,1);

   if(malw>mas1 && malw>mas2  && macd>0 && Order && Ask>malw && DnZone){
      res=OrderSend(Symbol(),OP_BUY,Lots(),Ask,Slip,Bid-StopLoss*Point,Bid+TakeProfit*Point,"",MagicNumber,0,Blue);
      Order=false;
      UpZone=true;
      DnZone=false;
      return;
   }       
   if(malw<mas1 && malw<mas2  && macd<0 && Order && Bid<malw && UpZone){
      res=OrderSend(Symbol(),OP_SELL,Lots(),Bid,Slip,Ask+StopLoss*Point,Ask-TakeProfit*Point,"",MagicNumber,0,Red);
      Order=false;
      UpZone=false;
      DnZone=true;
      return;
   }
 
}  
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double Lots()
{
   double Lots;
   if (Lot > 0) return(Lot);
   Lots=AccountFreeMargin()/9000;
   Lots=MathMin(15,MathMax(0.01,Lots));
   if(Lots<0.1) Lots=NormalizeDouble(Lots,2);
   else {
     if(Lots<1) Lots=NormalizeDouble(Lots,1);
     else       Lots=NormalizeDouble(Lots,0);
   }
   return(Lots);
}
//+------------------------------------------------------------------+
//| Count orders function                                                   |
//+------------------------------------------------------------------+
int CountTrades() 
{
   int count = 0;
   for (int pos = OrdersTotal() - 1; pos >= 0; pos--){
      if (OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)){
         if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
            if (OrderType() == OP_SELL || OrderType() == OP_BUY){
               count++;
               break;
            } 
      }     
   }
   return (count);
} 
//+------------------------------------------------------------------+
//| Order allowed function                                           |
//+------------------------------------------------------------------+
void CheckClear()
{
   double malw,mas1,mas2;
   if (Order) return;
   malw=iMA(NULL,0,MovingPeriodLw,0,maLw_metod,maLw_price,0);
   mas1=iMA(NULL,0,MovingPeriodS1,0,maS_metod,maS_price,0);
   mas2=iMA(NULL,0,MovingPeriodS2,0,maS_metod,maS_price,0);
   if ((malw<=mas1 && malw>=mas2) || (malw>=mas1 && malw<=mas2)) Order=true;
   if (InitOrder == 0) {
      UpZone=true;
      DnZone=true;   
   }   
   return;
}
 
  
 

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