Почему советник глючит? - страница 2

 
Alexsandr San:

вот начало - дальше можешь химичить 


Александр огромнейшее вам спасибо за помощь!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 MacdCurrent=iCustom(Symbol(), PERIOD_CURRENT,"CUSTOM",ADXperiod1,ADXperiod2,PRICE_HIGH,0);
   MacdPrevious=iCustom(Symbol(), PERIOD_CURRENT,"CUSTOM",ADXperiod1,ADXperiod2,PRICE_LOW,1);
   SignalCurrent=iCustom(Symbol(), PERIOD_CURRENT,"CUSTOM",ADXperiod1,ADXperiod2,PRICE_HIGH,0);
SignalPrevious=iCustom(Symbol(), PERIOD_CURRENT,"CUSTOM",ADXperiod1,ADXperiod2,PRICE_LOW,1); 
 MacdCurrent=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
   MacdPrevious=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,1);
   SignalCurrent=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
   SignalPrevious=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,1);
  

С моим индюком не открывает сделок!!

и так тоже как у тебя не отрывает..... что опять не слава Богу у меня??????????

 

Вот слепил свое творение НО открывает сразу два ордера сел и бай!!!!!

Как и что мне нужно изменить что бы работало с ордерами как нужно?


//-------------------------------------------------------------------
extern ENUM_TIMEFRAMES timeframe_RSI = 60;
extern int    level_buy    = PRICE_HIGH;
extern int    level_sell   = PRICE_LOW;

extern double Lot          = 0.1;
extern double K_Martin     = 2.5;

extern int    Stoploss     = 0,
              Takeprofit   = 24;
extern int    OrdersClose  = 5;

extern int    Magic        = 0;
extern int    DigitsLot    = 2;
extern int    slippage     = 3;
//----------------
input int ADXperiod1 = 20;
input int ADXperiod2 = 28;

//----------------
//-------------------------------------------------------------------
string AC;
datetime OpenTime;
double MINLOT,MAXLOT;
//-------------------------------------------------------------------
void OnTick()
{
   if (!IsTradeAllowed())
   {
      DrawLABEL("Торговля",0,0,0,Red,"Торговля запрещена");
      return;
   }
   else DrawLABEL("Торговля",0,0,0,Lime,"Торговля разрешена");

   //---

   double STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);
   //---
   double OSL,OTP,OOP,SL,TP,Profit=0;
   int b=0,s=0,tip;
   for (int i=0; i<OrdersTotal(); i++)
   {    
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderSymbol()==Symbol() && Magic==OrderMagicNumber())
         {
            tip = OrderType();
            OSL = NormalizeDouble(OrderStopLoss(),Digits);
            OTP = NormalizeDouble(OrderTakeProfit(),Digits);
            OOP = NormalizeDouble(OrderOpenPrice(),Digits);
            SL=OSL;TP=OTP;
            Profit+=OrderProfit()+OrderCommission()+OrderSwap();
            if (tip==OP_BUY)            
            {  
               b--;  
               if (OSL==0 && Stoploss!=0)
               {
                  if ((Bid-NormalizeDouble(OOP - Stoploss * Point,Digits)) / Point>=STOPLEVEL) SL = NormalizeDouble(OOP - Stoploss * Point,Digits);
               }
               if (OTP==0 && Takeprofit!=0)
               {
                  if ((NormalizeDouble(OOP + Takeprofit * Point,Digits)-Ask) / Point>=STOPLEVEL) TP = NormalizeDouble(OOP + Takeprofit * Point,Digits);
               }
               if (SL != OSL || TP != OTP)
               {  
                  if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error OrderModify ",GetLastError());
               }
            }                                        
            if (tip==OP_SELL)        
            {
               s--; 
               if (OSL==0 && Stoploss!=0)
               {
                  if ((NormalizeDouble(OOP + Stoploss * Point,Digits)-Ask) / Point>=STOPLEVEL) SL = NormalizeDouble(OOP + Stoploss   * Point,Digits);
               }
               if (OTP==0 && Takeprofit!=0)
               {
                  if ((Bid-NormalizeDouble(OOP - Takeprofit * Point,Digits)) / Point>=STOPLEVEL) TP = NormalizeDouble(OOP - Takeprofit * Point,Digits);
               }
               if (SL != OSL || TP != OTP)
               {  
                  if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error OrderModify ",GetLastError());
               }
            }
         }
      }
   }
  
  
   //---
  
   double AB = AccountBalance();
  
   //---
  
   DrawLABEL("Balance"        ,1,5,0,clrGreen,StringConcatenate("Balance ",DoubleToStr(AB,2),AC));
   DrawLABEL("Equity"         ,1,5,0,clrGreen,StringConcatenate("Equity ",DoubleToStr(AccountEquity(),2),AC));
   DrawLABEL("FreeMargin"     ,1,5,0,clrGreen,StringConcatenate("FreeMargin ",DoubleToStr(AccountFreeMargin(),2),AC));
   DrawLABEL("Take"           ,1,5,0,Color(Profit>0,Lime,Red),StringConcatenate("Profit ",DoubleToStr(Profit,2),AC));
  
   double Lots=0,RSI1=0,RSI0=0;
   if (b+s==0)
   {
      RSI0= iCustom(Symbol(), PERIOD_CURRENT, "CUSTOM",ADXperiod1,ADXperiod2,PRICE_HIGH,0);
      RSI1= iCustom(Symbol(), PERIOD_CURRENT, "CUSTOM",ADXperiod1,ADXperiod2,PRICE_LOW,0);
   }
   else return;

   //---
   if (RSI0>=level_buy && RSI1<=level_buy) 
   {
      Lots=LOT();

      if (Lots>MAXLOT) Lots = MAXLOT;
      if (Lots<MINLOT) Lots = MINLOT;
      
      if(SendOrder(OP_BUY, Lots, NormalizeDouble(Ask,Digits)))OpenTime=iTime(NULL,timeframe_RSI,1);
   }

   //---
  
   if (RSI1<=level_sell && RSI0>=level_sell) 
   {
      Lots=LOT();

      if (Lots>MAXLOT) Lots = MAXLOT;
      if (Lots<MINLOT) Lots = MINLOT;

      if(SendOrder(OP_SELL, Lots, NormalizeDouble(Bid,Digits))) OpenTime=iTime(NULL,timeframe_RSI,2);
   }
}
//------------------------------------------------------------------
bool SendOrder(int tip, double lots, double price, double sl=0, double tp=0)
{
   if (tip<2)
   {
      if (AccountFreeMarginCheck(Symbol(),tip,lots)<0)
      {
         Alert("Недостаточно средств");
         return(0);
      }
   }
   for (int i=0; i<1; i++) 
   {    
      if (OrderSend(Symbol(),tip, lots,price,slippage,sl,tp,NULL,Magic,0,clrNONE)!=-1) return(1);
         Alert(" попытка ",i," Ошибка открытия ордера ",Strtip(tip)," <<",(GetLastError()),">>  lot=",lots,"  pr=",price," sl=",sl," tp=",tp);
      Sleep(500);
      RefreshRates();
      if (IsStopped()) return(0);
   }
   return(0);
}
//------------------------------------------------------------------ 

