AutoTradeLevels

Author: Copyright © 2017, Nikolay Kositsin
2 Views
0 Downloads
0 Favorites
AutoTradeLevels
ÿþ//+------------------------------------------------------------------+ 

//|                                              AutoTradeLevels.mq5 | 

//|                               Copyright © 2017, Nikolay Kositsin | 

//|                              Khabarovsk,   farria@mail.redcom.ru | 

//+------------------------------------------------------------------+ 

#property copyright "Copyright © 2017, Nikolay Kositsin"

#property link "farria@mail.redcom.ru"

//--- =><5@ 25@A88 8=48:0B>@0

#property version   "1.00"

#property description "=48:0B>@ ?@>872>48B ?>4<5=C 2A5E 7=0G:>2 A>25@HQ==KE A45;>: ?>:C?:8 8 ?@>4068"

//+------------------------------------------------+ 

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0                |

//+------------------------------------------------+ 

//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5

#property indicator_chart_window 

#property indicator_buffers 0

#property indicator_plots   0

//+------------------------------------------------+ 

//|  1JO2;5=85 :>=AB0=B                           |

//+------------------------------------------------+

#define RESET               0                   // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AG5B 8=48:0B>@0

//+------------------------------------------------+ 

//|  E>4=K5 ?0@0<5B@K 8=48:0B>@0                  |

//+------------------------------------------------+ 

//---- =0AB@>9:8 287C0;L=>3> >B>1@065=8O 8=48:0B>@0

input string Sirname="AutoTradeLevels";  // 0720=85 4;O <5B>: 8=48:0B>@0

input uint Len=3;  // ;8=0 F5=>2KE C@>2=59 2 :>;8G5AB25 A25G59

//+------------------------------------------------------------------+    

//| Custom indicator initialization function                         | 

//+------------------------------------------------------------------+  

int OnInit()

  {

//---- 8<O 4;O >:>= 40==KE 8 ;M910 4;O AC1J>:>= 

   IndicatorSetString(INDICATOR_SHORTNAME,"AutoTradeLevels");

//--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//--- 7025@H5=85 8=8F80;870F88

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function                       |

//+------------------------------------------------------------------+    

void OnDeinit(const int reason)

  {

//----

   ObjectsDeleteAll(0,"AutoTradeLevels",-1,-1);

//----

   ChartRedraw(NULL);

  }

//+------------------------------------------------------------------+  

//| Custom indicator iteration function                              | 

//+------------------------------------------------------------------+  

int OnCalculate(const int rates_total,    // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

                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[])

  {

//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AG5B0

   if(rates_total<1) return(RESET);

   

   int total=ObjectsTotal(0,0,OBJ_ARROW_BUY);

//---- >A=>2=>9 F8:; 70<5=K Buy 7=0G:>2

   for(int kkk=total-1; kkk>=0 && !IsStopped(); kkk--)

     {

      string name=ObjectName(0,kkk,0,OBJ_ARROW_BUY);

      if(StringSubstr(name,0,9)=="autotrade")

        {

         datetime Time=datetime(ObjectGetInteger(0,name,OBJPROP_TIME,0));

         double Price=ObjectGetDouble(0,name,OBJPROP_PRICE,0);

         color Color=color(ObjectGetInteger(0,name,OBJPROP_COLOR));

         SetTline(0,"AutoTradeLevels"+name,0,Time,Price,Time+MathMax(1,Len)*PeriodSeconds(),Price,Color,0,2,name);

        }

     }

     

   total=ObjectsTotal(0,0,OBJ_ARROW_SELL);

//---- >A=>2=>9 F8:; 70<5=K Buy 7=0G:>2

   for(int kkk=total-1; kkk>=0 && !IsStopped(); kkk--)

     {

      string name=ObjectName(0,kkk,0,OBJ_ARROW_SELL);

      if(StringSubstr(name,0,9)=="autotrade")

        {

         datetime Time=datetime(ObjectGetInteger(0,name,OBJPROP_TIME,0));

         double Price=ObjectGetDouble(0,name,OBJPROP_PRICE,0);

         color Color=color(ObjectGetInteger(0,name,OBJPROP_COLOR));

         SetTline(0,"AutoTradeLevels"+name,0,Time,Price,Time+MathMax(1,Len)*PeriodSeconds(),Price,Color,0,2,name);

        }

     }

//----

   ChartRedraw(0);

   return(rates_total);

  }

//+------------------------------------------------------------------+

//|  !>740=85 B@5=4>2>9 ;8=88                                        |

//+------------------------------------------------------------------+

void CreateTline

(

long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

string   name,          // 8<O >1J5:B0

int      nwin,          // 8=45:A >:=0

datetime time1,         // 2@5<O 1 F5=>2>3> C@>2=O

double   price1,        // 1 F5=>2>9 C@>25=L

datetime time2,         // 2@5<O 2 F5=>2>3> C@>2=O

double   price2,        // 2 F5=>2>9 C@>25=L

color    Color,         // F25B ;8=88

int      style,         // AB8;L ;8=88

int      width,         // B>;I8=0 ;8=88

string   text           // B5:AB

)

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_TREND,nwin,time1,price1,time2,price2);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,false);

   ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,false);

   ObjectSetInteger(chart_id,name,OBJPROP_RAY,false);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,true);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,true);

   ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,true);

//----

  }

//+------------------------------------------------------------------+

//|  5@5CAB0=>2:0 B@5=4>2>9 ;8=88                                   |

//+------------------------------------------------------------------+

void SetTline

(

long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

string   name,          // 8<O >1J5:B0

int      nwin,          // 8=45:A >:=0

datetime time1,         // 2@5<O 1 F5=>2>3> C@>2=O

double   price1,        // 1 F5=>2>9 C@>25=L

datetime time2,         // 2@5<O 2 F5=>2>3> C@>2=O

double   price2,        // 2 F5=>2>9 C@>25=L

color    Color,         // F25B ;8=88

int      style,         // AB8;L ;8=88

int      width,         // B>;I8=0 ;8=88

string   text           // B5:AB

)

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateTline(chart_id,name,nwin,time1,price1,time2,price2,Color,style,width,text);

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectMove(chart_id,name,0,time1,price1);

      ObjectMove(chart_id,name,1,time2,price2);

      ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

     }

//----

  }

//+------------------------------------------------------------------+

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