Author: Copyright � 2010, Magellantech Software Corp.
Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicatorRelative strength index
Miscellaneous
Uses files from the file systemIt reads information from a fileIt issuies visual alerts to the screenIt writes information to file
0 Views
0 Downloads
0 Favorites
TSS1_82
//+------------------------------------------------------------------+
//|                                                         TSS1.mq4 |
//|                    Copyright © 2010, Magellantech Software Corp. |
//|                                             http://www.tss.do.am |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Magellantech Software Corp."
#property link      "http://www.tss.do.am"

//---- input parameters



extern int       Fast_MA=14;
extern int       Middle_MA=21;
extern int       Slow_MA=35;
extern int       rsi_period=22;

extern string    note="äëÿ 5õ çíàêîâ, âñå çíà÷åíèÿ *10";
extern int       offset=3;


extern double    delta=0.0001;


extern int       SellSignalLevel=70;//was 90
extern int       BuySignalLevel=70;//was 90

extern double    lots=2;
extern int       TP=260;// was 270
extern int       SL=200;// was 200
extern int RiskLevel = 41;// was 100


datetime SigLastTime=0;
int magic = 26022010;
datetime new_time;

string File_Name="tse.dat";  

 int Buy_ticket;
 int Sell_ticket;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   FileDelete(File_Name);
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int SellTickArr[];
int BuyTickArr[];


 
void MyOrderModify()
{
 
  for(int i=0;i<OrdersTotal();i++)
     {
     
       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) 
       break;
       
        if(OrderSymbol()==Symbol())
        {
        
           if(OrderType()==OP_SELL)
           {
                //Alert("||||||||||||||||||||||||||||||||||||||||||||||||||||Íàøåë îòêðûòûå äëÿ ìîäèôèêàöèè");
                
                double OP = OrderOpenPrice();
                OP=OP-(SL*Point);
                
                //Comment("   ",OP,"    ",Close[0],"   OP>Close[0]");
                
                //Alert(OP);
                
               if(OP>Close[0])
               {
               
               if(((Close[0]+((SL)*Point))<OrderStopLoss())&&(OrderStopLoss()>(OrderOpenPrice()+(SL/2))))
               {
                OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+(SL*Point),Close[0]-(TP*Point),0,YellowGreen);
               }
               
               if(((Close[0]-OrderTakeProfit())<=((SL)*Point))&&((Close[0] + (SL*Point)) < OrderStopLoss()   )  )
              {
                OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+(SL*Point),Close[0]-(TP*Point),0,YellowGreen);
               }
               
               //Alert("||||||||||||||||||||||||||||||||||||||||||||||||||||Íà÷èíàþ ìîäèôèöèðîâàòü!");
              // if((Close[0]+((SL*2)*Point))<OrderStopLoss())
              // {
              //  OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+(SL*2*Point),Close[0]-(TP*Point),0,Gold);
              // }
               
              // if(((Close[0]-OrderTakeProfit())<=((SL)*Point))&&((Close[0] + (SL*Point)) < OrderStopLoss()   )  )
              //{
              //  OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+(SL*Point),Close[0]-(TP*Point),0,YellowGreen);
              // }
               //Alert("||||||||||||||||||||||||||||||||||||||||||||||||||||Ïðîìîäèôèöèðîâàë!");
               
               }
        
           }
           else if(OrderType()==OP_BUY)
           {
           
               if((OrderOpenPrice()+(SL*Point))<Close[0])
               {
               
                if(((Close[0]-((SL)*Point))>OrderStopLoss())&&(OrderStopLoss()<(OrderOpenPrice()+(SL/2))))
               OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-((SL)*Point),Close[0]+(TP)*Point,0,LightSteelBlue);
               
                if(((OrderTakeProfit()-Close[0])<=((SL)*Point))&&((Close[0] - (SL*Point)) > OrderStopLoss()   )  )
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-((SL)*Point),Close[0]+(TP)*Point,0,LightSteelBlue);
               }
               //Alert("||||||||||||||||||||||||||||||||||||||||||||||||||||Íà÷èíàþ ìîäèôèöèðîâàòü! BUY");
               
               // if((Close[0]-((SL*2)*Point))>OrderStopLoss())
              // OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-((SL*2)*Point),Close[0]+(TP)*Point,0,LightSteelBlue);
               
              //  if(((OrderTakeProfit()-Close[0])<=((SL)*Point))&&((Close[0] - (SL*Point)) > OrderStopLoss()   )  )
              // {
             //  OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-((SL)*Point),Close[0]+(TP)*Point,0,LightSteelBlue);
             //  }
               
               }
           
           }
        }
     }
 
}
 
