Download MetaTrader 5

Time display problem while trades taken place

To add comments, please log in or register
Have you made a screenshot in MetaTrader? Share it with friends!
krishna Gaherwar
1838
krishna Gaherwar 2013.04.10 10:22 
//+------------------------------------------------------------------+
//|  Getting a timeframe as a line                                   |
//+------------------------------------------------------------------+
string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
  {
//----
   return(StringSubstr(EnumToString(timeframe),7,-1));
//----
  }
//+------------------------------------------------------------------+   
//| SlopeDirectionLine indicator initialization function             | 
//+------------------------------------------------------------------+ 
void OnInit()
  {
//---- Initialization of variables of the start of data calculation
   LengthX=int(Length1/2);
   LengthR=int(MathMax(MathSqrt(Length1),1));
   min_rates_=+XMA1.GetStartBars(MA_Method1,Length1,Phase1);
   min_rates_total=min_rates_+XMA1.GetStartBars(MA_Method2,LengthR,Phase2);

//---- Initialization of the vertical shift
   dPriceShift=_Point*PriceShift;

//---- set dynamic array as an indicator buffer
   SetIndexBuffer(0,IndBuffer,INDICATOR_DATA);
//---- setting dynamic array as a color index buffer   
   SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX);

//---- moving the indicator 1 horizontally
   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//---- performing the shift of beginning of indicator drawing
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//--- Create label to display in DataWindow
   PlotIndexSetString(0,PLOT_LABEL,"IndBuffer");
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//---- initializations of variable for indicator short name
   string shortname;
   string Smooth2=XMA1.GetString_MA_Method(MA_Method2);
   StringConcatenate(shortname,"TrendSignal(",Length1,", ",LengthR,", ",Smooth2,")");
//---- creating name for displaying if separate sub-window and in tooltip
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);

//---- determine the accuracy of displaying indicator values
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//---- end of initialization
  }
//+------------------------------------------------------------------+ 
//| SlopeDirectionLine iteration function                            | 
//+------------------------------------------------------------------+ 
int OnCalculate(
                const int rates_total,    // amount of history in bars at the current tick
                const int prev_calculated,// amount of history in bars at the previous tick
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]
                )
  {
//---- checking the number of bars to be enough for calculation
   if(rates_total<min_rates_total) return(0);

//---- declaration of variables with a floating point  
   double price,line,xline;
//---- Declaration of integer variables and getting the bars already calculated
   int first,bar,clr;

//---- calculation of the starting number first for the bar recalculation loop
   if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator
      first=0; // starting number for calculation of all bars
   else first=prev_calculated-1; // starting number for calculation of new bars

//---- Main calculation loop of the indicator
   for(bar=first; bar<rates_total && !IsStopped(); bar++)
     {
      price=PriceSeries(IPC,bar,open,low,high,close);

      line=XMA1.XMASeries(0,prev_calculated,rates_total,MA_Method1,Phase1,Length1,price,bar,false);
      line=2*XMA2.XMASeries(0,prev_calculated,rates_total,MA_Method1,Phase1,LengthX,price,bar,false)-line;
      xline=XMA3.XMASeries(min_rates_,prev_calculated,rates_total,MA_Method2,Phase2,LengthR,line,bar,false);
      //----       
      IndBuffer[bar]=xline+dPriceShift;
     }

//---- correction of the first variable value
   if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator
      first=min_rates_total-1; // starting index for calculation of all bars

//---- Main loop of the signal line coloring
   for(bar=first; bar<rates_total; bar++)
     {
      clr=1;
      ColorIndBuffer[bar]=1;
      if(IndBuffer[bar-1]<IndBuffer[bar]) clr=2;
      if(IndBuffer[bar-1]>IndBuffer[bar]) clr=0;
      ColorIndBuffer[bar]=clr;

      if(bar==rates_total-1-SignalBar)
        {
         if(ColorIndBuffer[bar-1]!=2 && clr==2)
           {
            datetime SignalTime=TimeCurrent();
            if(On_Play_Sound) PlaySound(NameFileSound);
            string period=GetStringTimeframe(Period());
            string comment,sTime=" CurrTime="+TimeToString(SignalTime,TIME_MINUTES);
            StringConcatenate(comment,CommentSirName,Symbol(),period," ",sTime," Buy signal!");
            if(On_Alert) Alert(comment);
            if(On_Push) SendNotification(comment);
            if(On_Email) SendMail(CommentSirName+Symbol()+period,comment);
           }
           
         if(ColorIndBuffer[bar-1]!=0 && clr==0)
           {
            datetime SignalTime=TimeCurrent();
            if(On_Play_Sound) PlaySound(NameFileSound);
            string period=GetStringTimeframe(Period());
            string comment,sTime=" CurrTime="+TimeToString(SignalTime,TIME_MINUTES);
            StringConcatenate(comment,CommentSirName,Symbol(),period," ",sTime," Sell signal!");
            if(On_Alert) Alert(comment);
            if(On_Push) SendNotification(comment);
            if(On_Email) SendMail(CommentSirName+Symbol()+period,comment);
           }
        }
     }
//----     
   return(rates_total);
  }
