FORTRADER_RU_RSIOMA_EA

Author: Copyright � 2010, FORTRADER.RU. ���������� �� �������
Orders Execution
It Closes Orders by itself Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
0 Views
0 Downloads
0 Favorites
FORTRADER_RU_RSIOMA_EA
//+------------------------------------------------------------------+
//| FT_RSIOMA_EA.mq4.mq4
//| Copyright © 2010, FORTRADER.RU. Îòêëîíåíèå îò ñðåäíåé
//| http://www.fortrader.ru Èññëåäîâàíèå äëÿ 64 âûïóñêà æóðíàëà FORTRADER.RU
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, FORTRADER.RU. Îòêëîíåíèå îò ñðåäíåé"
#property link      "http://www.fortrader.ru Èññëåäîâàíèå äëÿ 64 âûïóñêà æóðíàëà FORTRADER.RU"

extern string i = "Íàñòðîéêè èíäèêàòîðà";
extern int RSIOMA          = 14;
extern int RSIOMA_MODE     = MODE_EMA;
extern int RSIOMA_PRICE    = PRICE_CLOSE;

extern int Ma_RSIOMA       = 21,
           Ma_RSIOMA_MODE  = MODE_EMA;

extern int BuyTrigger      = 80;
extern int SellTrigger     = 20;

extern color BuyTriggerColor  = DodgerBlue;
extern color SellTriggerColor = Magenta;

extern int MainTrendLong   = 50;
extern int MainTrendShort  = 50;

extern color MainTrendLongColor     = Red;
extern color MainTrendShortColor    = Green;

extern int      EA_Magic=12354;  
extern double InpLots      =0.1; 
extern int    InpTakeProfit=0;  
extern int    InpStopLoss  =0;  

int start()
  {int err;
  
   double STP = InpTakeProfit;
   double TKP = InpStopLoss;
   if(Digits==5 || Digits==3)
     {
      STP = STP*10;
      TKP = TKP*10;
     }
  //çàïóñêàåì òðåéëèíã ñòîï
  err=TrailingStop();
  //ñìîòðèì íå áûëî ëè îøèáîê
  if(err<0){Print("TrailingStop()-  Îøèáêà òðåéëèíãà. "+GetLastError());return(0);}
  
double RSIOMA_1=iCustom(NULL, 0, "RSIOMA_v2",RSIOMA,RSIOMA_MODE,RSIOMA_PRICE,Ma_RSIOMA,Ma_RSIOMA_MODE,BuyTrigger,SellTrigger,BuyTriggerColor,SellTriggerColor,MainTrendLong,MainTrendShort,MainTrendLongColor,MainTrendShortColor,0,1);
double RSIOMA_2=iCustom(NULL, 0, "RSIOMA_v2",RSIOMA,RSIOMA_MODE,RSIOMA_PRICE,Ma_RSIOMA,Ma_RSIOMA_MODE,BuyTrigger,SellTrigger,BuyTriggerColor,SellTriggerColor,MainTrendLong,MainTrendShort,MainTrendLongColor,MainTrendShortColor,5,1);
double RSIOMA_1L=iCustom(NULL, 0, "RSIOMA_v2",RSIOMA,RSIOMA_MODE,RSIOMA_PRICE,Ma_RSIOMA,Ma_RSIOMA_MODE,BuyTrigger,SellTrigger,BuyTriggerColor,SellTriggerColor,MainTrendLong,MainTrendShort,MainTrendLongColor,MainTrendShortColor,0,2);
double RSIOMA_2L=iCustom(NULL, 0, "RSIOMA_v2",RSIOMA,RSIOMA_MODE,RSIOMA_PRICE,Ma_RSIOMA,Ma_RSIOMA_MODE,BuyTrigger,SellTrigger,BuyTriggerColor,SellTriggerColor,MainTrendLong,MainTrendShort,MainTrendLongColor,MainTrendShortColor,5,2);




if(RSIOMA_1<RSIOMA_2 && RSIOMA_1L>RSIOMA_2L && !ChPos(1)){OpenOrderOnMarket(1,TKP,STP);}
if(RSIOMA_1>RSIOMA_2 && RSIOMA_1L<RSIOMA_2L && !ChPos(0)){OpenOrderOnMarket(0,TKP,STP);}

if(RSIOMA_1>RSIOMA_2 && ChPos(1)){_OrderClose(0);}
if(RSIOMA_1<RSIOMA_2 && ChPos(0)){_OrderClose(1);}

//Print(RSIOMA_1+" "+RSIOMA_2);
   return(0);
  }

 //ïðîâåðÿåò åñòü ëè îòêðûòûå îðäåðà
int ChPos(int type) 
{//ïîäðîáíîå îïèñàíèå: http://fxnow.ru/blog.php?user=Yuriy&blogentry_id=100

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

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),"56 FORTRADER.RU",EA_Magic,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),"56 FORTRADER.RU",EA_Magic,0,Red);
    if(err<0){Print("OrderSend()-  Îøèáêà OP_SELL.  op "+op+" sl "+sl+" tp "+tp+" "+GetLastError());return(-1);}
   }
return(0);
}

//Çàêðûâàåò ïîçèöþ ïî òèïó
int _OrderClose(int type)
   {//http://fxnow.ru/blog.php?user=Yuriy&blogentry_id=99
   
   int err;
   for(int i=1; i<=OrdersTotal(); i++)          
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) 
        {
         if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && type==1 && OrderMagicNumber()==EA_Magic)
         {
          err=OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); 
          if(err<0){Print("OrderClose()-  Îøèáêà çàêðûòèÿ OP_BUY.  OrderTicket "+OrderTicket()+" OrderLots() "+OrderLots()+" Bid "+Bid+" "+GetLastError());return(-1);}
         }
         if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && type==0 && OrderMagicNumber()==EA_Magic)
         {
          err=OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); 
          if(err<0){Print("OrderClose()-  Îøèáêà çàêðûòèÿ OP_SELL.  OrderTicket "+OrderTicket()+" OrderLots() "+OrderLots()+" Ask "+Ask+" "+GetLastError());return(-1);}
         }
        }
       }
   return(0);
   }

extern int TrailingStop=20;
extern int TrailingStep=5;

int  TrailingStop()
{int i;bool err;int mn=1;

if(Digits==5 || Digits==3)
     {
      mn = 10;
     }
     
   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() || OrderStopLoss()==0))
          {
           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) || OrderStopLoss()==0))
          {
           if((OrderStopLoss()-(Ask+TrailingStop*Point*mn))>TrailingStep*Point*mn || OrderStopLoss()==0)
           {
            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);
}

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