Скачать MetaTrader 5
Авторизуйтесь или зарегистрируйтесь, чтобы добавить комментарий
MetaQuotes ID, что это? Узнай из статьи!
Gatis Alksnis
180
Gatis Alksnis 2011.06.08 13:28 

Pozalujsta pomogite reshitj problemu s sovetnikom.

Vidajot oshibku modify order ERROR!!!

modification of order #2612221 sell 1.00 GBPJPY. at 130.656 sl: 0.000 tp: 0.000 -> sl: 130.518 tp: 130.484 failed [Invalid S/L or T/P]

I na 4 znachnih koterovok vobshe modify nerabotaet!


//+------------------------------------------------------------------+
//|                                                        test3.mq4 |
//|                                      Gatis Alksnis © 2011 vs 109 |
//|                                                2xpoint@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Gatis Alksnis © 2011 vs 109"
#property link      "2xpoint@gmail.com"

 
#define MAGICMA  1777
 
extern double MaxRisk            = 0.0; // Risk percentage for the calculation of lot size (if 0 - does not work)
extern double Lots               = 1.0; // Fixed lot (if MaxRisk = 0)
extern int TakeProfit            = 13;  // Final profit
extern int MinProfit             = 9;   // Minimum profit
extern int ProfitStep            = 5;   // Profit Step 
extern double MinProfitPercent   = 0.8; // Percentage taking a minimum profit
extern double ProfitPercent      = 1.0; // Percentage of profit higher than the minimum
extern int TrailingStop          = 15;  // Work after taking MinProfit
int StopLost                     = 15;  // works before taking MinProfit
 
extern int Filter                = 31;  // Indicator Filter  

 
 
double MinLot;
double MaxLot;
int Spread;
double StartLots;
double NextProfit;
 
int slippage = 3;
bool UseAllTicks                 = false;
 
//+------------------------------------------------------------------+
int init() {
 Spread = MarketInfo(Symbol(),MODE_SPREAD);
 MinLot = MarketInfo(Symbol(),MODE_MINLOT);
 MaxLot = MarketInfo(Symbol(),MODE_MAXLOT);
 return(0);
}
//+------------------------------------------------------------------+
int deinit() {
   return(0);
}
 
double LotNormalize(double x) {
   x=MathFloor(x*100)/100;
   if (x > MaxLot) x = MaxLot;
   if (x < MinLot) x = MinLot;
   return(x);
}
 
//+------------------------------------------------------------------+
double Get_Lots() {
   double lot=Lots;
   if (MaxRisk > 0) {
    double RiskSumm = AccountFreeMargin()*MaxRisk;
    lot=RiskSumm/StopLost/100;
   }
   return(LotNormalize(lot));
}
 
 
//+------------------------------------------------------------------+
bool Signal_Stop_Buy() {
 return(false);
}
 
//+------------------------------------------------------------------+
bool Signal_Stop_Sell() {
 return(false);
}
 
//+------------------------------------------------------------------BUY-----+
bool Signal_Buy() {

 double LoMa = iLow(NULL,0,0);
 double LoHa = iHigh(NULL,0,1);
 double LoHa2 = iHigh(NULL,0,0);
 double red = iCustom(NULL, 0, "109",Filter, 1, 1);// Red
 double blu = iCustom(NULL, 0, "109",Filter, 2, 1);//Blue
 double blu2 = iCustom(NULL, 0, "109",Filter, 2, 2);//Blue
 
 if ((Close[1] > red) && (LoMa <=red) && (LoMa>blu))  {
  StopLost = blu2*Point;
  return(true);
 }
 
 return(false);
}
 
//+------------------------------------------------------------------SELL----+
bool Signal_Sell() {
 
 double HiMa = iHigh(NULL,0,0);
 double LoMa = iLow(NULL,0,1);
 double LoMa2 = iLow(NULL,0,0);
 double red = iCustom(NULL, 0, "109",Filter, 1, 1);// Red
 double blu = iCustom(NULL, 0, "109",Filter, 2, 1);//Blue
 double red2 = iCustom(NULL, 0, "109",Filter, 1, 2);// Red
 if ((Close[1] < blu) && (HiMa >=blu) && (HiMa <red)) {
  StopLost = red2*Point;
  return(true);
 }
 
 return(false);
}
 
