0lpr15zr5gfp624y_lpxhy0jscwms14wscxhuyvub49dfpwv6wvlxj5

Price Data Components
Series array that contains open time of each bar
Orders Execution
Checks for the total of open ordersChecks for the total of closed ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Miscellaneous
Uses files from the file systemIt writes information to fileIt reads information from a file
0 Views
0 Downloads
0 Favorites
0lpr15zr5gfp624y_lpxhy0jscwms14wscxhuyvub49dfpwv6wvlxj5
//+------------------------------------------------------------------+
//|                                              conf_i_investor.mq4 |
//|                      Copyright © 2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
///// out.txt   in.txt

extern string  ___         = "---------------- Money Management";
extern double  Lots        = 0.1;
extern double  RiskPercent = 3;

extern int     MagicNumber   = 333263964;

extern double stops = 85;

 double Profit = 0;
 double LastProfit = 0;

string _Time;
double _Open;

double Stops[2];// 0 ñòîï äëÿ áàé   1 ñòîï äëÿ ñåë
int k=1;
static int spread   = 3;
static int          prevtime = 0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
datetime TimeClose;
int init()
  {
//----
  
   FileDelete(Symbol()+".txt");
   for(int shift = Bars ; shift >= 0 ; shift--){
        _Time =  TimeToStr(Time[shift],TIME_DATE|TIME_MINUTES);
        _Open =  Open[shift];
        TextSave(_Open+"\t"+_Time,"out");
        prevtime = Time[0];
        if (Digits==3 || Digits==5) k=10;
        
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   
   
   
   
   
   if (Time[0] == prevtime) return(0);
   prevtime = Time[0];
   _Time =  TimeToStr(Time[0],TIME_DATE|TIME_MINUTES);
   _Open =  Open[0];
   TextSave(_Open+"\t"+_Time,"out");
   for(int i = 0; i <= OrdersTotal(); i++) 
     {
       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()) 
         {
          Profit = OrderProfit();
         } 
      } 
   int  total = OrdersHistoryTotal();   
   for ( i = 0; i < total; i++) {
      OrderSelect(i, SELECT_BY_POS, MODE_HISTORY); 
      // check for symbol & magic number
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {         

         LastProfit = OrderProfit();
         TimeClose=OrderCloseTime();
      
         }    
   } 

         //
         spread = MarketInfo(Symbol(), MODE_SPREAD);
         SendStopOrders(stops*k,stops*k); 
     if ( retOrders(Symbol())== 0 && TradingSystem()<0 ) 
        {
        OrderSend(Symbol(),OP_SELL,GetLots(Symbol()), Bid, 3, 0, 0, "", MagicNumber, 0, Red);
        }
     if ( retOrders(Symbol())== 0 && TradingSystem()>0  )
        {
        OrderSend(Symbol(),OP_BUY,GetLots(Symbol()) , Ask, 3, 0, 0, "",MagicNumber, 0, Blue);
        }
   for( i = 0; i <= OrdersTotal(); i++) 
     {
       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()) 
         {
          if (OrderType() == OP_BUY) {         
               if (TradingSystem() <= 0) {OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);}
               if (TradingSystem() > 0 && Bid > (OrderStopLoss() + ((stops*k) * 2  + spread) * Point)) { // trailing stop
                  if (! OrderModify(OrderTicket(), OrderOpenPrice(), Bid - (stops*k) * Point, 0, 0, Blue)) {
                     Sleep(30000);
                    }
                } 
           }  
          if (OrderType() == OP_SELL) {
               if (TradingSystem() >= 0) {OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);}
               if (TradingSystem() < 0 && Ask < (OrderStopLoss() - ((stops*k) * 2    + spread) * Point)) { // trailing stop
                  if (! OrderModify(OrderTicket(), OrderOpenPrice(), Ask + (stops*k) * Point, 0, 0, Blue)) {
                     Sleep(30000);
                  }
               }
            }        
         } 
      }
Out("\t"+Symbol()+"\t"+Period()+"\t"+retOrders(Symbol())+"\t"+Profit+"\t"+LastProfit+"\t"+TimeToStr(TimeClose,TIME_DATE|TIME_SECONDS),"out");      
  }
//+------------------------------------------------------------------+
void TextSave(string savetext,string namefile) {
   int h=FileOpen(Symbol()+".txt" , FILE_CSV | FILE_READ | FILE_WRITE);  
       if(h>0)
        {
        FileSeek (h, 0, SEEK_END );
        FileWrite(h,savetext);
        FileClose(h);                         
        }
  }      
//+------------------------------------------------------------------+
void Out(string savetext,string namefile) {
   if(IsOptimization())return;
   int h=FileOpen(Symbol()+".txt" , FILE_CSV | FILE_READ | FILE_WRITE);  
       if(h>0)
        {
        FileSeek (h, 0, SEEK_SET );
        FileWrite(h,savetext);
        FileClose(h);                         
        }
  }      
//************************************************************************************************
void SendStopOrders(double sl = -1, double tp = -1){
if(OrdersTotal()!=0)
   for(int i = 0; i < OrdersTotal(); i++) 
     if(OrderSelect(i, SELECT_BY_POS))
        if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()&&OrderStopLoss()==0&&OrderTakeProfit()==0)
         {if(OrderType() == OP_BUY)
            {sl =  Bid - sl * Point;tp =  Bid + tp * Point;}
            else
            {sl =  Ask + sl * Point;tp =  Ask - tp * Point;}
            if(!OrderModify(OrderTicket(), 0, sl, 0,0))prevtime = Time[1];
         }  
     }           
//************************************************************************************************
// ÐÀÑ×ÅÒ ËÎÒÀ
//************************************************************************************************
double GetLots(string _Symbol) {
  if(IsOptimization() || IsTesting())return(0.1);
   double RetVal;
   double LotsMin    = MarketInfo(_Symbol,MODE_MINLOT);
   double LotsMax    = MarketInfo(_Symbol,MODE_MAXLOT);
   double LotsStep   = MarketInfo(_Symbol,MODE_LOTSTEP);
   RetVal=MathCeil(Lots/LotsStep)*LotsStep;
   if (RiskPercent>0) 
      RetVal=MathCeil(AccountFreeMargin()/100000*RiskPercent/LotsStep)*LotsStep;
   RetVal=MathMin(LotsMax,MathMax(LotsMin,RetVal));
   return(RetVal);
}
//************************************************************************************************
int retOrders(string sym){
   int total = OrdersTotal();
   int OrderCount=0;
   for(int i = 0; i <= total; i++) 
     {
       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       if( OrderSymbol() == sym && OrderMagicNumber() == MagicNumber) 
         {
          if(OrderType()==OP_BUY)return(1);
          if(OrderType()==OP_SELL)return(-1);
         }
      }
     return(0);
 }
//************************************************************************************************
int TradingSystem() {
       int result = 0;
       int h=FileOpen(Symbol()+".txt" , FILE_CSV | FILE_READ ,';');  
       if(h>0)
        {
        result = FileReadNumber(h);
        FileClose(h);                         
        }

    return(result); 
 }
//************************************************************************************************ FileTell

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