#SVM_b4_dd_pred5

Author:
#SVM_b4_dd_pred5
Miscellaneous
Uses files from the file systemIt reads information from a fileImplements a curve of type %1
0 Views
0 Downloads
0 Favorites
#SVM_b4_dd_pred5
//+------------------------------------------------------------------+
//|                                           
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#include <stderror.mqh>
/*
SL      TP
0.006	 0.008
0.006	 0
0.006	 0.006
0.005	 0.008

*/
#define COL1 1
#define COL2 1

//  5-10, 10-15 and 5-15
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Magenta
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Orange
#property indicator_color5 Aqua
#property indicator_color6 Blue
#property indicator_color7 Yellow
#property indicator_level1 0.0

//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
int NrBars = 1003;
int StopLoss=40;
int TakeProfit=40;
int Period1=PERIOD_M5;
int Period0=0;
int Buffers1=6;

//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
int FutureWindow1;
int FutureWindow2;
int FutureWindow3;
int FutureWindow4;
int FutureWindow5;
int FutureWindow6;
int FW;
//---- buffers
double VolBuffer1[];
double VolBuffer2[];
double VolBuffer3[];
double VolBuffer4[];
double VolBuffer5[];
double VolBuffer6[];
double VolBuffer7[];

string v[][COL1];
string vv[][COL2];
string f1,f2;
double dv[];
double dvv[];
   
string pr1(string sym1, int sig)
{
  int i,j,size,lin;
  int col=COL1;
  string nameData1 = "b4/dd/pred"+sig+"/"+sym1+".libsvm.prd";
  int handle=FileOpen(nameData1,FILE_CSV|FILE_READ,' ');
  if(handle<1)
    {
     Print("File"+nameData1+" not found, the last error is ", GetLastError());
     return(0);
    }
  else 
  {    
     FileSeek(handle, 0, SEEK_SET );
     i=0;
     while(!FileIsEnding(handle))
     {
       FileReadString(handle);
       i++;
     }
     size=i-1;//=755->0..754
     lin = size / col; //151 , usd lin=1564,col=5,size=7820
     ArrayResize(v,lin);
     FileSeek(handle, 0, SEEK_SET );
     for (i=0;i<lin;i++)
       for (j=0;j<col;j++)
         v[i][j]=FileReadString(handle);     
     FileClose(handle);    
  } 
  return (nameData1);
}


string pr2(string sym1, int sig)
{
  int i,j,size,lin;
  int col=COL2;
  string nameData1 = "b4/dd/pred"+sig+"/"+sym1+".libsvm.t";
  int handle=FileOpen(nameData1,FILE_CSV|FILE_READ,' ');
  if(handle<1)
    {
     Print("File"+nameData1+" not found, the last error is ", GetLastError());
     return(0);
    }
  else 
  {    
     FileSeek(handle, 0, SEEK_SET );
     i=0;
     while(!FileIsEnding(handle))
     {
       FileReadString(handle);
       i++;
     }
     size=i-1;//=755->0..754
     lin = size / col; //151 , usd lin=1564,col=5,size=7820
     ArrayResize(vv,lin);
     FileSeek(handle, 0, SEEK_SET );
     for (i=0;i<lin;i++)
       for (j=0;j<col;j++)
         vv[i][j]=FileReadString(handle);     
     FileClose(handle);    
  } 
  return (nameData1);
}


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|

int init()
  {
  if(NrBars==0)
    NrBars=Bars;//iBars(Symbol(),Period1);
  if (Period1==PERIOD_M5)
  {
     FutureWindow1 = 10;
     FutureWindow2 = 50;
     FutureWindow3 = 100;
     FutureWindow4 = 150;
     FutureWindow5 = 200;
     FutureWindow6 = 250;
  }
  else if(Period1==PERIOD_H1)
  {
     FutureWindow1 = 1;
     FutureWindow2 = 5;
     FutureWindow3 = 10;
     FutureWindow4 = 15;
     FutureWindow5 = 20;
     FutureWindow6 = 25;
  }
  else if(Period1==PERIOD_H4)
  {
     FutureWindow1 = 1;
     FutureWindow2 = 2;
     FutureWindow3 = 3;
     FutureWindow4 = 4;
     FutureWindow5 = 5;
     FutureWindow6 = 6;
 
  }

   IndicatorBuffers(7);
   
   SetIndexStyle(0,DRAW_ARROW,0,1);
   SetIndexBuffer(0, VolBuffer1);
   SetIndexLabel(0,"0");
   SetIndexArrow(0,158);
   
   SetIndexStyle(1,DRAW_ARROW,0,1);
   SetIndexBuffer(1, VolBuffer2);
   SetIndexLabel(1,"1");
   SetIndexArrow(1,158);
  
   SetIndexStyle(2,DRAW_ARROW,0,1);
   SetIndexBuffer(2, VolBuffer3);
   SetIndexLabel(2,"2");
   SetIndexArrow(2,158); 
   
   SetIndexStyle(3,DRAW_ARROW,0,1);
   SetIndexBuffer(3, VolBuffer4);
   SetIndexLabel(3,"3");
   SetIndexArrow(3,158);   

   SetIndexStyle(4,DRAW_ARROW,0,1);
   SetIndexBuffer(4, VolBuffer5);
   SetIndexLabel(4,"4");
   SetIndexArrow(4,158); 
      
   SetIndexStyle(5,DRAW_ARROW,0,1);
   SetIndexBuffer(5, VolBuffer6);
   SetIndexLabel(5,"5");
   SetIndexArrow(5,158); 
   
   SetIndexStyle(6,DRAW_ARROW,0,1);
   SetIndexBuffer(6, VolBuffer7);
   SetIndexLabel(6,"6");
   SetIndexArrow(6,158);    
   
   if(Buffers1==0)
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow1+" "+FutureWindow2+" "+FutureWindow3+" "+FutureWindow4+" "+FutureWindow5+" "+FutureWindow6);
   else if(Buffers1==1)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow1);     
     FW=FutureWindow1; 
   }  
   else if(Buffers1==2)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow2);     
     FW=FutureWindow2; 
   }       
   else if(Buffers1==3)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow3);     
     FW=FutureWindow3; 
   }       
   else if(Buffers1==4)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow4);     
     FW=FutureWindow4; 
   }       
   else if(Buffers1==5)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow5);     
     FW=FutureWindow5; 
   }       
   else if(Buffers1==6)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow6);     
     FW=FutureWindow6; 
   }  
     
