Cross ema + send message with socket

To add comments, please log in or register
hikary3
30
hikary3  

I have simple indicator where there are 2 ema. When they cross i have singal but i need to send message with socket to localhost and idk how to do it, can anyone help me? I dont understend how to use socket in mql. Can sameone show me simple expample using sockets plox???


Something like that:

1. 2 ema crossing

2. the arrow appears

3. indicator send message eg. "1" with socket to localhost, port eg. 8080


My indicator

#property copyright "Moje"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+


#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red

input int FasterEMA = 8;
input int SlowerEMA = 20;

double BufferFast[];
double BufforSlow[];
double CrossUp[];
double CrossDown[];

#define FastIndicator 0
#define SlowIndicator 1

int OnInit()
  {
  SetIndexStyle(0, DRAW_LINE, 2, 3, clrRed);
  SetIndexBuffer(0, BufferFast);
  SetIndexLabel(0, "Fast");
  
  SetIndexStyle(1, DRAW_LINE, 2, 3, clrGreen);
  SetIndexBuffer(1, BufforSlow);
  SetIndexLabel(1, "Slow");
  
  SetIndexStyle(2, DRAW_ARROW, EMPTY);
  SetIndexArrow(2, 233);
  SetIndexBuffer(2, CrossUp);
   
  SetIndexStyle(3, DRAW_ARROW, EMPTY);
  SetIndexArrow(3, 234);
  SetIndexBuffer(3, CrossDown);
  
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,      // size of input time series
                 const int prev_calculated,  // bars handled in previous call
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[]         // Spread
                 )
   {
   
   int limit;
   double fastMAprev, slowMAprev, fastMAnow, slowMAnow, fastMAprev2, slowMAprev2, slowMA, fastMA;
   
   if(rates_total<=SlowerEMA){
      return(0);
   }
      
   limit = rates_total-prev_calculated;
   
   if(prev_calculated>0){
      limit++;
   }
   
   for(int i = 0; i<limit; i++){
       
       double o;
       int m,s,l,u,t;
       m=Time[i]+Period()*60-CurTime();
       o=m/60.0;
       s=m%60;
       m=(m-m%60)/60;
       l=0;
       u=1;
       t=2;
       
       
       fastMA = iMA(Symbol(), Period(), FasterEMA, 0, MODE_SMA, PRICE_CLOSE, i);
       slowMA = iMA(Symbol(), Period(), SlowerEMA, 0, MODE_SMA, PRICE_CLOSE, i);
      
      
       fastMAnow = iMA(NULL, 0, FasterEMA, 0, MODE_SMA, PRICE_CLOSE, i);
       fastMAprev = iMA(NULL, 0, FasterEMA, 0, MODE_SMA, PRICE_CLOSE, i+1);
       fastMAprev2 = iMA(NULL, 0, FasterEMA, 0, MODE_SMA, PRICE_CLOSE, i+1);
       
       slowMAnow = iMA(NULL, 0, SlowerEMA, 0, MODE_SMA, PRICE_CLOSE, i);
       slowMAprev = iMA(NULL, 0, SlowerEMA, 0, MODE_SMA, PRICE_CLOSE, i+1); 
       slowMAprev2 = iMA(NULL, 0, SlowerEMA, 0, MODE_SMA, PRICE_CLOSE, i+1); 
       
       if( (fastMAprev2<slowMAprev2) && (fastMAnow>slowMAnow)){
       CrossUp[i] = Low[i]  - 0;
       BufferFast[i]=fastMA;
       BufforSlow[i]=slowMA;
       if(s==0){
       Alert(Symbol() + "Call");
       }
       }
       
       else if((fastMAprev2>slowMAprev2) && (fastMAnow<slowMAnow)){
       CrossDown[i] = High[i] - 0;
       BufferFast[i]=fastMA;
       BufforSlow[i]=slowMA;
       if(s==0){
       Alert(Symbol() + "Put");
       }
       }

       else if(fastMA>slowMA){ // trend rosnacy 
       BufferFast[i]=fastMA;
       BufforSlow[i]=slowMA;
       }   
            
       else if(fastMA<slowMA){ //trend spadkowy
       BufferFast[i]=fastMA;
       BufforSlow[i]=slowMA;
       }
     
       }
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
To add comments, please log in or register