VisualStrategyGray

Orders Execution
Checks for the total of open orders
Indicators Used
Indicator of the average true rangeRelative strength index
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
VisualStrategyGray
ÿþ#property version   "1.00"

#property strict

#property indicator_chart_window

#property indicator_buffers 8

#property indicator_color1 Blue

#property indicator_color2 Red

#property indicator_color3 Blue

#property indicator_color4 Blue

#property indicator_color5 Red

#property indicator_color6 Red

#property indicator_color7 Green

#property indicator_color8 Green

#property indicator_width1 5

#property indicator_width2 5

#property indicator_width3 5

#property indicator_width4 5

#property indicator_width5 5

#property indicator_width6 5

#property indicator_width7 3

#property indicator_width8 3



#define prefix          "InfoPanel_"

#define FonColor        clrLightGray

#define txtfont         "Times New Roman"          

#define txtsize         10                      

#define txtcolor        clrBlack

#define profitcolor     clrBlue



extern bool      inform=true;



long   X=1090, Y=30;

double BufferUP[];

double BufferLOW[];

double BufferUPb1[];

double BufferUPb2[];

double BufferLOWb1[];

double BufferLOWb2[];

double BufferUPClose[];

double BufferLOWClose[];

double OPEN[];

bool Up=false;

bool Dn=false;

double p1,p2;



int OnInit()

  {

  ArraySetAsSeries(OPEN,true);

    for(int e=0; e<5; e++) 

     { 

     CopyOpen(Symbol(),Period(),0,(int)ChartGetInteger(0,CHART_WIDTH_IN_BARS,0),OPEN);

     }

//--- indicator buffers mapping

   SetIndexStyle(0,DRAW_ARROW);

   SetIndexStyle(1,DRAW_ARROW);

   SetIndexArrow(0,241);

   SetIndexArrow(1,242);

   SetIndexBuffer(0,BufferUP);

   SetIndexBuffer(1,BufferLOW);

   SetIndexLabel(0,"UP");

   SetIndexLabel(1,"DOWN");

   SetIndexEmptyValue(0,0.0);

   

   SetIndexStyle(2,DRAW_HISTOGRAM);

   SetIndexBuffer(2,BufferUPb1);

   SetIndexEmptyValue(2,EMPTY_VALUE);

   SetIndexStyle(3,DRAW_HISTOGRAM);

   SetIndexBuffer(3,BufferUPb2);

   SetIndexEmptyValue(3,EMPTY_VALUE);

   

   SetIndexStyle(4,DRAW_HISTOGRAM);

   SetIndexBuffer(4,BufferLOWb1);

   SetIndexEmptyValue(4,EMPTY_VALUE);

   SetIndexStyle(5,DRAW_HISTOGRAM);

   SetIndexBuffer(5,BufferLOWb2);

   SetIndexEmptyValue(5,EMPTY_VALUE);  

   

   SetIndexStyle(6,DRAW_ARROW);

   SetIndexStyle(7,DRAW_ARROW);

   SetIndexArrow(6,253);

   SetIndexArrow(7,253);

   SetIndexBuffer(6,BufferUPClose);

   SetIndexBuffer(7,BufferLOWClose);

   SetIndexEmptyValue(6,EMPTY_VALUE);

   SetIndexEmptyValue(7,EMPTY_VALUE);

//---

   return(0);

  }



void Del()

{

   ObjectsDeleteAll(0,prefix);

   

}



int start() 

{ 

  Graph();

  if (inform) Logo();

  ChartRedraw();

  return(0); 

}



void Logo()

