Author: Copyright 2012, FORTRADER.RU
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 reached
Indicators Used
Parabolic Stop and Reverse systemCommodity channel indexMoving average indicator
0 Views
0 Downloads
0 Favorites
PCSTrader
//+------------------------------------------------------------------+
//|                                              PCSTrader.mq4
//| Copyright 2012, FORTRADER.RU, ftyuriy: http://forexsystems.ru/member.php?u=4
//|                                              http://fortrader.ru 
//+------------------------------------------------------------------+
// Âíèìàíèå! Ñîâåòíèê íå ïðåäíàçíà÷åí äëÿ ðåàëüíîé àâòîìàòè÷åñêîé òîðãîâëè! Ðàçðàáîòàí äëÿ 70 âûïóñêà æóðíàëà FORTRADER.RU. 
// http://fortrader.ru/journal/scripts/ftgate.php?num=70&siteId=3&uid=20

#property copyright "Copyright 2012, FORTRADER.RU"
#property link      "http://fortrader.ru"

extern double sma_period=21;
extern double cci_period=45;
extern double cci_level=100;
extern double parabolic_step=0.02;
extern double parabolic_max=0.2;

extern int    MG=12354;  
extern double InpLots      =0.1; 
extern int    InpTakeProfit=7;  
//extern int    InpStopLoss  =0;  
extern int mn=10;

extern int shift=1; //äëÿ òåñòà ïî çàêðûòèþ, äîëæíî áûòü =1, ïî òèêàì ìîæíî ïðîáîâàòü =0;

int bars,sellok,buyok;
int start()
  {
   double cci_level_up=cci_level;
   double cci_level_dw=-cci_level;
      if(bars<Bars)
      {
          bars=Bars;
          double parabolic= iSAR(NULL,0,parabolic_step,parabolic_max,shift);
          double cci= iCCI(NULL,0,cci_period,PRICE_TYPICAL,shift);
          double sma= iMA(NULL,0,sma_period,0,MODE_SMA,PRICE_CLOSE,shift);
   
          if(cci<cci_level_up){buyok=0;}
          if(parabolic>sma && cci>cci_level_up && ChPos(0)==0 && buyok==0){
            buyok=1;
            OpenOrderOnMarket(0,0,InpTakeProfit*mn);
          }
          
          if(cci>cci_level_dw){sellok=0;}
          if(parabolic<sma && cci<cci_level_dw && ChPos(1)==0 && sellok==0){
            sellok=1;
            OpenOrderOnMarket(1,0,InpTakeProfit*mn);
          }
          
          TrailingStopMA(sma);
          TrailingStop();
      }
   
   return(0);
  }
  
extern int TrailingStop=7;
extern int TrailingStep=1;


int  TrailingStop()
{int i;bool err;

   for( i=1; i<=OrdersTotal(); i++)        
   {
      if(OrderSelect(i-1,SELECT_BY_POS)==true)
       {  
        if(TrailingStop>0 && OrderType()==OP_BUY && OrderSymbol()==Symbol())  
        {                
         if(Bid-OrderOpenPrice()>=TrailingStop*Point*mn && TrailingStop>0 && (Bid-Point*TrailingStop*mn)>OrderStopLoss())
          {
           if(((Bid-Point*TrailingStop*mn)-OrderStopLoss())>=TrailingStep*Point*mn)
           {
            Print("ÒÐÅÉËÈÌ");
            err=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop*mn,OrderTakeProfit(),0,Green);
            if(err==false){return(-1);}
            GlobalVariableSet(DoubleToStr(OrderTicket(),0),Bid);
           }//if(Bid>=OrderStopLoss()
          }//if(Bid-OrderOpenPrice()
         }//if(BBUSize>0
        }//if(OrderSelect(i
           
       if(OrderSelect(i-1,SELECT_BY_POS)==true)
       {
        if(OrderType()==OP_SELL && OrderSymbol()==Symbol() )  
        {        
         if(OrderOpenPrice()-Ask>=TrailingStop*Point*mn && TrailingStop>0 && OrderStopLoss()>(Ask+TrailingStop*Point*mn))
          {
           if((OrderStopLoss()-(Ask+TrailingStop*Point*mn))>TrailingStep*Point*mn)
           {
            Print("ÒÐÅÉËÈÌ");
            err=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point*mn,OrderTakeProfit(),0,Green);
            if(err==false){return(-1);}
           }//if(Ask<=OrderStopLoss()
          }//if(OrderOpenPrice()
         }//if(BBUSize>0 
       }// if(OrderSelect
    }// for( i=1;
return(0);
}

int  TrailingStopMA(double ma)
{int i;bool err;

   for( i=1; i<=OrdersTotal(); i++)        
   {
      if(OrderSelect(i-1,SELECT_BY_POS)==true)
       {  
        if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==MG)  
        {                
            Print("ÒÐÅÉËÈÌ");
            err=OrderModify(OrderTicket(),OrderOpenPrice(),ma,OrderTakeProfit(),0,Green);
            if(err==false){return(-1);}
         }
        }//if(OrderSelect(i
           
       if(OrderSelect(i-1,SELECT_BY_POS)==true)
       {
        if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MG)  
        {        
            Print("ÒÐÅÉËÈÌ");
            err=OrderModify(OrderTicket(),OrderOpenPrice(),ma,OrderTakeProfit(),0,Green);
            if(err==false){return(-1);}
         }
       }// if(OrderSelect
    }// for( i=1;
return(0);
}


int OpenOrderOnMarket(int type,int slpips,int tppips)
{double op,sl,tp;int err;
   
   if(type==0)
   {
   op=Ask;if(slpips>0){sl=op-slpips*Point;}if(tppips>0){tp=op+tppips*Point;}
   err=OrderSend(Symbol(),OP_BUY,InpLots,NormalizeDouble(op,Digits),3,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),"FORTRADER.RU",MG,0,Red);
   if(err<0){Print("OrderSend()-  Îøèáêà OP_BUY.  op "+op+" sl "+sl+" tp "+tp+" "+GetLastError());return(-1);}
   }
   
   if(type==1)
   {
    op=Bid;if(slpips>0){sl=op+slpips*Point;}if(tppips>0){tp=op-tppips*Point;}
    err=OrderSend(Symbol(),OP_SELL,InpLots,NormalizeDouble(op,Digits),3,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),"FORTRADER.RU",MG,0,Red);
    if(err<0){Print("OrderSend()-  Îøèáêà OP_SELL.  op "+op+" sl "+sl+" tp "+tp+" "+GetLastError());return(-1);}
   }
return(0);
}

//ïðîâåðÿåò åñòü ëè îòêðûòûå îðäåðà
int ChPos(int type) 
{

   int i;int col;
   for( i=1; i<=OrdersTotal(); i++)         
   {
      if(OrderSelect(i-1,SELECT_BY_POS)==true) 
       {                                   
           if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && type==0&& OrderMagicNumber()==MG){col=1;}
           if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && type==1&& OrderMagicNumber()==MG){col=1;}
       }
    }   
return(col);
}

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