void MyCloseAllOrderByPrice(double CurPrice,int MyOrderType)
{
    //RefreshRates();

 for(int i=0;i<OrdersTotal();i++)
     {
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
     if(OrderSymbol()==Symbol() && OrderType()==MyOrderType)
        {
        
         //OrderClose(Sell_ticket,lots,Ask,10,Red);
         if(MyOrderType==OP_SELL)
         {
         
            if(OrderOpenPrice()>(CurPrice+(SL/2)))
            {
            
            OrderClose(OrderTicket(),OrderLots(),OrderOpenPrice(),100,Black);
            
            
            }
            

        
         }
         
         
          if(MyOrderType==OP_BUY)
         {
         
            if(OrderOpenPrice()<(CurPrice-(SL/2)))
            {
            
            OrderClose(OrderTicket(),OrderLots(),OrderOpenPrice(),100,Black);
            
            
            }
        
         }
        
       /* kbi++;
        M_ob[kbi][0]=OrderTicket();
        M_ob[kbi][1]=OrderOpenPrice();
        M_ob[kbi][2]=OrderLots();
        M_ob[kbi][3]=OrderType();
        M_ob[kbi][4]=OrderMagicNumber();
        M_ob[kbi][5]=OrderStopLoss();
        M_ob[kbi][6]=OrderTakeProfit();
        M_ob[kbi][7]=OrderProfit();*/
        }
      } 
      
      
      //Sleep(100);
      //RefreshRates();
      
}
void MyCloseAllOrder(int MyOrderType)
{
    //RefreshRates();

 for(int i=0;i<OrdersTotal();i++)
     {
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
     if(OrderSymbol()==Symbol() && OrderType()==MyOrderType)
        {
        
         //OrderClose(Sell_ticket,lots,Ask,10,Red);
         
        OrderClose(OrderTicket(),OrderLots(),OrderOpenPrice(),100,Black);
        
       /* kbi++;
        M_ob[kbi][0]=OrderTicket();
        M_ob[kbi][1]=OrderOpenPrice();
        M_ob[kbi][2]=OrderLots();
        M_ob[kbi][3]=OrderType();
        M_ob[kbi][4]=OrderMagicNumber();
        M_ob[kbi][5]=OrderStopLoss();
        M_ob[kbi][6]=OrderTakeProfit();
        M_ob[kbi][7]=OrderProfit();*/
        }
      } 
      
      
      Sleep(100);
      RefreshRates();

 for( i=0;i<OrdersTotal();i++)
     {
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
     if(OrderSymbol()==Symbol() && OrderType()==MyOrderType)
        {
        
         //OrderClose(Sell_ticket,lots,Ask,10,Red);
         
        OrderClose(OrderTicket(),OrderLots(),OrderOpenPrice(),100,Black);
        

        }
      } 
      
}
void MySendOrder()
{


  MyOrderModify();

   int f;                                                 // Ôàéëîâàÿ ñòðóêòóðà
   double SigBuy;                                         // Ñèãíàë íà ïîêóïêó
   double SigSell;                                        // Ñèãíàë íà ïðîäàæó
   datetime SigTime;                                      // Âðåìÿ ñèãíàëà
   string DataRead;                                       // Ïåðåìåííàÿ äëÿ ÷òåíèÿ äàííûõ èç ôàéëà                                         
                             // Èìÿ ôàéëà
   string buf;                                            // Âðåìåííàÿ ïåðåìåííàÿ
   int index1,index2;  
   
       
       
    f=FileOpen(File_Name,FILE_READ,";"); 
   


             
   
  if(f>0)
  {
  
      DataRead=FileReadString(f);                         // ÷òåíèå èç ôàéëà
      index1=StringFind(DataRead, "|", 0);                // Ðàçäåëÿåì ñòðîêó
      buf=StringSubstr(DataRead,0,index1);                // Èçâëåêàåì ñèãíàë íà ïîêóïêó
      SigBuy=StrToDouble(buf);                            // Ïðåîáðàçîâàíèå òèïà äàííûõ
      index2=StringFind(DataRead, "|", index1+1);         // Ðàçäåëÿåì ñòðîêó
      buf=StringSubstr(DataRead,index1+1,index2-1);       // Èçâëåêàåì ñèãíàë íà ïðîäàæó
      SigSell=StrToDouble(buf);                           // Ïðåîáðàçîâàíèå òèïà äàííûõ
      buf=StringSubstr(DataRead,index2+1,index2+9);       // Èçâëåêàåì âðåèÿ ñèãíàëà
      SigTime =StrToTime(buf);
      
      Alert("Ïðî÷èòàë");
      
      if(SigLastTime!=SigTime)
      {
      
        Alert(" Âðåìÿ "+SigTime);
        
      if(SigBuy>=BuySignalLevel)
      {
           
           Alert(" Ñèãíàë "+SigBuy);
        

         if(SigSell<RiskLevel)
         {
         
              Alert(" Ðèñê " + SigSell );
              
             //MyCloseAllOrder(OP_SELL);
             
             int TPIND = SigBuy/BuySignalLevel;
             
             if(TPIND>=5)
             {
             //if(Close[4]<Close[0])//äîáàâèë âîò ýòè ñòðîêè - äî ýòîãî ðóáèò êàïóñòó äàæå î÷åíü
                //MyCloseAllOrder(OP_SELL);//ñíà÷àëà çàêðûâàåì âñå òàêîãî æå òèïà êàê ñîáèðàåìñÿ îòêðûòü
                
                 MyCloseAllOrderByPrice(Ask,OP_BUY);
                 
                int NewTP = TP ;//+ 4;
                Buy_ticket=OrderSend(Symbol(), OP_BUY, lots, NormalizeDouble(Ask,Digits), 50, Close[0]-SL*Point, Ask+NewTP*Point, "BUY_tss", magic, 0, Blue);
                
               
                
             }
             else
             {
            // if(Close[4]<Close[0])
               ///MyCloseAllOrder(OP_SELL);//ñíà÷àëà çàêðûâàåì âñå òàêîãî æå òèïà êàê ñîáèðàåìñÿ îòêðûòü
                
                Alert(" Îòêð " );
                
                MyCloseAllOrderByPrice(Ask,OP_BUY);
                Buy_ticket=OrderSend(Symbol(), OP_BUY, lots, NormalizeDouble(Ask,Digits), 50, Close[0]-SL*Point, Ask+TP*Point, "BUY_tss", magic, 0, Blue);
                 
             }
            
             
             
             
            
         } 
         
          
          
               
        
         
         
         // MyCloseAllOrder(OP_SELL);
          
         //çäåñü çàêðûâàåì âñå îðäåðà
         //OrderClose(Sell_ticket,lots,Ask,10,Red);
         
         
      }
      
       if(SigSell>=SellSignalLevel)
      {
       Alert(" Ñèãíàë "+SigSell);
    
        if(SigBuy<RiskLevel)
       {
        Alert(" Ðèñê " + SigBuy );
       // MyCloseAllOrder(OP_BUY);
       
       int sTPIND = SigSell/SellSignalLevel;
             
             if(sTPIND>=5)
             {
               //// if(Close[4]>Close[0])
               // {
                 // MyCloseAllOrder(OP_BUY);//ñíà÷àëà çàêðûâàåì âñå òàêîãî æå òèïà êàê ñîáèðàåìñÿ îòêðûòü
                //}
                  MyCloseAllOrderByPrice(Bid,OP_SELL);
                 int sNewTP = TP;// + 10;
                 Sell_ticket=OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 50,  Close[0]+((SL)*Point), Bid-(sNewTP)*Point, "SELL_tss", magic, 0, Green);
            
             }
             else
             {
                //if(Close[4]>Close[0])
                //{
                  // MyCloseAllOrder(OP_BUY);//ñíà÷àëà çàêðûâàåì âñå òàêîãî æå òèïà êàê ñîáèðàåìñÿ îòêðûòü
                //}
                 Alert(" Îòêð " );
                MyCloseAllOrderByPrice(Bid,OP_SELL);
                Sell_ticket=OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 50,  Close[0]+((SL)*Point), Bid-(TP)*Point, "SELL_tss", magic, 0, Green);
             }
      
       
       }

       
      // MyCloseAllOrder(OP_BUY);
       
      }
      
      
      
      }
      
       
      SigLastTime=SigTime;
      FileClose(f);  
      
      
      int s_count=ArraySize(SellTickArr);
      int b_count=ArraySize(BuyTickArr);

      Comment("  TSS-1 "," Buy:",SigBuy," Sell:",SigSell,"     SellArCount:",s_count,"     BuyArCount:",b_count);  
  }
}