{

   //info panel

   RectLabelCreate(0,prefix +"fon1",0,X+1  ,Y+1 ,220,300,FonColor,FonColor,STYLE_SOLID,1,false,false,true,0);

   RectLabelCreate(0,prefix +"fon2",0,X+6  ,Y+6 ,210,290,txtcolor,txtcolor,STYLE_SOLID,1,false,false,true,0);

   RectLabelCreate(0,prefix +"fon3",0,X+1  ,Y+51 ,220,150,FonColor,FonColor,STYLE_SOLID,1,false,false,true,0);

   //labels

   LabelCreate(0,prefix + "balance",0,X+10,Y+60,CORNER_LEFT_UPPER,"Account balance:",txtfont, txtsize,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

   LabelCreate(0,prefix + "balancev",0,X+150,Y+60,CORNER_LEFT_UPPER,DoubleToString(AccountInfoDouble(ACCOUNT_BALANCE),2)+"$",txtfont, txtsize,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

   LabelCreate(0,prefix + "margin",0,X+10,Y+80,CORNER_LEFT_UPPER,"AccountFreeMargin:",txtfont, txtsize,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

   LabelCreate(0,prefix + "marginv",0,X+150,Y+80,CORNER_LEFT_UPPER,DoubleToString(AccountInfoDouble(ACCOUNT_FREEMARGIN),2)+"$",txtfont, txtsize,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

   LabelCreate(0,prefix + "openord",0,X+10,Y+100,CORNER_LEFT_UPPER,"Number of open orders:",txtfont, txtsize,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

   LabelCreate(0,prefix + "openordv",0,X+150,Y+100,CORNER_LEFT_UPPER,IntegerToString(OrdersTotal()),txtfont, txtsize,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

   LabelCreate(0,prefix + "profitloss",0,X+110,Y+120,CORNER_LEFT_UPPER,"Profit / loss in points:",txtfont, txtsize,txtcolor,0,ANCHOR_CENTER,false,false,true,0);

   int profit=0;

   int nL = ObjectsTotal();

   string name;

   for(int n = nL-1; n >=0; n--)

      {

       name = ObjectName(n);

       int nch = StringFind(name,"TextHigh_");

       if(nch == 0) profit=profit+(StrToInteger(ObjectGetString(0,name,OBJPROP_TEXT)));

      } 

   if(profit>0)

    LabelCreate(0,prefix + "profitlossv",0,X+110,Y+140,CORNER_LEFT_UPPER,"+"+IntegerToString(profit),txtfont, txtsize+6,profitcolor,0,ANCHOR_CENTER,false,false,true,0);    

   else

    LabelCreate(0,prefix + "profitlossv",0,X+110,Y+140,CORNER_LEFT_UPPER,IntegerToString(profit),txtfont, txtsize+6,profitcolor,0,ANCHOR_CENTER,false,false,true,0);    

    LabelCreate(0,prefix + "points",0,X+110,Y+160,CORNER_LEFT_UPPER,"points",txtfont, txtsize,txtcolor,0,ANCHOR_CENTER,false,false,true,0);    

}



void OnDeinit(const int reason)

{

   Del();

   ObjectsDeleteAll(0,"TextHigh_");

}



void Redraw()

{

 Del();

 if (inform) Logo();

 Graph();

}



void Graph()

{

 int counted_bars=IndicatorCounted();

 int S,S1;

 int i;

 int lk;

   if(counted_bars>0) counted_bars--;

   int limit=Bars-counted_bars;

   //signal detection

   Up=false;

   Dn=false;

   for(i=limit-1; i>0; i--)

     {

      S=Figura(i);

      switch(S)

        {

                

         case 1:

         if(!Up)

         {

         BufferUP[i]=Low[i]-5*Point;

         BufferUPb1[i]=Open[i];

         BufferUPb2[i]=Close[i];

         Up=true;

         Dn=false;

         }

         break;

         

         case -1:

         if(!Dn)

         {

         BufferLOW[i]=High[i]+5*Point;

         BufferLOWb1[i]=Open[i];

         BufferLOWb2[i]=Close[i];

         Up=false;

         Dn=true;

         }

         break;

        }

      }

   //definition of exit point

   Up=false;

   Dn=false;

   for(i=limit-1; i>0; i--)

     {

      if(BufferUP[i]==Low[i]-5*Point) 

       {

        Up=true;

        Dn=false;

       } 

      if(BufferLOW[i]==High[i]+5*Point) 

       {

        Dn=true;

        Up=false;

       } 

      //check signal for closing 

      S1=CloseFigura(i);

      switch(S1)

        {

         case -1:

         if (Up) 

          {

           BufferUPClose[i]=High[i]+5*Point;

           Up=false;

          } 

         break;

         

         case 1:

         if(Dn) 

          {

           BufferLOWClose[i]=Low[i]-5*Point;

           Dn=false;

          } 

         break;

         

        }

      //signal change check

      if(BufferUP[i-1]==Low[i-1]-5*Point) 

       {

        if(Dn)

         {

          BufferLOWClose[i]=Low[i]-5*Point;

         } 

       } 

      if(BufferLOW[i-1]==High[i-1]+5*Point) 

       {

        if(Up)

         {

          BufferUPClose[i]=High[i]+5*Point;

         }

       }   

       

     }  

     

     for(i=limit-1; i>0; i--)

     {

      if(BufferUP[i]==Low[i]-5*Point) 

       {

        Up=true;

        Dn=false;

        p1=Open[i];

       } 

      if(BufferLOW[i]==High[i]+5*Point) 

       {

        Dn=true;

        Up=false;

        p1=Open[i];

       } 

      

      if(Up)

       {

        BufferUPb1[i]=Open[i];

        BufferUPb2[i]=Close[i];

       }

      if(Dn)

       {

        BufferLOWb1[i]=Open[i];

        BufferLOWb2[i]=Close[i];

       } 

      if(BufferUPClose[i]==High[i]+5*Point && Up) 

       {

        Up=false;

        p2=Close[i];

        lk=int((p2-p1)/Point);

        if(ObjectFind(0,"TextHigh_"+(string)i)==-1)

         {

        TextCreate(0,"TextHigh_"+(string)i,0,Time[i],High[i]+iATR(NULL,0,521,i),IntegerToString(lk),txtfont,txtsize,

         clrGreen,0,ANCHOR_CENTER,false,false,true,0);

         }

       } 

      if(BufferLOWClose[i]==Low[i]-5*Point && Dn) 

       {

        Dn=false;

        p2=Close[i];

        lk=int((p1-p2)/Point);

        if(ObjectFind(0,"TextHigh_"+(string)i)==-1)

         {

        TextCreate(0,"TextHigh_"+(string)i,0,Time[i],Low[i]-iATR(NULL,0,521,i),IntegerToString(lk),txtfont,txtsize,

         clrGreen,0,ANCHOR_CENTER,false,false,true,0);

         }

       } 

      

     }

}



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

//| Creates a rectangular label                                      | 

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

bool RectLabelCreate(const long             chart_ID=0,               // ID 3@0D8:0

                     const string           name="RectLabel",         // 8<O <5B:8

                     const int              sub_window=0,             // =><5@ ?>4>:=0

                     const long              x=0,                     // :>>@48=0B0 ?> >A8 X

                     const long              y=0,                     // :>>@48=0B0 ?> >A8 y

                     const int              width=50,                 // H8@8=0

                     const int              height=18,                // 2KA>B0

                     const color            back_clr=clrNONE,         // F25B D>=0

                     const color            clr=clrNONE,              // F25B ?;>A:>9 3@0=8FK (Flat)

                     const ENUM_LINE_STYLE  style=STYLE_SOLID,        // AB8;L ?;>A:>9 3@0=8FK

                     const int              line_width=1,             // B>;I8=0 ?;>A:>9 3@0=8FK

                     const bool             back=false,               // =0 704=5< ?;0=5

                     const bool             selection=false,          // 2K45;8BL 4;O ?5@5<5I5=89

                     const bool             hidden=true,              // A:@KB 2 A?8A:5 >1J5:B>2

                     const long             z_order=0)                // ?@8>@8B5B =0 =060B85 <KHLN

  {

   ResetLastError();

   if (ObjectFind(chart_ID,name)==-1)

   {

      ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,BORDER_FLAT);

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);

      ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

      ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width);

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   }

   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);

   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   return(true);

}

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

//| Creates a text label                                             | 

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

bool LabelCreate(const long              chart_ID=0,               // ID 3@0D8:0

                 const string            name="Label",             // 8<O <5B:8

                 const int               sub_window=0,             // =><5@ ?>4>:=0

                 const long              x=0,                      // :>>@48=0B0 ?> >A8 X

                 const long              y=0,                      // :>>@48=0B0 ?> >A8 y

                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // C3>; 3@0D8:0 4;O ?@82O7:8

                 const string            text="Label",             // B5:AB

                 const string            font="Arial",             // H@8DB

                 const int               font_size=10,             // @07<5@ H@8DB0

                 const color             clr=clrNONE,      

                 const double            angle=0.0,                // =0:;>= B5:AB0

                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // A?>A>1 ?@82O7:8

                 const bool              back=false,               // =0 704=5< ?;0=5

                 const bool              selection=false,          // 2K45;8BL 4;O ?5@5<5I5=89

                 const bool              hidden=true,              // A:@KB 2 A?8A:5 >1J5:B>2

                 const long              z_order=0)                // ?@8>@8B5B =0 =060B85 <KHLN

{

   ResetLastError();

   if (ObjectFind(chart_ID,name)==-1)

   {

      if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))

      {

         Print(__FUNCTION__,": =5 C40;>AL A>740BL B5:AB>2CN <5B:C! >4 >H81:8 = ",GetLastError());

         return(false);

      }

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);

      ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

      ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

      ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);

      ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   }

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

   return(true);

}



