I will write a free mql4 advisor - page 13

 
oleg3791: the advisor was constructing four lines on five clicks on the chart

Required lines in yellow

#property strict

int      Количество;
datetime старый, новый=0;
double   старая, новая=0;

void OnInit()
{
  Количество=0;
  ObjectsDeleteAll(0, "Линия");
}

void OnChartEvent(const int     id,  // идентификатор события   
                  const long &x, const double &yy,
                  const string& s)
{
  if(id!=CHARTEVENT_CLICK) return;
  if(Количество>4){OnInit();return;}
  string name[5]={"","Линия_1","Линия_2","Линия_3","Линия_4"};
  int y=int(yy);
  int O;
  старый=новый; старая=новая;
  ChartXYToTimePrice(0,int(x),y,O,новый,новая); // xy ---> время,цену
  if(Количество>0)
  ObjectCreate(name[Количество],OBJ_TREND,0,старый,старая,новый,новая);
  ObjectSet(name[Количество],OBJPROP_RAY,false);
  ObjectSet(name[Количество],OBJPROP_COLOR,Gold);
  ObjectSet(name[Количество],OBJPROP_WIDTH,2);
  Количество++; 
}

void OnDeinit(const int причина)
{
  OnInit();
}
 
STARIJ:

Yellow lines required

Thank you!!!
 
oleg3791:   Thank you!!!

Now tell me how to make a profit here... Or is it to build a game?

 

Hi everyone, can you please help me find an error in the code of the EA, I think I have looked through it all, it seems to be all written correctly in the code, but the program does not trade correctly for some reason! The idea is this: The advisor has to look for two long candles of the same direction (the length between the candles is adjustable in the advisor, ie between the two minimum or maximum candles, depending on the direction), if the price in the opposite direction breaks the minimum or maximum of the last candle, a deal should open (Example picture situations on the chart attached to the file). The adviser should open deals at every such suitable situation, but for some reason it opens deals only on the trading windows between days. Here is the situation, who is not difficult from programmers, please help, fix the error. EA code see below as well as in attached file.

//+-----------------------------------------------------------------------------------------------+
//|                                                                           Spacing_Candles.mq4 |
//|                                                                        Copyright 2017, Vladim |
//|                                                                            vk.com/id229534564 |
//|                                                                  Mail: Vladim120385@yandex.ru |
//+-----------------------------------------------------------------------------------------------+
#property copyright "Copyright 2017, Vladim"
#property link      "vk.com/id229534564"
#property version   "1.00"
#property strict

//--- параметры советника
extern string paramEA    = "";     // Parameters EA
extern double volume     = 0.01;   // Volume
extern double stopLoss   = 5;     // StopLoss
extern double takeProfit = 1.5;    // TakeProfit
extern double maxSpacing = 150;   // MaxSpacing
extern double minSpacing = 30;    // MinSpacing
extern double TrailingStop  = 0;   // TrailingStop
extern int    magic      = 127;    // Magic

//--- глобальные переменные
datetime newCandle;
int tip;

