Navigation:Home > Content >

optionslevel-v3.mq4

Time: 2016-02-19 | Download file:optionslevel-v3.mq4

//+------------------------------------------------------------------+
//|                                                 OptionsLevel.mq4 |
//|                                              Copyright 2016, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link      "http://www.forexsystems.biz"
#property version   "1.00"
#property strict
#property indicator_chart_window

input string NAME           = "0";
input string Time_Day       = "2016.07.28";
input double Call_1_Strike  = 1115;     // Call Strike Price 1
input double Call_1_Prem    = 7.6;      // Call Premium 1
input double Call_1_Vol     = 471;      // Call Volume 1
input double Call_1_OI      = 1513;     // Call Open Interest 1

input double Call_2_Strike  = 1120;     // Call Strike Price 2
input double Call_2_Prem    = 5.8;      // Call Premium 2
input double Call_2_Vol     = 419;      // Call Volume 2
input double Call_2_OI      = 3016;     // Call Open Interest 2

input double Call_3_Strike  = 1130;     // Call Strike Price 3
input double Call_3_Prem    = 3.1;      // Call Premium 3
input double Call_3_Vol     = 696;      // Call Volume 3
input double Call_3_OI      = 2738;     // Call Open Interest 3

input double Put_1_Strike   = 1080;     // Put Strike Price 1
input double Put_1_Prem     = 1.9;      // Put Premium 1
input double Put_1_Vol      = 694;      // Put Volume 1
input double Put_1_OI       = 2541;     // Put Open Interest 1

input double Put_2_Strike   = 1100;     // Put Strike Price 2
input double Put_2_Prem     = 6.2;      // Put Premium 2
input double Put_2_Vol      = 655;      // Put Volume 2
input double Put_2_OI       = 3148;     // Put Open Interest 2

input double Put_3_Strike   = 1090;     // Put Strike Price 3
input double Put_3_Prem     = 3.5;      // Put Premium 3
input double Put_3_Vol      = 286;      // Put Volume 3
input double Put_3_OI       = 7061;     // Put Open Interest 3

input double Multiplier     = 0.001;    // Premium Multiplier

input string Line_Inputs="**** Line Inputs *****";

input int    LineWidth      = 1;        // Line Width
input int    LineStyle      = 0;        // Line Style
input color  CallColor      = Navy;      // Call Line Color 
input color  PutColor       = Maroon;     // Put Line Color 

input string Text_Inputs="**** Text_Inputs *****";

input int    FontSize       = 6;        // Font Size
input string FontName       = "Lucida Console";  // Font Name  
input color  CallText       = Navy;     // Call Text Color
input color  PutText        = Maroon;    // Put Text Color 
input bool   ShowText       = true;     // Show Text

int LineStart,LineEnd;
datetime T,TD;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
 //
 TD=(int)StrToTime(Time_Day);
 LineStart=iBarShift(NULL,PERIOD_CURRENT,TD,1);
 LineEnd=iBarShift(NULL,PERIOD_CURRENT,TD+72000,0);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Put Line Function                                                |
//+------------------------------------------------------------------+
void PutTrendLine(string name,datetime time1,double price1,datetime time2,double price2,color clr)
  {name=NAME+name;
   ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price2);
//--- set line color 
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
//--- set the display style of the line 
   ObjectSetInteger(0,name,OBJPROP_STYLE,LineStyle);
//--- set line thickness 
   ObjectSetInteger(0,name,OBJPROP_WIDTH,LineWidth);
//--- enable (true) or disable (false) the mode of continuing the line display to the right 
   ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
   ObjectMove(0,name,1,TD+72000,price1);
   ObjectMove(0,name,0,TD,price1);
   if(ObjectGet(name,OBJPROP_SELECTED)>0)
   ObjectSet(name,OBJPROP_SELECTED,0);
  }
//+------------------------------------------------------------------+
//| Put Text Function                                                |
//+------------------------------------------------------------------+
void Text(string name,const string text,double price,datetime time,const color clr)
  {
//--- create a "Text" object 
   name=NAME+name;
   ObjectCreate(0,name,OBJ_TEXT,0,time,price);
//--- set the text
   ObjectSetString(0,name,OBJPROP_TEXT,text);
//--- set the font of the text
   ObjectSetString(0,name,OBJPROP_FONT,FontName);
//--- set the font size
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,FontSize);
//--- set the method binding
   ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_RIGHT_LOWER);