//==============================================================================================================



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

//|!ondition of opening an order                                     |

//|Here you need to change the conditions for your strategy          |

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

int Figura(int bar)

  {

   //condition of sell opening

   if(iRSI(NULL,0,7,PRICE_CLOSE,bar)>80 && iRSI(NULL,0,7,PRICE_CLOSE,bar+1)<80)

     {

      return(-1);

     }

   //condition of buy opening  

   if(iRSI(NULL,0,7,PRICE_CLOSE,bar)<20 && iRSI(NULL,0,7,PRICE_CLOSE,bar+1)>20)

     {

      return(1);

     }

   return(0);

  }



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

//|closing order condition                                           |

//|Here you need to change the conditions for your strategy          |

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

int CloseFigura(int bar)

  {

//----------------------------------------- 0=0;87 D83C@

   //Sell

   if(iRSI(NULL,0,7,PRICE_CLOSE,bar)<25 && iRSI(NULL,0,7,PRICE_CLOSE,bar+1)>25)

     {

      return(1);

     }

   //Buy

   if(iRSI(NULL,0,7,PRICE_CLOSE,bar)>75 && iRSI(NULL,0,7,PRICE_CLOSE,bar+1)<75)

     {

      return(-1);

     }

   return(0);

  }  



//==============================================================================================================

  

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