///////////////////////////////////////////  
   f1=pr1(Symbol(), Buffers1-1);
   f2=pr2(Symbol(), Buffers1-1);  
   Print(f1,"-> ",v[0][0]," ",v[1][0]);
   Print(f2,"-> ",vv[0][0]," ",vv[1][0]); 
   ArrayResize(dv,ArraySize(v));
   for (int k=0;k<ArraySize(v);k++)
   {
     dv[k]= StrToDouble(v[k][0]);
   }    
   ArrayResize(dvv,ArraySize(vv));
   for (k=0;k<ArraySize(vv);k++)
   {
     dvv[k]= StrToInteger(vv[k][0]);
   }
/////////////////////////////////////////////     
     
   return(0);
  }


//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

  double x1,x2,x3,x4,x5,x6,x7;
  int pos=0;
///////////////////////////////////////////  
   f1=pr1(Symbol(), Buffers1-1);
   f2=pr2(Symbol(), Buffers1-1);  
   Print(f1,"-> ",v[0][0]," ",v[1][0]);
   Print(f2,"-> ",vv[0][0]," ",vv[1][0]); 
   ArrayResize(dv,ArraySize(v));
   for (int k=0;k<ArraySize(v);k++)
   {
     dv[k]= StrToDouble(v[k][0]);
   }    
   ArrayResize(dvv,ArraySize(vv));
   for (k=0;k<ArraySize(vv);k++)
   {
     dvv[k]= StrToInteger(vv[k][0]);
   }
/////////////////////////////////////////////     
   int dayshift=-1;

  pos=NrBars;
  while(pos>=0)
  //while(pos<=NrBars)
     {  
		//PREDICT
		
      if(Buffers1!=0)
      {
      
       double max=dv[ArrayMaximum(dv)];
       double min=dv[ArrayMinimum(dv)];
       datetime d2 = Time[pos];
       dayshift=ArrayBsearch(dvv,d2,WHOLE_ARRAY,0,MODE_ASCEND);
       datetime maxt2=dvv[ArrayMaximum(dvv,WHOLE_ARRAY,0)];
       if (
            (dayshift > 0) && 
            (d2<=maxt2) && 
            StrToDouble(v[dayshift][0])<7.1 && 
            StrToDouble(v[dayshift][0])>-7.1 &&
            (max > min)           
            )
       //if ((dayshift > 0))
       {       
         VolBuffer7[pos]=StrToDouble(v[dayshift][0])+0.1; //Open
       }
       else
         VolBuffer7[pos]=EMPTY_VALUE;     		
		}
 	   //pos++;
 	   pos--;
     }
     
    //InSigNormalize(VolBuffer1);
    //InSigNormalize(VolBuffer2);
    //InSigNormalize(VolBuffer3);

  //int lasterror=0;
  //string pict_file1 = "b4/dd/shots"+(Buffers1-1)+"/"+Symbol()+".gif";
  //string pict_file1="shots\\signal"+(Buffers1-1)+"\\better"+(Buffers1-1)+".gif";
  //---- make WindowScreenShot for further checking
  //if(!WindowScreenShot("shots\\tester"+ExtShotsCounter+".gif",640,480))
  //if(!WindowScreenShot(pict_file1,640,480))
  //  lasterror=GetLastError();
    
  //if(!SendFTP(pict_file1))
  //  lasterror=GetLastError();
  // Print("error(",lasterror,"): ");      
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---