string Strtip(int tip)
{
   switch(tip)
   {
   case OP_BUY:
      return("BUY");
   case OP_SELL:
      return("SELL");
   case OP_BUYSTOP:
      return("BUYSTOP");
   case OP_SELLSTOP:
      return("SELLSTOP");
   case OP_BUYLIMIT:
      return("BUYLIMIT");
   case OP_SELLLIMIT:
      return("SELLLIMIT");
   }
   return("error"); 
} 
//------------------------------------------------------------------
void OnDeinit(const int reason)
{
   if (!IsTesting())
   {
      ObjectsDeleteAll(0);
   }
}
//-------------------------------------------------------------------
void DrawLABEL(string name, int CORNER, int X, int Y, color clr, string Name)
{
   if (ObjectFind(name)==-1)
   {
      ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
      ObjectSet(name, OBJPROP_CORNER, CORNER);
      ObjectSet(name, OBJPROP_XDISTANCE, X);
      ObjectSet(name, OBJPROP_YDISTANCE, Y);
   }
   ObjectSetText(name,Name,10,"Arial",clr);
}
//+------------------------------------------------------------------+
int OnInit()
{
   MINLOT = MarketInfo(Symbol(),MODE_MINLOT);
   MAXLOT = MarketInfo(Symbol(),MODE_MAXLOT);
   Comment("Start ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
  
   AC = StringConcatenate(" ", AccountCurrency());
  
   int Y=15;
   DrawLABEL("Торговля"  ,1,5,Y,Red,"Торговля ");Y += 20;
   DrawLABEL("Balance"   ,1,5,Y,clrGreen,StringConcatenate("Balance ",DoubleToStr(AccountBalance(),2),AC));Y += 15;
   DrawLABEL("Equity"    ,1,5,Y,clrGreen,StringConcatenate("Equity ",DoubleToStr(AccountEquity(),2),AC));Y += 15;
   DrawLABEL("FreeMargin",1,5,Y,clrGreen,StringConcatenate("FreeMargin ",DoubleToStr(AccountFreeMargin(),2),AC));Y += 30;

   DrawLABEL("Take"           ,1,5,Y,Lime,"Profit ");Y += 20;
  
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
color Color(bool P,color a,color b)
{
   if (P) return(a);
   else return(b);
}
//------------------------------------------------------------------
double LOT()
{
   int n=0;
   double OL=Lot;
   for (int j = OrdersHistoryTotal()-1; j >= 0; j--)
   {
      if (OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
         {
            if (OrderProfit()<0)
            {
               if (n==0) OL=NormalizeDouble(OrderLots()*K_Martin,DigitsLot);
               n++;
               if (n>=OrdersClose) {Comment("1");return(Lot);}
            }
            else
            {
               if (n==0) {Comment("2");return(Lot);}
               else {Comment("3");return(OL);}
            }
         }
      }
   }
   return(OL);
}
//------------------------------------------------------------------
 
Сергей Дыбленко:

Вот слепил свое творение НО открывает сразу два ордера сел и бай!!!!!

Как и что мне нужно изменить что бы работало с ордерами как нужно?


Уря!!!! я нашел свою ошибку!!!

Вот где была собака зарыта!


if (RSI0>=level_buy && RSI1<=level_buy) 
   {
      Lots=LOT();

      if (Lots>MAXLOT) Lots = MAXLOT;
      if (Lots<MINLOT) Lots = MINLOT;
      
      if(SendOrder(OP_BUY, Lots, NormalizeDouble(Ask,Digits)))OpenTime=iTime(NULL,timeframe_RSI,1);
   }

   //---
  
   if (RSI1<=level_sell && RSI0>=level_sell)