Скачать MetaTrader 5

Не получается исправить код, help please..

Авторизуйтесь или зарегистрируйтесь, чтобы добавить комментарий
Forex Trader
114283
Forex Trader  
Помогите доделать код вот этого пивотника:

Сейчас он кладет линии как горизонтальные, то есть на весь график ( в том числе и на предыдущие дни).
Мне это не нужно, а нужно чтоб линии - были лучами, и начинались Только! на начале японской сессии, как и установлено в индикаторе начало дня ( влево чтоб не продолжались). И вот эта вертикальная линия StartOf Period1440 чтобы вставала не на 00,00 сервера, а на тот же момент, какой сейчас установлен в нем для нового дня ( сервер альпари+2часа). (пс. У меня самого .. ничего не получается, к сожалению.Помогите, плз, в языке пока ориентируюсь очень плохо_)

//+------------------------------------------------------------------+
//|                                             DailyPivot_Shift.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 SaddleBrown
#property indicator_color2 Red
extern int  Controltimeframe = 0;
extern int  PeriodSignalMA = 1;
extern color StartOfPeriodColour =SaddleBrown;
extern int  TimeFrame = 1440;
extern bool times = true;
extern bool ShowAlert=true;
//---- input parameters
extern int       ShiftTime = 2;
extern int       ExtFormula= 0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

