Arrows and Curves

Author: Copyright � 2006
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Arrows and Curves
//+------------------------------------------------------------------+
//|                                          Arrows and Curves EA.mq4 |
//|           Ïðîñòîé ýêñïåðò èñïîëüçóþùèé èíäèêàòîð Ñòðåëêè è Ëèíèè |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006"
#property link      "kolas@list.ru"

// Ïàðàìåòðû òîðãîâëè äëÿ H4 EURUSD
extern double TrailingStop = 30;
extern double TakeProfit   = 30;
extern double StopLoss     = 80;

// Ïàðàìåòðû èíäèêàòîðà Ñòðåëêè è Ëèíèè
extern int SSP             = 6;     //ïåðèîä ëèíåéíîãî ðàçâîðîòà èíäèêàòîðà
extern int RISK            = 12;
extern int CountBars       = 50;    //ðàñ÷åòíûé ïåðèîä (áîëüøå íå íàäî)
extern double SkyCh        = 23.6;

// Ïàðàìåòðû MM
extern double Slippage     = 3;
extern bool PropotinalLots = false; // Ðåèíâåñòèðîâàíèå
extern double MinDepo      = 100;   // Ìèíèìàëüíûé äåïîçèò
extern double FixedLots    = 0.1;   // Ôèêñèðîâàííûé ðàçìåð îðäåðà
extern double PercentLots  = 10;    // Ïðîöåíò ðåèíâåñòèðîâàíèÿ

// Èäåíòèôèêàöèÿ ýêñïåðòà
extern string NameEA       = "Arrows and Curves";
extern int MAGICNUM        = 123;

double Lots;
double Sloss, Tprof;
bool Buy = false, Sell = false;
static int PrevBar = 0;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() 
  {return(0);}
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() 
  {return(0);}
  
//+------------------------------------------------------------------+
//|  Ïîëó÷åíèå ñèãíàëîâ íà ïîêóïêó è ïðîäàæó                         |
//+------------------------------------------------------------------+
void Indicators() 
   {                  
      Buy = (iCustom(Symbol(),0,"lukas1 ñòðåëêè è ëèíèè", SSP, RISK, CountBars, SkyCh, 0, 1) > 0) && (Time[0] != PrevBar);
      Sell = (iCustom(Symbol(),0,"lukas1 ñòðåëêè è ëèíèè", SSP, RISK, CountBars, SkyCh, 1, 1) > 0) && (Time[0] != PrevBar);
   }
   
//+------------------------------------------------------------------+
//|  Âûâîä ïðåäóïðåæäåíèÿ îá îòïðàâêå îðäåðà                         |
//+------------------------------------------------------------------+
void prtAlert(string str = "") 
  {
      Print(str);
      Alert(str);
  }
  
//+------------------------------------------------------------------+
//|  Ðàñ÷åò ðàçìåðà îðäåðà                                           |
//+------------------------------------------------------------------+
void LotsSize()
   {
      Lots = FixedLots;
      if (PropotinalLots) Lots = MathCeil(AccountFreeMargin() / 10000 * PercentLots) / 10;
      if (Lots > 10000) Lots = 10000;
   }  
  
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() 
  {
   // Ïðîâåðêà èñòîðèè
   if(Bars < SSP) 
     {
       Print("Not enough bars for this strategy - ", NameEA);
       return(-1);
     }
   // Ðàñ÷åò çíà÷åíèé èíäèêàòîðà
   Indicators();
   
   // Ðàñ÷åò æåëàåìîãî ðàçìåðà îðäåðà
   LotsSize();   

   // Òðåéëèíã è ðàçâîðîò
   int totalOrders = OrdersTotal();
   int numPos = 0;

   for(int i = 0; i < totalOrders; i++) 
     {
       OrderSelect(i, SELECT_BY_POS);    
       if(OrderSymbol() == Symbol() && OrderMagicNumber() == MAGICNUM) 
         {
           numPos++;
           // Ïðîâåðÿåì ïîêóïêó
           if(OrderType() == OP_BUY) 
             {
               // Çàêðûâàåì ïðè ðàçâîðîòå
               if (Sell) 
               {
                  OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Blue); 
                  numPos--;
               }
               else
               // Òðåéëèíã ñòîï
               if(TrailingStop > 0) 
                 {
                   if(Bid - OrderOpenPrice() > TrailingStop*Point) 
                     {
                       if(OrderStopLoss() < (Bid - TrailingStop*Point))
                           OrderModify(OrderTicket(), OrderOpenPrice(), 
                                       Bid - TrailingStop*Point, OrderTakeProfit(), 0, Blue);
                     }
                 }
               
             } 
           else 
             // Ïðîâåðÿåì ïðîäàæó
             {
               // Çàêðûâàåì ïðè ðàçâîðîòå
               if (Buy) 
               {
                  OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Red);
                  numPos--;
               }
               else
               // Òðåéëèíã ñòîï
               if(TrailingStop > 0) 
                 {
                   if(OrderOpenPrice() - Ask > TrailingStop*Point)
                     {
                       if(OrderStopLoss() == 0 || OrderStopLoss() > Ask + TrailingStop*Point)
                           OrderModify(OrderTicket(), OrderOpenPrice(), 
                                       Ask + TrailingStop*Point, OrderTakeProfit(), 0, Red);
                     }           
                 }
             }
         }
     }
     
   // Îòêðûâàåì íîâûå îðäåðà
   if(numPos < 1)
     {   
       // Åñëè ðàçìåð äåïîçèòà óñòðàèâàåò
       if(AccountFreeMargin() < MinDepo)
         {
           Print("Not enough money to trade ", Lots, " lots. Strategy:", NameEA);
           return(0);
         }
       // Åñëè åñòü ñèãíàë íà ïîêóïêó
       if (Buy)
         {
           Sloss = Ask - StopLoss * Point;
           Tprof = Bid + TakeProfit * Point;
           PrevBar = Time[0];
            OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, Sloss, Tprof, NameEA + CurTime(), 
                     MAGICNUM, 0, Green);
           prtAlert("Buying"); 
         }
       // Åñëè åñòü ñèãíàë íà ïðîäàæó
       if (Sell) 
         {
           Sloss = Bid + StopLoss * Point;
           Tprof = Ask - TakeProfit * Point;
           PrevBar = Time[0];
            OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, Sloss, Tprof, NameEA + CurTime(), 
                     MAGICNUM, 0, Red);
           prtAlert("Selling"); 
         }
     } 

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