#SVM_b4_dd_pred3

Download script
Author:
#SVM_b4_dd_pred3

This script is designed as a specialized technical indicator for the MetaTrader platform. Its primary purpose is to perform predictive analysis by cross-referencing real-time market data with pre-calculated external datasets.

Instead of relying solely on standard price action (like moving averages or RSI), this tool functions by "looking up" information from specific external prediction files stored on your system. Here is the logical breakdown of how it operates:

Data Integration

The script is designed to locate and open two specific types of external data files associated with the currency pair or asset you are currently viewing. It identifies these files based on the symbol name and a specific "prediction" signature. It essentially acts as a bridge, pulling in outside intelligence (likely generated by a machine learning model like LibSVM) and bringing it into your trading chart.

Dynamic Timeframe Adjustment

The tool is intelligent enough to adapt to different trading styles. Depending on which timeframe you choose to use (such as 5-minute, 1-hour, or 4-hour charts), the script automatically adjusts its "Future Windows." This ensures that the predictive data it pulls remains relevant and synchronized with the speed of the market you are currently observing.

The Selection Logic

Once the external data is loaded into the system, the script performs a specific logic check to decide where to place visual signals on your chart:

  1. Time Synchronization: It compares the current time on your chart against the timestamps provided in the external prediction files.
  2. Value Filtering: It looks for specific numerical values within that data. It specifically seeks out "neutral-to-active" zones (filtering for values between -7.1 and 7.1) while ensuring there is a clear distinction between maximum and minimum predicted movements.
  3. Signal Placement: If the market's current time aligns with these specific conditions in the external file, the script places a visual marker (an arrow) on your chart.

Visual Output

The indicator creates multiple "buffers," which allow it to display different layers of predictive data simultaneously. These are represented as arrows on the chart, providing the trader with visual cues based on where the external model predicts significant price action is likely to occur relative to the current market time.

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

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