#SVM_b4_dd_pred0

Download script
Author:
#SVM_b4_dd_pred0

This script functions as a specialized predictive analytics tool designed to identify specific market conditions by cross-referencing historical data with pre-calculated external files. Instead of relying solely on live price action, it acts as a bridge between your trading platform and a separate machine learning or statistical model (specifically referencing "libsvm" files).

Core Logic Overview

The script operates by retrieving data from specialized prediction files stored on your local system. It looks for these files based on the specific currency pair you are viewing and the timeframe you have selected.

Here is the step-by-step breakdown of how it processes this information:

1. Data Retrieval & Mapping When the script initializes, it searches for external data files (formatted as CSVs). These files contain "predictions" that have been generated elsewhere. The script automatically organizes these predictions into various categories based on different "Time Windows." For example, depending on whether you are viewing a 5-minute chart versus a 4-hour chart, the script adjusts its logic to look at different horizontal slices of data.

2. Dynamic Time Synchronization The script performs a sophisticated search to align historical timeframes with the data provided in those external files. It looks at the current bar on your chart and attempts to find the corresponding entry in the prediction file. It does this by searching for specific date and time stamps to ensure that the prediction being displayed matches the exact moment in history you are looking at.

3. Filtering Criteria The logic does not display a signal for every data point it finds. It applies a set of "filters" to the retrieved information before showing anything on your chart. To trigger a visual signal, the following conditions must be met simultaneously:

  • Value Range: The prediction value must fall within a specific neutral range (between -7.1 and 7.1). This ensures that extreme outliers or "noisy" data points are ignored.
  • Trend Validation: The script checks if the maximum predicted value is greater than the minimum, ensuring there is a discernible movement.
  • Time Validity: It confirms that the data point exists within a valid time boundary established by the external file.

4. Visual Output Once all conditions are satisfied, the script places a visual marker (an arrow) on your chart at the specific historical position. This tells the trader: "Based on the external model's data, this was a validated point of interest."

Summary for the User

Essentially, you aren't just looking at an indicator that calculates math on the fly; you are looking at a visualizer for a pre-calculated model. It pulls "answers" from external files and paints them onto your chart only when they meet specific safety and logic requirements.

Miscellaneous
Uses files from the file systemIt reads information from a fileImplements a curve of type %1
10 Views
0 Downloads
0 Favorites
#SVM_b4_dd_pred0
//+------------------------------------------------------------------+
//|                                           
//+------------------------------------------------------------------+
#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=1;

//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
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