//+-----------------------------------------------------------------------------------------------+
int OnInit()
{
   
   return(INIT_SUCCEEDED);
}
//+-----------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   
}
//+-----------------------------------------------------------------------------------------------+
void OnTick()
{
   if(newCandle != Time[0]) FindPattern();
   newCandle = Time[0];
}
//+-----------------------------------------------------------------------------------------------+
void OpenOrder(int type)   // Откроем рыночный ордер
{
   if(type == OP_BUY)  if(OrderSend(_Symbol, OP_BUY,  volume, Ask, 0, 0, 0, "", magic, 0)) SetSLTP(OP_BUY);
   if(type == OP_SELL) if(OrderSend(_Symbol, OP_SELL, volume, Bid, 0, 0, 0, "", magic, 0)) SetSLTP(OP_SELL);
}
//+-----------------------------------------------------------------------------------------------+
void SetSLTP(int type)   // Установим стоп приказы
{
   double sl = 0;
   double tp = 0;
   
   if(type == OP_BUY)
      for(int i = 0; i < OrdersTotal(); i++)
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            if(OrderSymbol() == _Symbol && OrderMagicNumber() == magic && OrderType() == OP_BUY && OrderStopLoss() == 0)
            {
               sl = NormalizeDouble(Low[1] - stopLoss * _Point, _Digits);
               tp = NormalizeDouble(OrderOpenPrice() + (OrderOpenPrice() - Low[1]) * takeProfit, Digits);
               if(OrderModify(OrderTicket(), OrderOpenPrice(), sl, tp, 0)) return;
            }
   if(type == OP_SELL)
      for(int i = 0; i < OrdersTotal(); i++)
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            if(OrderSymbol() == _Symbol && OrderMagicNumber() == magic && OrderType() == OP_SELL && OrderStopLoss() == 0)
            {
               sl = NormalizeDouble(High[1] + stopLoss * _Point, _Digits);
               tp = NormalizeDouble(OrderOpenPrice() - (High[1] - OrderOpenPrice()) * takeProfit, Digits);
               if(OrderModify(OrderTicket(), OrderOpenPrice(), sl, tp, 0)) return;
            }
}
//+-----------------------------------------------------------------------------------------------+
void FindPattern()   // Ищем большое расстояние между свечами
{
   if(High[1] < High[2] && Bid > High[1] && Low[1] < Low[2])
   {
      double spacing = NormalizeDouble((High[2] - High[1]) / _Point, 0);
            
      if(maxSpacing >= spacing && minSpacing <= spacing)
         OpenOrder(OP_BUY);
   }
   if(Low[1] > Low[2] && Bid < Low[1] && High[1] > High[2])
   {
      double spacing = NormalizeDouble((Low[1] - Low[2]) / _Point, 0);
            
      if(maxSpacing >= spacing && minSpacing <= spacing)
         OpenOrder(OP_SELL);
   }   
   {
      if (TrailingStop!=0) TrailingStop();      
   }
}
//+-----------------------------------------------------------------------------------------------+
void TrailingStop()
{
   double StLo,OSL,OOP;
   bool error=true;   
   for (int i=0; i<OrdersTotal(); i++) 
   {
      if (OrderSelect(i, SELECT_BY_POS))
      {
         tip = OrderType();
         if (tip<2 && OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
         {
            OSL   = NormalizeDouble(OrderStopLoss(),Digits);
            OOP   = NormalizeDouble(OrderOpenPrice(),Digits);
            if (tip==0)        
            {  
               StLo = NormalizeDouble(Bid - TrailingStop*Point,Digits);
               if (StLo < OOP) continue;
               if (StLo > OSL)
                  error=OrderModify(OrderTicket(),OrderOpenPrice(),StLo,OrderTakeProfit(),0,White);

            }                                         
            if (tip==1)    
            {                                         
               StLo = NormalizeDouble(Ask + TrailingStop*Point,Digits);           
               if (StLo > OOP) continue;
               if (StLo < OSL || OSL==0 )
                  error=OrderModify(OrderTicket(),OrderOpenPrice(),StLo,OrderTakeProfit(),0,White);
            } 
            if (!error) Alert("Error TrailingStop ",GetLastError(),"   ",Symbol(),"   SL ",StLo);
         }
      }
   }
}
//+-----------------------------------------------------------------------------------------------+


Photo of the "How an EA should bet" chart

Files:
 
Vladim1203:

Hi everyone, can you please help me find an error in the code of the EA, I think I have looked through it all, it seems to be all written correctly in the code, but the program does not trade correctly for some reason! The idea is this: The advisor has to look for two long candles of the same direction (the length between the candles is adjustable in the advisor, ie between the two minimum or maximum candles, depending on the direction), if the price in the opposite direction breaks the minimum or maximum of the last candle, a deal should open (Example picture situations on the chart attached to the file). The adviser should open deals at every such suitable situation, but for some reason it opens deals only on the trading windows between days. Here is the situation, who is not difficult from programmers, please help, fix the error. See the EA code below as well as in the attached file.

It is better to first write the part of the EA that would mark on the chart the candles found, so that everything becomes clear. And the following lines are unnecessary in your case:

extern string paramEA    = "";     // Parameters EA

и

//+-----------------------------------------------------------------------------------------------+
int OnInit()
{
   
   return(INIT_SUCCEEDED);
}
//+-----------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   
}
//+-----------------------------------------------------------------------------------------------+
 