//--- set the color
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
   ObjectMove(0,name,1,TD,price);
   ObjectMove(0,name,0,TD,price);
   if(ObjectGet(name,OBJPROP_SELECTED)>0)
   ObjectSet(name,OBJPROP_SELECTED,0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
   if(_PeriodT){double pr=0;
  
// Call 1 
   if(Call_1_Strike>0)
     {
      pr=NormalizeDouble(Call_1_Strike*0.001+Call_1_Prem*Multiplier,_Digits);
      PutTrendLine("Call_1_"+(string)TD,Time[LineStart],pr,Time[LineEnd],pr,CallColor);
      if(ShowText)
         Text("Call 1 Text_"+(string)TD,""+DoubleToString(Call_1_Vol,0)+"/"+DoubleToString(Call_1_OI,0)+"/"+DoubleToString(Call_1_Prem,1),pr,Time[LineStart],CallText);
     }
     
// Call 2
   if(Call_2_Strike>0)
     {
      pr=NormalizeDouble(Call_2_Strike*0.001+Call_2_Prem*Multiplier,_Digits);
      PutTrendLine("Call_2_"+(string)TD,Time[LineStart],pr,Time[LineEnd],pr,CallColor);
      if(ShowText)
         Text("Call 2 Text_"+(string)TD,""+DoubleToString(Call_2_Vol,0)+"/"+DoubleToString(Call_2_OI,0)+"/"+DoubleToString(Call_2_Prem,1),pr,Time[LineStart],CallText);
     }

// Call 3
   if(Call_3_Strike>0)
     {
      pr=NormalizeDouble(Call_3_Strike*0.001+Call_3_Prem*Multiplier,_Digits);
      PutTrendLine("Call_3_"+(string)TD,Time[LineStart],pr,Time[LineEnd],pr,CallColor);
      if(ShowText)
         Text("Call 3 Text_"+(string)TD,""+DoubleToString(Call_3_Vol,0)+"/"+DoubleToString(Call_3_OI,0)+"/"+DoubleToString(Call_3_Prem,1),pr,Time[LineStart],CallText);
     }

// Put 1
   if(Put_1_Strike>0)
     {
      pr=NormalizeDouble(Put_1_Strike*0.001-Put_1_Prem*Multiplier,_Digits);
      PutTrendLine("Put_1_"+(string)TD,Time[LineStart],pr,Time[LineEnd],pr,PutColor);
      if(ShowText)
         Text("Put 1 Text_"+(string)TD,""+DoubleToString(Put_1_Vol,0)+"/"+DoubleToString(Put_1_OI,0)+"/"+DoubleToString(Put_1_Prem,1),pr,Time[LineStart],PutText);
     }
     
// Put 2
   if(Put_2_Strike>0)
     {
      pr=NormalizeDouble(Put_2_Strike*0.001-Put_2_Prem*Multiplier,_Digits);
      PutTrendLine("Put_2_"+(string)TD,Time[LineStart],pr,Time[LineEnd],pr,PutColor);
      if(ShowText)
         Text("Put 2 Text_"+(string)TD,""+DoubleToString(Put_2_Vol,0)+"/"+DoubleToString(Put_2_OI,0)+"/"+DoubleToString(Put_2_Prem,1),pr,Time[LineStart],PutText);
     }

// Put 3
   if(Put_3_Strike>0)
     {
      pr=NormalizeDouble(Put_3_Strike*0.001-Put_3_Prem*Multiplier,_Digits);
      PutTrendLine("Put_3_"+(string)TD,Time[LineStart],pr,Time[LineEnd],pr,PutColor);
      if(ShowText)
         Text("Put 3 Text_"+(string)TD,""+DoubleToString(Put_3_Vol,0)+"/"+DoubleToString(Put_3_OI,0)+"/"+DoubleToString(Put_3_Prem,1),pr,Time[LineStart],PutText);
     }

//--- return value of prev_calculated for next call
   ChartRedraw();T=iTime(NULL,PERIOD_D1,0);}
   return(rates_total);
  }
//+------------------------------------------------------------------+

Recommend