Write to file signal 1 or 0

Back to topics list To post a new topic, please log in or register
avatar
86
fly7680 2016.07.24 10:50
 
Hello everybody, I'm looking for a solution to write to a csv file, all the signals of my indicator.

When I get a signal,  write the result to a csv file, for a Sell if the candle closes Red I will have a result 1 else 0, for a buy signal if the candle closes Green will have a result 1 else 0.

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 Red
#property indicator_label1 "Sell"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 Lime
#property indicator_label2 "Buy"

//--- indicator buffers
double Buffer1[];
double Buffer2[];




extern string RSI             ="Setting RSI";
extern int Periodo            = 2;
extern double RSI_Max         = 70;
extern double RSI_Min         = 30;
datetime time_alert; //used when sending alert
extern bool Audible_Alerts = true;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | RSIalert @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      if(Audible_Alerts) Alert(type+" | RSIalert @ "+Symbol()+","+Period()+" | "+message);
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 159);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 159);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                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[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation  
      
      

      // Indicator Buffer 1 Sell
      if(iRSI(NULL, PERIOD_CURRENT, Periodo, PRICE_CLOSE, 1+i) > RSI_Max 
         )

        {
         Buffer1[i] = High[i] + 1 * myPoint; // if close Red write to file 1 else 0
        }
      
        
      //Indicator Buffer 2 Buy
      if(iRSI(NULL, PERIOD_CURRENT, Periodo, PRICE_CLOSE, 1+i) < RSI_Min   
         )

        {
         Buffer2[i] = Low[i] - 1 * myPoint; // if close Lime write to file 1 else 0  
        }  
      }
      
  return(0);
  } 
   
  
   
//+------------------------------------------------------------------+
avatar
164
rod178 2016.07.24 14:21 #
 
avatar
12985
WHRoeder 2016.07.24 15:57 #
 
fly7680 I'm looking for a solution to write to a csv file,
  1. Perhaps you should read the manual.
  2. learn to code it, or pay someone. We're not going to code it FOR you.
    We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.

avatar
86
fly7680 2016.07.24 20:38 #
 
Thank you and sorry for my post, I will study better code.
Back to topics list  

To add comments, please log in or register