STARIJ:

Now tell me how to make a profit here... Or do you need it to build a game?


There is no way to get a profit yet. There is an algorithm for calculation of two probable price targets, along the trend, by five major points, but it is calculated on a special server with a paid subscription. I want to calculate targets myself, the work on the algorithm is not over yet.

What will your program look like in MQL4?

 
Anton Yakovlev:
If you have a good strategy and are willing to share it, i can write an EA. i invite you to discuss it either publicly or in private messages.

Anton, help me out, I've added trailing stop function to the EA, I've tested it and it shows two errors. - I've got my head bashed, I cannot figure out how to fix them to get an owl. However trades are closed according to old strategy after the price has touched the upper limit of the channel and the lower one, respectively. I guess something has to be changed here as well. - Call back to the dnr army guys.

#property copyright "Copyright 2017, MetaQuotes Software Corp."

#property link "https://www.mql5.com"

#property version "1.00"

#property strict


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

extern double Lots = 0.01;

extern int TakeProfit = 600;

extern int StopLoss = 25;

extern int Magic = 0001;

extern int Slippage = 3;

extern int TralType = 0; // 0-SAR, 1-ATR, 2-HMA.

extern double SAR_Step = 0.02;

extern double SAR_Max = 0.2;

extern int ATR_Period = 14;

extern double ATR_K = 2.0;

extern inttern HMA_Period = 16;

extern intern HMA_Method = 3;

extern inttern HMA_Shift = 0;

datetime LBT;

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

extern string TMA = "TMA indicator parameters";

extern string TimeFrame = "current time frame";

extern int HalfLength = 56;

extern int Price = "PRICE_CLOSE;

extern double ATRMultiplier = 2.0;

extern inttern ATRPeriod = 100;

extern bool Interpolate = true;

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

double PriceHigh, PriceLow, SL, TP;

int ticket;


//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

if (Digits == 3 || Digits == 5)

{

TakeProfit *= 10;

StopLoss *= 10;

Slippage *= 10;

}

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{


}

//+------------------------------------------------------------------+

//| expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);

PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);

if(CountSell() == 0 && Bid >= PriceHigh)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);

if (ticket > 0)

{

SL = NormalizeDouble(Bid + StopLoss*Point, Digits);

TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);

if (OrderSelect(ticket, SELECT_BY_TICKET))

if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Print(" Ordermodification error!)

}

}

if (CountBuy() == 0 && Ask <= PriceLow)

{

ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);

if (ticket > 0)

{

TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);

SL = NormalizeDouble(Ask - StopLoss*Point, Digits);

if (OrderSelect(ticket, SELECT_BY_TICKET))

if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Print("Error modifying the buy order!)

} else Print("Error opening the Buy order");

}

//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//--------


//--------

return (0);

}

//+------------------------------------------------------------------+

//| expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);

PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);

if(CountSell() == 0 && Bid >= PriceHigh)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);

if (ticket > 0)

{

SL = NormalizeDouble(Bid + StopLoss*Point, Digits);

TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);

if (OrderSelect(ticket, SELECT_BY_TICKET))

if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Print("Error modifying the sell order!)

} else Print("Error opening the sell order!)

}

if (CountBuy() == 0 && Ask <= PriceLow)

{

ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);

if (ticket > 0)

{

TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);

SL = NormalizeDouble(Ask - StopLoss*Point, Digits);

if (OrderSelect(ticket, SELECT_BY_TICKET))

if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Print("Error modifying the buy order!)

} else Print("Error opening the Buy order");

}

if (Ask <= PriceLow && CountSell() > 0)

{

for (int i = OrdersTotal() -1; i>0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)

if (!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black))

Print("Sell order close error!)

}

}

}

if (Bid >= PriceHigh && CountBuy() > 0)

{

for (int i = OrdersTotal() -1; i>0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)

if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Black))

Print("OrderClose Buy error!)

}

}

}

}

//+------------------------------------------------------------------+

