#SVM_b4_dd_pred1

Download script
Author:
#SVM_b4_dd_pred1

This script is designed as a custom technical indicator for the MetaTrader platform. It functions by retrieving and processing external data files to provide visual signals on a trading chart. Instead of calculating standard moving averages or oscillators purely from live price action, this tool relies on "prediction" data stored in external files.

Data Retrieval and Processing

The core logic of the script involves connecting to specific external files (formatted as CSVs) located in a dedicated folder on your computer. These files contain pre-calculated values related to various timeframes and symbols.

When the script runs, it performs the following steps:

  • File Identification: It identifies which data files to read based on the current currency symbol and the specific configuration settings (such as the "Future Window" parameters).
  • Data Mapping: It pulls a list of historical dates and corresponding numerical values from these files. These values are treated as "predictions" or external signals.
  • Conversion: The script converts raw text data from these files into usable numerical formats (doubles and integers) so the platform can interpret them correctly.

Signal Logic

The indicator works by scanning the historical bars on your chart and comparing the current time against the dates stored in the external data files. It looks for specific criteria to trigger a visual signal:

  1. Time Matching: It searches the external data to find the entry that most closely matches the current bar's date.
  2. Value Filtering: Once a match is found, it checks if the numerical value falls within a specific "neutral" range (roughly between -7.1 and 7.1).
  3. Trend Validation: It ensures that the highest predicted value in the dataset is greater than the lowest, confirming there is active data to display.

Visual Output

If all the conditions above are met—meaning the script finds a valid, filtered prediction for that specific point in time—it places an arrow on the chart (specifically on "Buffer 7"). This allows the trader to see exactly where the external predictive model suggests a signal should occur.

Timeframe Adaptability

The script is programmed to adjust its "Future Window" settings automatically based on the timeframe you are currently viewing (e.g., M5, H1, or H4). This ensures that the look-ahead and data windows remain proportional to the speed of the market regardless of whether you are day trading or swing trading.

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

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