CurrentInfo

Author: Andrei Andreev
CurrentInfo
Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open orders
Indicators Used
Indicator of the average true range
0 Views
0 Downloads
0 Favorites
CurrentInfo
//+------------------------------------------------------------------+
//|                                                Donchian.mq4 |
//|                                                   Andrei Andreev |
//|                                             http://www.andand.ru |
//+------------------------------------------------------------------+

// BASED ON:
//+------------------------------------------------------------------+
//|                                                   ^X_Sensors.mq4 |
//|                                                    Version 2.0.1 |
//|------------------------------------------------------------------|
//|                     Copyright © 2007, Mr.WT, Senior Linux Hacker |
//|                                     http://w-tiger.narod.ru/wk2/ |
//+------------------------------------------------------------------+
#property copyright "Andrei Andreev"
#property link      "http://www.andand.ru"

#property indicator_chart_window

extern int ForDays=10;



int _N_Time, ObjectId;
string OBJECT_PREFIX = "LEVELS";
int _My_Period=PERIOD_D1;
//-------------------------------------------------------------------------------------------
int init() {
_N_Time = 0;
return(0);
}
//-------------------------------------------------------------------------------------------
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {

//if ( _N_Time == Time[0] ) return(0);

double _rates[][6];

double open,close, high, low;
double AverageRange;

ArrayCopyRates(_rates, NULL, _My_Period);
int err = GetLastError();
if(err == 4066) 
  {
  Sleep(1000);
  if(iClose(NULL, _My_Period, 0) != Close[0]) 
    {
     Sleep(1000);
     return(0);
     }
  }
close = _rates[1][4];
high = _rates[0][3];
low = _rates[0][2];
open = _rates[0][1];

AverageRange=0;
for (int i=1;i<ForDays+1;i++)
    {
    AverageRange=AverageRange+(_rates[i][3]-_rates[i][2])/Point;
    }
AverageRange=NormalizeDouble(AverageRange/ForDays,0); 

double Risk=0.05;
double N=NormalizeDouble(iATR(Symbol(),0,96,1)/Point,0);
double pips=MarketInfo(Symbol(),MODE_TICKVALUE);
double NUS=NormalizeDouble(N*pips,0);

Comment( "\nÏðèáûëüíûõ ñäåëîê  : ",TotalProfitableDeals()," íà ",ProfitableDealsAmount()," òóãðèêîâ",
         "\nÓáûòî÷íûõ ñäåëîê    : ",TotalLoosingDeals()," íà ",-LoosingDealsAmount()," òóãðèêîâ",
         "\nÏðèáûëü ïî ñòîïàì  : ", NormalizeDouble(TotalProfitByStops(),0)," òóãðèêîâ",
         "\nÎòëîæåííûõ ñäåëîê : ",CalculatePendingTotal(),
         "\n",
         "\nÄíåâíîé äèàïàçîí:",
         "\nÑåãîäíÿ   :  ",(high-low)/Point," ïèïñîâ",
         "\nÂ÷åðà       : ",(_rates[1][3]-_rates[1][2])/Point," ïèïñîâ",
         "\nÑðåäíèé   :  ",AverageRange," ïèïñîâ"," çà ",ForDays," äíåé",
         "\nÎäèí ïèïñ : ",pips," òóãðèêîâ"
         );  
              



   
_N_Time = Time[0];
//---- End Of Program
return(0);
}
//+------------------------------------------------------------------+
double TotalProfitByStops()
{
int cnt, ticket, total;
double Profit=0;
   
   total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  if (OrderStopLoss()!=0)
      {   
      if(OrderType()==OP_BUY)  Profit=Profit+(OrderStopLoss()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT)*OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)+OrderSwap();
      if(OrderType()==OP_SELL) Profit=Profit+(OrderOpenPrice()-OrderStopLoss())/MarketInfo(OrderSymbol(),MODE_POINT)*OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)+OrderSwap();
      }
     } 
return (Profit);    
} 




double TotalProfitableDeals()
{
int cnt, ticket, total;
double ProfitableDeals=0;
   
   total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  if (OrderProfit()>0)
      {  
      ProfitableDeals=ProfitableDeals+1; 
      }
     } 
return (ProfitableDeals);    
} 

double ProfitableDealsAmount()
{
int cnt, ticket, total;
double Amount=0;
   
   total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  if (OrderProfit()>0)
      {   
      Amount=Amount+(OrderProfit()+OrderSwap());
      }
     } 
return (Amount);    
} 

double LoosingDealsAmount()
{
int cnt, ticket, total;
double Amount=0;
   
   total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  if (OrderProfit()<0)
      {
      Amount=Amount+(OrderProfit()+OrderSwap());
      }
     } 
return (Amount);    
} 


double TotalLoosingDeals()
{
int cnt, ticket, total;
double LoosingDeals=0;
   
   total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  if (OrderProfit()<0)
      {  
      LoosingDeals=LoosingDeals+1; 
      }
     } 
return (LoosingDeals);    
} 

int CalculatePendingTotal()
  {
   int cmd;
   int orders=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
         cmd=OrderType();
         if(cmd!=OP_BUY && cmd!=OP_SELL) orders++;

     }
//---- return orders volume
  return(orders);
  
  }   

//-------------------------------------------------------------------------------------------

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