int CountSell()

{

int count = 0;

for (int trade = OrdersTotal()-1; trade>=0; trade--)

{

if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)

count++;

}

}

return(count);

}//+------------------------------------------------------------------+

int CountBuy()

{

int count = 0;

for (int trade = OrdersTotal()-1; trade>=0; trade--)

{

if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)

count++;

}

}

return(count);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//+-------


//+-------

return (0)

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int Start()

{

//-----

bool error = fals;

if (LBT!=Time[0]) {

if (OrdersTotal()!=0) {

for (int i=0; i<OrdersTotal(); i++) {

if (OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderType()<2) {

double SL = OrderStopLoss();

if OrderType()==0) {

switch (TralType) {

case 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);

break;

case 1: SL = High[1] - iATR(NULL,0,ATR,Period,1)*ATR_K;

break;

case 2: SL = iCustom(NULL,0, "VininI_HMAsound&amp",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);

break;

}

if (SL<OrderStopLoss())

SL = OrderStopLoss();

}

if (OrderType()==1) {

switch (TralType) {

case 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);

break;

case 1: SL = Low[1] + iATR(NULL,0,ATR,Period,1)*ATR_K;

break;

case 2: SL = iCustom(NULL,0, "VininI_HMAsound&amp",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);

break;

}

if (SL>OrderStopLoss())

SL = OrderStopLoss();

}

if (SL!=OrderStopLoss()) {

if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0))

error = true;

}

}

}

}

if (!error)

LBT = Time[0];

}

return (0);

}

//+------------------------------------------------------------------+

Автоматический трейдинг и тестирование торговых стратегий
Автоматический трейдинг и тестирование торговых стратегий
  • www.mql5.com
Выберите подходящую торговую стратегию и оформите подписку на нее в пару кликов. Все Сигналы сопровождаются подробной статистикой и графиками. Станьте Поставщиком торговых сигналов и продавайте подписку тысячам трейдеров по всему миру. Наш сервис позволит вам хорошо зарабатывать на прибыльной стратегии даже при небольшом стартовом капитале...
 
Andrey Luxe:

To gain experience in this area, I will write 25 EAs for free for your interesting ideas and strategies

Only 19 EAs left


I haveadded trailing stop function to EA and I have commented it and it has two errors. - I may have some errors, but I do not know how to fix them. However trades are closed according to old strategy after the price has touched the upper limit of the channel and the lower one, respectively. I guess something has to be changed here as well. - Call back to the dnr army guys.

#property copyright "Copyright 2017, MetaQuotes Software Corp."

#property link "https://www.mql5.com"

#property version "1.00"

#property strict


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

extern double Lots = 0.01;

extern int TakeProfit = 600;

extern int StopLoss = 25;

extern int Magic = 0001;

extern int Slippage = 3;

extern int TralType = 0; // 0-SAR, 1-ATR, 2-HMA.

extern double SAR_Step = 0.02;

extern double SAR_Max = 0.2;

extern int ATR_Period = 14;

extern double ATR_K = 2.0;

extern inttern HMA_Period = 16;

extern intern HMA_Method = 3;

extern inttern HMA_Shift = 0;

datetime LBT;

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

extern string TMA = "TMA indicator parameters";

extern string TimeFrame = "current time frame";

extern int HalfLength = 56;

extern int Price = "PRICE_CLOSE;

extern double ATRMultiplier = 2.0;

extern inttern ATRPeriod = 100;

extern bool Interpolate = true;

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

double PriceHigh, PriceLow, SL, TP;

int ticket;


//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

if (Digits == 3 || Digits == 5)

{

TakeProfit *= 10;

StopLoss *= 10;

Slippage *= 10;

}

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{


}

//+------------------------------------------------------------------+

//| expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);

PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);

if(CountSell() == 0 && Bid >= PriceHigh)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);

if (ticket > 0)

{

SL = NormalizeDouble(Bid + StopLoss*Point, Digits);

TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);

if (OrderSelect(ticket, SELECT_BY_TICKET))

if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Print(" Ordermodification error!)

}

}

if (CountBuy() == 0 && Ask <= PriceLow)