//+------------------------------------------------------------------+

Kindly suggest me time is not matching with actual time. Examples. if CRUDEAPRM6 CurrTime+10.18 Sell here in india 1.50 afternoon time is going on.So please suggest or correct or guide me.

 

thanks

Krishna 

Kourosh Davallou
40184
Kourosh Davallou 2013.04.10 10:43  
saibabashirdi:

Kindly suggest me time is not matching with actual time. Examples. if CRUDEAPRM6 CurrTime+10.18 Sell here in india 1.50 afternoon time is going on.So please suggest or correct or guide me.

 

thanks

Krishna 

Hi Krishna, You can send all the code for your problem

 I can help you.

SignalTime=TimeCurrent(); //  server time

 or SignalTime=TimeLocal();// local time

 or SignalTime=TimeGMT();// GMT time
krishna Gaherwar
1838
krishna Gaherwar 2013.04.10 10:54  
kourosh1347:

Hi Krishna, You can send all the code for your problem

 I can help you.

How can i put this code.

Guide me in which line Kourosh

thanks for your co operation

krishna 

Alain Verleyen
Moderator
30721
Alain Verleyen 2013.04.10 11:06  
saibabashirdi:

How can i put this code.

Guide me in which line Kourosh

thanks for your co operation

krishna 

Is it your code you publish in the first comment ? If yes, you don't have difficulty to use what Kourosh proposed.
krishna Gaherwar
1838
krishna Gaherwar 2013.04.10 11:08  
angevoyageur:
Is it your code you publish in the first comment ? If yes, you don't have difficulty to use what Kourosh proposed.

Thanks 

 

krishna 

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.04.10 11:50  
angevoyageur:
Is it your code you publish in the first comment ?
No,  https://www.mql5.com/en/code/1489
SlopeDirectionLine
SlopeDirectionLine
  • votes: 12
  • 2013.01.30
  • Nikolay Kositsin
  • www.mql5.com
The SlopeDirectionLine trend indicator with the ability to change the algorithms of averaging and triggering alerts, push notifications and sending e-mail messages
Alain Verleyen
Moderator
30721
Alain Verleyen 2013.04.10 12:10  
I thought so. Would he not take the code from someone else to publish it on the Market and Signals ? Clearly he does not know programming.
Kourosh Davallou
40184
Kourosh Davallou 2013.04.10 12:40  

if you want only display local time  you can change below :

datetime SignalTime=TimeCurrent();
 if(On_Play_Sound) PlaySound(NameFileSound);
 string period=GetStringTimeframe(Period());
 string comment,sTime=" CurrTime="+TimeToString(SignalTime,TIME_MINUTES)+" local time ="+TimeToString(TimeLocal()),TIME_MINUTES) ;
            
            StringConcatenate(comment,CommentSirName,Symbol(),period," ",sTime," Buy signal!");
            if(On_Alert) Alert(comment);
            if(On_Push) SendNotification(comment);
            if(On_Email) SendMail(CommentSirName+Symbol()+period,comment);
To add comments, please log in or register