//+------------------------------------------------------------------+
void CheckForOpen() {
   int res;
 
   
 
   if (Signal_Sell()) {
      StartLots = Get_Lots();
      NextProfit = Bid - MinProfit*Point;
      res=OrderSend(Symbol(),OP_SELL,StartLots,Bid,slippage,0,0,"",MAGICMA,0,Red);
      return;
   }
 
   if (Signal_Buy()) {
      StartLots = Get_Lots();
      NextProfit = Ask + MinProfit*Point;
      res=OrderSend(Symbol(),OP_BUY,StartLots,Ask,slippage,0,0,"",MAGICMA,0,Blue);
      return;
   }
}
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double SL,TP,lx;
   int profit;
 
 if ((!UseAllTicks) && (Volume[0]>1)) return;
 
   for(int i=0;i<OrdersTotal();i++) {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //---- check order type 
      if(OrderType()==OP_BUY) {
         if (Signal_Stop_Buy()) OrderClose(OrderTicket(),OrderLots(),Bid,slippage,White);
         else if (OrderStopLoss() == 0.0) {
          SL = NormalizeDouble(Bid - StopLost*Point,Digits);
          TP = NormalizeDouble(Ask + TakeProfit*Point,Digits);
          OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Blue);
         }
         else {
          if (Bid > NextProfit) {
           if (Bid < (OrderOpenPrice()+(MinProfit+ProfitStep/2)*Point)) lx = LotNormalize(StartLots*MinProfitPercent);
           else lx = LotNormalize(StartLots*ProfitPercent);
           OrderClose(OrderTicket(),lx,Bid,slippage,White);
           NextProfit = Bid + ProfitStep*Point;
          }
          else if (NextProfit > (OrderOpenPrice()+MinProfit*Point)) {
           if (TrailingStop > 0) {
            SL = NormalizeDouble((Bid - TrailingStop*Point),Digits);
            if (OrderStopLoss() < SL) OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Blue);
           }
          }
         }
         break;
      }
      if(OrderType()==OP_SELL) {
         if (Signal_Stop_Sell()) OrderClose(OrderTicket(),OrderLots(),Ask,slippage,White);
         else if (OrderStopLoss() == 0.0) {
          SL = NormalizeDouble(Ask + StopLost*Point,Digits);
          TP = NormalizeDouble(Bid - TakeProfit*Point,Digits);
          OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Blue);
         }
         else {
          if (Ask < NextProfit) {
           if (Ask > (OrderOpenPrice()-(MinProfit+ProfitStep/2)*Point)) lx = LotNormalize(StartLots*MinProfitPercent);
           else lx = LotNormalize(StartLots*ProfitPercent);
           OrderClose(OrderTicket(),lx,Ask,slippage,White);
           NextProfit = Bid - ProfitStep*Point;
          }
          else if (NextProfit < (OrderOpenPrice()-MinProfit*Point)) {
           if (TrailingStop > 0) {
            SL = NormalizeDouble(Ask + TrailingStop*Point,Digits);
            if (OrderStopLoss() > SL) OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Blue);
           }
          }
         }
         break;
      }
   }
}
 
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
   if(buys>0) return(buys);
   else       return(-sells);
  }
 
//+------------------------------------------------------------------+
void start()
  {
   if(Bars<100 || IsTradeAllowed()==false) return;
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else CheckForClose();
  }
//+------------------------------------------------------------------+
Gatis Alksnis
180
Gatis Alksnis 2011.06.08 13:28  

A vot i indikator

//+------------------------------------------------------------------+
//|                                            DynamicRS+Channel.mq4 |
//|                                 Copyright © 2007, Nick A. Zhilin |
//|                                                  rebus58@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Nick A. Zhilin"
#property link      "rebus58@mail.ru"
 
extern int Filter=31;
 
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Red
#property indicator_color3 Aqua
 
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("DynamicRS+Channel");
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| DynamicRS+Channel                                                |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
   double Channel;
 
//----
   i=Bars-counted_bars-1;
   while(i>=0)
     {
      if(High[i]<High[i+1] && High[i]<ExtMapBuffer1[i+1]-Filter*Point)   
          ExtMapBuffer1[i]=High[i];
      else if(Low[i]>Low[i+1] && Low[i]>ExtMapBuffer1[i+1]+Filter*Point)
          ExtMapBuffer1[i]=Low[i];
      else
          ExtMapBuffer1[i]=ExtMapBuffer1[i+1];
          
      ExtMapBuffer2[i]=ExtMapBuffer1[i]+Filter*Point;
      ExtMapBuffer3[i]=ExtMapBuffer1[i]-Filter*Point;
         
      i--;
     }
 
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
ilunga
744
ilunga 2011.06.08 14:29  
OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Blue);

добавьте везде NormalizeDouble:


OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(SL, Digits),NormalizeDouble(TP, Digits),0,Blue);
Gatis Alksnis
180
Gatis Alksnis 2011.06.08 14:49  
ilunga:

добавьте везде NormalizeDouble:



Sposibo, dobavil, na testere oshibku nepokazivaet bolshe.

Posmotrim, kak budet na realnoj torgovle.

Gatis Alksnis
180
Gatis Alksnis 2011.06.08 15:24  
2xpoint:

Sposibo, dobavil, na testere oshibku nepokazivaet bolshe.

Posmotrim, kak budet na realnoj torgovle.

Gatis Alksnis
180
Gatis Alksnis 2011.06.08 15:24  
2xpoint:

Sposibo, dobavil, na testere oshibku nepokazivaet bolshe.

Posmotrim, kak budet na realnoj torgovle.



Opjatj oshibka, no ja ponjal v chom zacepka,

Stop i Profit slishkom blisko, nado shtobi uchitival + Spread ! No kak eto dobavitj v sovetnik???

Pozalujsta pomogite!!!
Gatis Alksnis
180
Gatis Alksnis 2011.06.08 15:24  
ilunga:

добавьте везде NormalizeDouble:




Opjatj oshibka, no ja ponjal v chom zacepka,

Stop i Profit slishkom blisko, nado shtobi uchitival + Spread ! No kak eto dobavitj v sovetnik???

Pozalujsta pomogite!!!
Victor Nikolaev
Модератор
14078
Victor Nikolaev 2011.06.08 19:01  
2xpoint:


Opjatj oshibka, no ja ponjal v chom zacepka,

Stop i Profit slishkom blisko, nado shtobi uchitival + Spread ! No kak eto dobavitj v sovetnik???

Pozalujsta pomogite!!!

MarketInfo(Symbol(), MODE_STOPLEVEL);
Gatis Alksnis
180
Gatis Alksnis 2011.06.08 19:34  
Vinin:

MarketInfo(Symbol(), MODE_STOPLEVEL);

Sposibo, tolko kuda v kod evo vstavitj, i kak?

Ja ne programist, ja tolko uchusj :)

/
Авторизуйтесь или зарегистрируйтесь, чтобы добавить комментарий