{

ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);

if (ticket > 0)

{

TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);

SL = NormalizeDouble(Ask - StopLoss*Point, Digits);

if (OrderSelect(ticket, SELECT_BY_TICKET))

if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Print("Error modifying the buy order!)

} else Print("Error opening the Buy order");

}

//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//--------


//--------

return (0);

}

//+------------------------------------------------------------------+

//| expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);

PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);

if(CountSell() == 0 && Bid >= PriceHigh)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);

if (ticket > 0)

{

SL = NormalizeDouble(Bid + StopLoss*Point, Digits);

TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);

if (OrderSelect(ticket, SELECT_BY_TICKET))

if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Print("Error modifying the sell order!)

} else Print("Error opening the sell order!)

}

if (CountBuy() == 0 && Ask <= PriceLow)

{

ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);

if (ticket > 0)

{

TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);

SL = NormalizeDouble(Ask - StopLoss*Point, Digits);

if (OrderSelect(ticket, SELECT_BY_TICKET))

if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Print("Error modifying the buy order!)

} else Print("Error opening the Buy order");

}

if (Ask <= PriceLow && CountSell() > 0)

{

for (int i = OrdersTotal() -1; i>0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)

if (!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black))

Print("Sell order close error!)

}

}

}

if (Bid >= PriceHigh && CountBuy() > 0)

{

for (int i = OrdersTotal() -1; i>0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)

if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Black))

Print("OrderClose Buy error!)

}

}

}

}

//+------------------------------------------------------------------+

int CountSell()

{

int count = 0;

for (int trade = OrdersTotal()-1; trade>=0; trade--)

{

if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)

count++;

}

}

return(count);

}//+------------------------------------------------------------------+

int CountBuy()

{

int count = 0;

for (int trade = OrdersTotal()-1; trade>=0; trade--)

{

if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)

count++;

}

}

return(count);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//+-------


//+-------

return (0)

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int Start()

{

//-----

bool error = fals;

if (LBT!=Time[0]) {

if (OrdersTotal()!=0) {

for (int i=0; i<OrdersTotal(); i++) {

if (OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderType()<2) {

double SL = OrderStopLoss();

if OrderType()==0) {

switch (TralType) {

case 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);

break;

case 1: SL = High[1] - iATR(NULL,0,ATR,Period,1)*ATR_K;

break;

case 2: SL = iCustom(NULL,0, "VininI_HMAsound&amp",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);

break;

}

if (SL<OrderStopLoss())

SL = OrderStopLoss();

}

if (OrderType()==1) {

switch (TralType) {

case 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);

break;

case 1: SL = Low[1] + iATR(NULL,0,ATR,Period,1)*ATR_K;

break;

case 2: SL = iCustom(NULL,0, "VininI_HMAsound&amp",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);

break;

}

if (SL>OrderStopLoss())

SL = OrderStopLoss();

}

if (SL!=OrderStopLoss()) {

if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0))

error = true;

}

}

}

}

if (!error)

LBT = Time[0];

}

return (0);

}

//+------------------------------------------------------------------+

Автоматический трейдинг и тестирование торговых стратегий
Автоматический трейдинг и тестирование торговых стратегий
  • www.mql5.com
Выберите подходящую торговую стратегию и оформите подписку на нее в пару кликов. Все Сигналы сопровождаются подробной статистикой и графиками. Станьте Поставщиком торговых сигналов и продавайте подписку тысячам трейдеров по всему миру. Наш сервис позволит вам хорошо зарабатывать на прибыльной стратегии даже при небольшом стартовом капитале...
 
vkravtzov:

I'veadded trailing stop function to the Expert Advisor, and I've compiled it and got two errors. - I have lost my mind, I cannot figure out how to fix them to get an owl. However trades are closed according to old strategy after the price has touched the upper limit of the channel and the lower one, respectively. I guess something has to be changed here as well. - Give it back to the guys from the army of the DPR.


No need to spam.
 
Victor Nikolaev:
You shouldn't spam.

I apologise if I did something wrong. I still don't understand how I spammed... I think I addressed two messages to two comrades. Or is that not allowed? - My bad.