//| Creates a Text object                                            |

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

bool TextCreate(const long              chart_ID=0,               // ID 3@0D8:0

                const string            name="Text",              // 8<O >1J5:B0

                const int               sub_window=0,             // =><5@ ?>4>:=0

                datetime                time=0,                   // 2@5<O B>G:8 ?@82O7:8

                double                  price=0,                  // F5=0 B>G:8 ?@82O7:8

                const string            text="Text",              // A0< B5:AB

                const string            font="Arial",             // H@8DB

                const int               font_size=10,             // @07<5@ H@8DB0

                const color             clr=clrRed,               // F25B

                const double            angle=0.0,                // =0:;>= B5:AB0

                const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // A?>A>1 ?@82O7:8

                const bool              back=false,               // =0 704=5< ?;0=5

                const bool              selection=false,          // 2K45;8BL 4;O ?5@5<5I5=89

                const bool              hidden=true,              // A:@KB 2 A?8A:5 >1J5:B>2

                const long              z_order=0)                // ?@8>@8B5B =0 =060B85 <KHLN

  {

   ChangeTextEmptyPoint(time,price);

   ResetLastError();

   if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))

     {

      Print(__FUNCTION__,

            ": could not create object \"text\"! Error code = ",GetLastError());

      return(false);

     }

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);

   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   return(true);

  }

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

//| Checks the values   of the anchor point and for null values        |

//| sets default values                                              |

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

void ChangeTextEmptyPoint(datetime &time,double &price)

  {

   if(!time)

      time=TimeCurrent();

   if(!price)

      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);

  } 

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