I will write an advisor free of charge - page 127

 
Наджибулло Хабибов:
Hello , I have an EA that opens a trade in all currencies except gold , can you please help which code I need to add in the EA to open and gold ?

Not being moderated in the marketplace?

 
Наджибулло Хабибов:

lot 0.01 lot no stop loss no profit in the log do not open even though there is no error

In the window of symbols there are technical characteristics of each symbol, minimal/maximal volume, minimal level of stops

If there is no error it may be that the algorithm does not allow to open :)

 
VVT:

In the symbols window there are technical characteristics of each instrument; minimum/maximum volume, minimum stop level

If it does not print an error, maybe the algorithm does not allow to open :)

//--- ***

If you know the algorithm, can you please check the reason why it won't open for gold?

 
Наджибулло Хабибов:
//--- ***

If you know what the reason for not opening for gold is, can you please check it?

Insert the code correctly: use the Code button or alternatively: attach the file using the Attach file

 
Vladimir Karputov:

Insert the code correctly: use the button or alternatively: attach the file using the button

Yes, show what is taking part in the opening, spread, slippage or something else wrong

 
//--- Inputs
extern double Lots       = 0.1;      // лот
extern double KLot       = 1;        // умножение лота
extern double MaxLot     = 5;        // максимальный лот
extern double Profit     = 0;        // Профит в валюте
extern int StopLoss      = 0;        // Стоп Лось
extern int TakeProfit    = 0;        // ТейкПрофит
extern int BULevel       = 0;        // уровень БУ
extern int BUPoint       = 30;       // пункты БУ
extern int TrailingStop  = 0;        // трал
extern int StartHour     = 0;        // час начала торговли
extern int StartMin      = 30;       // минута начала торговли
extern int EndHour       = 23;       // час окончания торговли
extern int EndMin        = 30;       // минута окончания торговли
extern int Reverse       = 0;        // 1-реверс
extern int CloseSig      = 0;        // 1-закрытие по сигналу
extern int Slip          = 30;       // реквот
extern int Shift         = 1;        // на каком баре сигнал индикатора
extern int Magic         = 123;      // магик

extern string IndName    = "Aroow";
extern int SignalPeriod  = 9;

datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool TimeSession(int aStartHour,int aStartMinute,int aStopHour,int aStopMinute,datetime aTimeCur)
  {
//--- время начала сессии
   int StartTime=3600*aStartHour+60*aStartMinute;
//--- время окончания сессии
   int StopTime=3600*aStopHour+60*aStopMinute;
//--- текущее время в секундах от начала дня
   aTimeCur=aTimeCur%86400;
   if(StopTime<StartTime)
     {
      //--- переход через полночь
      if(aTimeCur>=StartTime || aTimeCur<StopTime)
        {
         return(true);
        }
     }
   else
     {
      //--- внутри одного дня
      if(aTimeCur>=StartTime && aTimeCur<StopTime)
        {
         return(true);
        }
     }
   return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
  {
   int r=0;
   color clr=Green;
   double sl=0,tp=0;

   if(type==1 || type==3 || type==5)
     {
      clr=Red;
      if(StopLoss>0)
         sl=NormalizeDouble(price+StopLoss*_Point,_Digits);
      if(TakeProfit>0)
         tp=NormalizeDouble(price-TakeProfit*_Point,_Digits);
     }

   if(type==0 || type==2 || type==4)
     {
      clr=Blue;
      if(StopLoss>0)
         sl=NormalizeDouble(price-StopLoss*_Point,_Digits);
      if(TakeProfit>0)
         tp=NormalizeDouble(price+TakeProfit*_Point,_Digits);
     }

   r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,_Digits),Slip,sl,tp,"",Magic,0,clr);
   return;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountTrades()
  {
   int count=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()<2)
               count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot()
  {
   double lot=Lots;
   
   if(CountTrades()>0)
     {
      lot=NormalizeDouble(lot*MathPow(KLot,CountTrades()),2);
     }
   if(lot>MaxLot)
      lot=Lots;
   return(lot);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Trailing()
  {
   bool mod;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(Bid-OrderOpenPrice()>TrailingStop*_Point)
                 {
                  if(OrderStopLoss()<Bid-TrailingStop*_Point)
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*_Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if((OrderOpenPrice()-Ask)>TrailingStop*_Point)
                 {
                  if((OrderStopLoss()>(Ask+TrailingStop*_Point)) || (OrderStopLoss()==0))
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*_Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void BU()
  {
   bool m;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*_Point) && OrderOpenPrice()>OrderStopLoss())
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*_Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*_Point) && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*_Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
  {
   bool cl;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==0 && (ot==0 || ot==-1))
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,_Digits),Slip,White);
              }
            if(OrderType()==1 && (ot==1 || ot==-1))
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,_Digits),Slip,White);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
  {
   double pr=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==0 && (ot==0 || ot==-1))
              {
               pr+=OrderProfit()+OrderCommission()+OrderSwap();
              }

            if(OrderType()==1 && (ot==1 || ot==-1))
              {
               pr+=OrderProfit()+OrderCommission()+OrderSwap();
              }
           }
        }
     }
   return(pr);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double blu = iCustom(NULL,0,IndName,SignalPeriod,4,Shift);
   double red = iCustom(NULL,0,IndName,SignalPeriod,5,Shift);
   double blu2 = iCustom(NULL,0,IndName,SignalPeriod,4,Shift+1);
   double red2 = iCustom(NULL,0,IndName,SignalPeriod,5,Shift+1);

   bool buy = blu<1000 && red2<1000;
   bool sell = red<1000 && blu2<1000;

   if(Reverse>0)
     {
      buy = red<1000 && blu2<1000;
      sell = blu<1000 && red2<1000;
     }

   if(BULevel>0)
      BU();
   if(TrailingStop>0)
      Trailing();
   if(AllProfit()>Profit && Profit>0)
      CloseAll();

   if(TimeSession(StartHour,StartMin,EndHour,EndMin,TimeCurrent()) && t!=Time[0])
     {
      if(buy)
        {
         PutOrder(0,Ask);
        }
      if(sell)
        {
         PutOrder(1,Bid);
        }
      t=Time[0];
     }

   if(CountTrades()>0 && CloseSig>0)
     {
      if(sell)
        {
         CloseAll(0);
        }
      if(buy)
        {
         CloseAll(1);
        }
     }

   Comment("\n blu: ",blu,
           "\n red: ",red,
           "\n All Profit: ",AllProfit());
  }
//+------------------------------------------------------------------+
VVT:

Yes, show me what is taking part in the opening there, the spread, the slippage or whatever else is wrong

 

Hi all!

There are 4 indicators and a library.

Two indicators are just needed for calculations, 2 are thrown on the chart.

I want to automate this process, only 3 conditions.... but i need to put everything in one file and i don't know what to do with the library.

Can someone do this?

 
Наджибулло Хабибов:

What does the following mean? Is it a spread and slippage? If yes, set the value higher than 100-150 for example

extern int BUPoint       = 30;       // пункты БУ
extern int Slip          = 30;       // реквот
 
VVT:

What does the following mean? Is it a spread and slippage? If yes, then set a higher value of 100-150 for example

yes it is, set these values depending on the technical characteristics of the instrument, i.e. the maximum spread of the instrument

 
VVT:

yes it is, set these values depending on the technical characteristics of the instrument, i.e. the maximum spread of the instrument is not o

does not work set 150 does not open

Reason: