Author: Copyright � 2006, Victor Chebotariov
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GOTO
//+------------------------------------------------------------------+
//|                                                           GO.mq4 |
//|                             Copyright © 2006, Victor Chebotariov |
//|                                      http://www.chebotariov.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Victor Chebotariov"
#property link      "http://www.chebotariov.com/"

#define MAGICMA 30072006

int    PERIOD = 174;
int    MODE = 0;
extern double RISK = 30.0;
extern int    MAXORDERS = 5;

//+------------------------------------------------------------------+
//| Ðàñ÷åò îïòèìàëüíîãî îáúåìà ëîòà                                  |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
//----
   double Lots=NormalizeDouble(AccountBalance()*RISK/100000.0,1);
   if(AccountFreeMargin()<(1000*Lots)){Lots=NormalizeDouble(AccountFreeMargin()*RISK/100000.0,1);}
   if(Lots>MarketInfo(Symbol(),MODE_MAXLOT)){Lots=MarketInfo(Symbol(),MODE_MAXLOT);}
   if(Lots<MarketInfo(Symbol(),MODE_MINLOT)){Lots=MarketInfo(Symbol(),MODE_MINLOT);}
//----
   return(Lots);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

//+------------------------------------------------------------------+
//if(!IsDemo()){return(0);} //  óäàëèòü äëÿ ðàáîòû íà ðåàëüíîì ñ÷åòå   |
//+------------------------------------------------------------------+

   int cnt,ticket,MODEMA;
   int total=OrdersTotal();

   if(MODE==0){MODEMA=MODE_SMA;}
   if(MODE==1){MODEMA=MODE_EMA;}
   if(MODE==2){MODEMA=MODE_SMMA;}
   if(MODE==3){MODEMA=MODE_LWMA;}
   
   HideTestIndicators(true);
   double high =iMA(NULL,0,PERIOD,0,MODEMA,PRICE_HIGH,0);
   double low  =iMA(NULL,0,PERIOD,0,MODEMA,PRICE_LOW,0);
   double open =iMA(NULL,0,PERIOD,0,MODEMA,PRICE_OPEN,0);
   double close=iMA(NULL,0,PERIOD,0,MODEMA,PRICE_CLOSE,0);
   double GO=((close-open)+(high-open)+(low-open)+(close-low)+(close-high))*Volume[0];
   HideTestIndicators(false);

   if(GO<0)
     {
      for(cnt=total-1;cnt>=0;cnt--)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
         {OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);return(0);}
        }
     }

   if(GO>0)
     {
      for(cnt=total-1;cnt>=0;cnt--)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
         {OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);return(0);}
        }
     }

   if((GO>0 || GO<0) && (!GlobalVariableCheck("Symbol()"+"MAGICMA"+"TimeBuySell") || GlobalVariableGet("Symbol()"+"MAGICMA"+"TimeBuySell")!=Time[0] && total<MAXORDERS))
     {
      if(AccountFreeMargin()<(1000*LotsOptimized()))
      {Print("Ó Âàñ íåäîñòàòî÷íî äåíåã. Ñâîáîäíîé ìàðæè = ", AccountFreeMargin());return(0);}
      if(GO>0)
        {
         ticket=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Ask,3,0,0,"MoneyPlus",MAGICMA,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
            GlobalVariableSet("Symbol()"+"MAGICMA"+"TimeBuySell",Time[0]);
           }
         else Print("Error opening BUY order : ",GetLastError());return(0); 
        }
      if(GO<0)
        {
         ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Bid,3,0,0,"MoneyPlus",MAGICMA,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
            GlobalVariableSet("Symbol()"+"MAGICMA"+"TimeBuySell",Time[0]);
           }
         else Print("Error opening SELL order : ",GetLastError());return(0);
        }
     }
//----
   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 ---