//+------------------------------------------------------------------+
//| Deleting lines function                                          |
//+------------------------------------------------------------------+
void DeleteLines()
  {
   ObjectDelete("Pivot_Line");
   ObjectDelete("R0.5_Line");
   ObjectDelete("R1.0_Line");
   ObjectDelete("R1.5_Line");
   ObjectDelete("R2.0_Line");
   ObjectDelete("R2.5_Line");
   ObjectDelete("R3.0_Line");
   ObjectDelete("S0.5_Line");
   ObjectDelete("S1.0_Line");
   ObjectDelete("S1.5_Line");
   ObjectDelete("S2.0_Line");
   ObjectDelete("S2.5_Line");
   ObjectDelete("S3.0_Line");
   ObjectDelete("Start of period"+TimeFrame);
   ObjectsRedraw();
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if(MathAbs(ShiftTime)>23) ShiftTime=0;
   //Comment("Shift Hours = ", ShiftTime);
   if(ShiftTime<0) ShiftTime+=24;
   ShiftTime*=3600;
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
//---- clear buffers when reinitializing
   if(ArraySize(ExtMapBuffer1)>0) ArrayInitialize(ExtMapBuffer1,0.0);
   if(ArraySize(ExtMapBuffer2)>0) ArrayInitialize(ExtMapBuffer2,0.0);
//---- set labels for DataWindow
   if(ExtFormula==0)
     {
      SetIndexLabel(0,"Pivot");
      SetIndexLabel(1,NULL);
     }
    else
     {
      SetIndexLabel(0,"Resistance");
      SetIndexLabel(1,"Support");
     }
//----
   DeleteLines();
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   DeleteLines();
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int    begin_bar, cnt,i;
   double hi=0, lo=0, cl;
   double yesterday_high, yesterday_low, yesterday_close, today_open;
   double P, S, R, S05, R05, S10, R10, S15, R15, S20, R20, S25, R25, S30, R30;
//---- test parameters
   if(ExtFormula<0 || ExtFormula>3) return(-1);
   if(Period()>=PERIOD_D1)          return(-1);
   if(counted_bars==Bars-1)         return(-1);
//---- set check beginning
   begin_bar=Bars-counted_bars;
//----
   int    new_day=TimeDayOfWeek(Time[begin_bar]-ShiftTime);
   for(cnt=MathMax(begin_bar,1440/Period()); cnt>=0; cnt--)
     {
      if(TimeDayOfWeek(Time[cnt]-ShiftTime)==new_day)
        {
         if(High[cnt]>hi) hi=High[cnt];
         if((Low[cnt]<lo)||(lo==0)) lo=Low[cnt];
         cl=Close[cnt];
        }
      else 
        {
         new_day=TimeDayOfWeek(Time[cnt]-ShiftTime);
         if(new_day>0 && new_day<6)
           {
            yesterday_close=cl;
            yesterday_high=hi;
            yesterday_low=lo;
            hi=0;lo=0;
            P = (yesterday_high + yesterday_low + yesterday_close) / 3;
           } 
         switch(ExtFormula)
           {
            case 1 :
               R = P + P - yesterday_low;
               S = P + P - yesterday_high;
               break;
            case 2 :
               R = P + yesterday_high - yesterday_low;
               S = P - yesterday_high + yesterday_low;
               break;
            case 3 :
               R = P + P - yesterday_low - yesterday_low + yesterday_high;
               S = P + P - yesterday_high - yesterday_high + yesterday_low;		
           }
        }  
       if(ExtFormula==0) ExtMapBuffer1[cnt]=P;
       else
         {
          ExtMapBuffer1[cnt]=R;
          ExtMapBuffer2[cnt]=S;
         }
     }
   P = NormalizeDouble((yesterday_high + yesterday_low + yesterday_close)/3,Digits);

   R10 = NormalizeDouble((2*P)-yesterday_low,Digits);
   S10 = NormalizeDouble((2*P)-yesterday_high,Digits);

   R05 = NormalizeDouble((P+R10)/2,Digits);
   S05 = NormalizeDouble((P+S10)/2,Digits);

   R20 = NormalizeDouble(P+(yesterday_high-yesterday_low),Digits);
   S20 = NormalizeDouble(P-(yesterday_high-yesterday_low),Digits);

   R15 = NormalizeDouble((R10+R20)/2,Digits);
   S15 = NormalizeDouble((S10+S20)/2,Digits);

   R30 = NormalizeDouble(2*P+(yesterday_high-2*yesterday_low),Digits);
   S30 = NormalizeDouble(2*P-(2*yesterday_high-yesterday_low),Digits);		

   R25 = NormalizeDouble((R20+R30)/2,Digits);
   S25 = NormalizeDouble((S20+S30)/2,Digits);

   ObjectCreate("Pivot_Line", OBJ_HLINE, 0, 0, P);
   ObjectSet("Pivot_Line", OBJPROP_COLOR, SaddleBrown);
   ObjectSet("Pivot_Line", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet("Pivot_Line", OBJPROP_WIDTH, 2);
   //ObjectSetText("Pivot_Line","Pivot "+DoubleToStr(P,Digits));

   ObjectCreate("R0.5_Line", OBJ_HLINE, 0, 0, R05);
   ObjectSet("R0.5_Line", OBJPROP_COLOR, Gold);
   ObjectSet("R0.5_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText("R0.5_Line",""+DoubleToStr(R05,Digits));

   ObjectCreate("R1.0_Line", OBJ_HLINE, 0, 0, R10);
   ObjectSet("R1.0_Line", OBJPROP_COLOR, SaddleBrown);
   ObjectSet("R1.0_Line", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSetText("R1.0_Line","R1");

   ObjectCreate("R1.5_Line", OBJ_HLINE, 0, 0, R15);
   ObjectSet("R1.5_Line", OBJPROP_COLOR, Gold);
   ObjectSet("R1.5_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText("R1.5_Line","   "+DoubleToStr(R15,Digits));

   ObjectCreate("R2.0_Line", OBJ_HLINE, 0, 0, R20);
   ObjectSet("R2.0_Line", OBJPROP_COLOR, SaddleBrown);
   ObjectSet("R2.0_Line", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSetText("R2.0_Line","     R2");

   ObjectCreate("R2.5_Line", OBJ_HLINE, 0, 0, R25);
   ObjectSet("R2.5_Line", OBJPROP_COLOR, Gold);
   ObjectSet("R2.5_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText("R2.5_Line","        "+DoubleToStr(R25,Digits));

   ObjectCreate("R3.0_Line", OBJ_HLINE, 0, 0, R30);
   ObjectSet("R3.0_Line", OBJPROP_COLOR, SaddleBrown);
   ObjectSet("R3.0_Line", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSetText("R3.0_Line","            R3");

   ObjectCreate("S0.5_Line", OBJ_HLINE, 0, 0, S05);
   ObjectSet("S0.5_Line", OBJPROP_COLOR, Gold);
   ObjectSet("S0.5_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText("S0.5_Line"," "+DoubleToStr(S05,Digits));

   ObjectCreate("S1.0_Line", OBJ_HLINE, 0, 0, S10);
   ObjectSet("S1.0_Line", OBJPROP_COLOR, SaddleBrown);
   ObjectSet("S1.0_Line", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSetText("S1.0_Line","S1 ");

   ObjectCreate("S1.5_Line", OBJ_HLINE, 0, 0, S15);
   ObjectSet("S1.5_Line", OBJPROP_COLOR, Gold);
   ObjectSet("S1.5_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText("S1.5_Line","   "+DoubleToStr(S15,Digits));

   ObjectCreate("S2.0_Line", OBJ_HLINE, 0, 0, S20);
   ObjectSet("S2.0_Line", OBJPROP_COLOR, SaddleBrown);
   ObjectSet("S2.0_Line", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSetText("S2.0_Line","     S2");

   ObjectCreate("S2.5_Line", OBJ_HLINE, 0, 0, S25);
   ObjectSet("S2.5_Line", OBJPROP_COLOR, Gold);
   ObjectSet("S2.5_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText("S2.5_Line","       "+DoubleToStr(S25,Digits));

   ObjectCreate("S3.0_Line", OBJ_HLINE, 0, 0, S30);
   ObjectSet("S3.0_Line", OBJPROP_COLOR, SaddleBrown);
   ObjectSet("S3.0_Line", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSetText("S3.0_Line","            S3 ");

//---------------"Start of period"------------
double rates_d1[2][6];
double today_opentime=0;
ArrayResize(rates_d1,cnt);
ArrayCopyRates(rates_d1, Symbol(), TimeFrame);
today_opentime=rates_d1[1+cnt][0];

 if(times){

if(ObjectFind("Start of period"+TimeFrame)!=0){
    ObjectCreate("Start of period"+TimeFrame,OBJ_VLINE,0,today_opentime,0);
}


ObjectSet("Start of period"+TimeFrame,OBJPROP_TIME1,today_opentime);
ObjectSet("Start of period"+TimeFrame,OBJPROP_COLOR,StartOfPeriodColour);
ObjectSet("Start of period"+TimeFrame,OBJPROP_STYLE,STYLE_DOT);
}
//---- force objects drawing
   ObjectsRedraw();
//----

//-------------------Alert---------------------
     
 double SignalMA_0 = iMA(NULL,Controltimeframe,PeriodSignalMA,0,MODE_SMA,PRICE_CLOSE,i); 
 double SignalMA_1 = iMA(NULL,Controltimeframe,PeriodSignalMA,0,MODE_SMA,PRICE_CLOSE,i+1);

  static int lta1;
//--------------Ressistens Level cross---------------//   
  if ( (SignalMA_0 > R10&& SignalMA_1<R10)||(SignalMA_0 < R10&& SignalMA_1>R10)  )
       if(lta1!=Time[i]){
          PlaySound( "titi.wav");
            lta1=Time[i]; }
//--  	
     if ( (SignalMA_0 > R20&& SignalMA_1<R20)||(SignalMA_0 < R20&& SignalMA_1>R20)  )
       if(lta1!=Time[i]){
          PlaySound( "titi.wav");
            lta1=Time[i]; }
   
//--
  if ( (SignalMA_0 > R30&& SignalMA_1<R30)||(SignalMA_0 < R30&& SignalMA_1>R30)  )
       if(lta1!=Time[i]){
          PlaySound( "all_done.wav");
            lta1=Time[i]; }
//-------------- Midlressistens Level cross---------------//            
 if ( (SignalMA_0 > R05&& SignalMA_1<R05)||(SignalMA_0 < R05&& SignalMA_1>R05)  )
       if(lta1!=Time[i]){
          PlaySound( "stops.wav");
            lta1=Time[i]; }
//--  	
     if ( (SignalMA_0 > R15&& SignalMA_1<R15)||(SignalMA_0 < R15&& SignalMA_1>R15)  )
       if(lta1!=Time[i]){
          PlaySound( "stops.wav");
            lta1=Time[i]; }
   
//--
  if ( (SignalMA_0 > R25&& SignalMA_1<R25)||(SignalMA_0 < R25&& SignalMA_1>R25)  )
       if(lta1!=Time[i]){
          PlaySound( "done.wav");
            lta1=Time[i]; }   
 
 
 //--------------Support Level cross---------------//   
  if ( (SignalMA_0 > S10&& SignalMA_1<S10)||(SignalMA_0 < S10&& SignalMA_1>S10)  )
       if(lta1!=Time[i]){
          PlaySound( "titi.wav");
            lta1=Time[i]; }
//--  	
     if ( (SignalMA_0 > S20&& SignalMA_1<S20)||(SignalMA_0 < S20&& SignalMA_1>S20)  )
       if(lta1!=Time[i]){
          PlaySound( "titi.wav");
            lta1=Time[i]; }
   
//--
  if ( (SignalMA_0 > S30&& SignalMA_1<S30)||(SignalMA_0 < S30&& SignalMA_1>S30)  )
       if(lta1!=Time[i]){
          PlaySound( "all_done.wav");
            lta1=Time[i]; }
//-------------- MidlSupport Level cross---------------//            
 if ( (SignalMA_0 > S05&& SignalMA_1<S05)||(SignalMA_0 < S05&& SignalMA_1>S05)  )
       if(lta1!=Time[i]){
          PlaySound( "stops.wav");
            lta1=Time[i]; }
//--  	
     if ( (SignalMA_0 > S15&& SignalMA_1<S15)||(SignalMA_0 < S15&& SignalMA_1>S15)  )
       if(lta1!=Time[i]){
          PlaySound( "stops.wav");
            lta1=Time[i]; }
   
//--
  if ( (SignalMA_0 > S25&& SignalMA_1<S25)||(SignalMA_0 < S25&& SignalMA_1>S25)  )
       if(lta1!=Time[i]){
          PlaySound( "done.wav");
            lta1=Time[i]; }             
              
//--------------Pivot Level cross---------------//   
    if(ShowAlert){
      if( (SignalMA_0 > P&& SignalMA_1<P)||(SignalMA_0 < P&& SignalMA_1>P)  ){
      
         if(lta1!=Time[i]){
            
           Alert ("Daily Pivot!!!("+Symbol()+Period()+"): Пробой");
            lta1=Time[i];
         }

      }

    }       


   return(0);
  }
//+------------------------------------------------------------------+



СПАСИБО!

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