int start()
  {
  
   // Alert(" Çäåñü ");
   //  Comment(TP);
   //  Sell_ticket=OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 50,  Close[0]+((SL)*Point), Bid-(TP)*Point, "SELL_tss", magic, 0, Green);
   //  return (0);     
   
    MySendOrder();   

   int    counted_bars=IndicatorCounted();
   string CurrentSymbol =Symbol();
   double CurrentClosePrice = iClose(CurrentSymbol,PERIOD_M1,0);

if(CurrentClosePrice==0)
{
  int LastError =   GetLastError();
  return(0);
}
   
 int FileHandle =  FileOpen(CurrentSymbol+".dat",  FILE_BIN |FILE_WRITE);
    
 if(FileHandle>0)
 {
     string strPrice = CurrentClosePrice;
     FileWrite(FileHandle,strPrice);// Close[0]
     FileClose(FileHandle);
 }
 
   
      
MySendOrder();  
  
  /*
//----
   // 1. îïðåäåëÿåì äàííûå=====================================================
   double ma42_0 = NormalizeDouble(iMA(Symbol(), 0, Slow_MA, 0, 1, 0, 1), Digits);
   double ma42_1 = NormalizeDouble(iMA(Symbol(), 0, Slow_MA, 0, 1, 0, 2), Digits);
   double dif_ma42 = ma42_0 - ma42_1;
   //----
   double ma21_0 = NormalizeDouble(iMA(Symbol(), 0, Middle_MA, 0, 1, 0, 1), Digits);
   double ma21_1 = NormalizeDouble(iMA(Symbol(), 0, Middle_MA, 0, 1, 0, 2), Digits);
   double dif_ma21 = ma21_0 - ma21_1;
   //----
   double ma14_0 = NormalizeDouble(iMA(Symbol(), 0, Fast_MA, 0, 1, 0, 1), Digits);
   double ma14_1 = NormalizeDouble(iMA(Symbol(), 0, Fast_MA, 0, 1, 0, 2), Digits);
   double dif_ma14 = ma14_0 - ma14_1;
   //----
   double rsi17_0 = NormalizeDouble(iRSI(Symbol(), 0, rsi_period, 0, 1), Digits);
   double rsi17_1 = NormalizeDouble(iRSI(Symbol(), 0, rsi_period, 0, 2), Digits);
   double dif_rsi17 = rsi17_0 - rsi17_1;
   //----
   Comment("dif42 = "+dif_ma42, "\nma42_0="+ma42_0, " ma42_1="+ma42_1,
       "\n\ndif21 = "+dif_ma21, "\nma21_0="+ma21_0, " ma21_1="+ma21_1,
       "\n\ndif14 = "+dif_ma14, "\nma14_0="+ma14_0, " ma14_1="+ma14_1,
       "\n\ndifrsi = "+dif_rsi17, "\nrsi17_0="+rsi17_0, " rsi_17_1="+rsi17_1);
   // 1. ======================================================================
   
   // 2. îòêðûòèå ïîçèöèé =====================================================
   if(new_time!=Time[0])
   {
      // 2.1 îòêðûòèå áàé
      if(rsi17_1<50 && rsi17_0>50)
         {
          if(dif_ma42>delta && dif_ma21>delta && dif_ma14>delta)
            {
             OrderSend(Symbol(), OP_BUY, lots, NormalizeDouble(Ask,Digits), 3, Low[1]-offset*Point, Ask+TP*Point, "BUY_sidus", magic, 0, CLR_NONE);
            }
         }
      //=================
      // 2.2 îòêðûòèå ñåëë
      if(rsi17_1>50 && rsi17_0<50)
         {
          if(dif_ma42<delta && dif_ma21<delta && dif_ma14<delta)
            {
             OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 3, High[1]+offset*Point, Bid-TP*Point, "SELL_sidus", magic, 0, CLR_NONE);
            }
         }
      //==================
   new_time = Time[0];
   }
   // 2. ======================================================================
   
   // 3. òðåéëèíã ïîçèöèé =====================================================
   
   //==========================================================================
//----
*/
   return(0);
  }
//+------------------------------------------------------------------+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 ---