GraficRatioCalculator1.0

0 Views
0 Downloads
0 Favorites
GraficRatioCalculator1.0
ÿþ//+------------------------------------------------------------------+

//|                                            GraficRatioCalculator |

//|                                            Autor BailandoConHumo | 

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

input string                       InpNameBull="RectangleBull"; // BullName

input string                       InpNameBear="RectangleBear"; // BearName

input double                       InpRatio=2.0; //Ratio

input int                          InpTWidith=20; // TWidith

input color                        InpColorBull=clrPaleGreen; // Color Bull

input color                        InpColorBear=clrLightCoral; // Color Bear

input ENUM_LINE_STYLE              InpStyle=STYLE_DASH; // Line Style

input int                          InpWidth=2; // Line Width

input bool                         InpFill=true; // Fill

input bool                         InpBack=true; // Back

input bool                         InpSelection=true; // Selection

input bool                         InpHidden=false; // Hidden

input long                         InpZOrder=0; // ZOrder

input bool                         InpPrediction=true; //Prediction mode



double prices[2];

datetime times[2];

int points=0;

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

//|Bull position function                                            |

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

void BullPositionOption(const double         priceEntrance=0,

                        datetime             timeEntrance=0,

                        const double         priceStop=0,

                        datetime             timeStop=0)

  {

   datetime prediction=0;

   if(InpPrediction==true)

     {

      prediction=timeEntrance-timeStop;

     }



   Print("BullPosition");

   if(!RectangleCreate(0,InpNameBull,0,timeEntrance+prediction,priceEntrance,timeStop,priceStop,InpColorBear,InpStyle,

      InpWidth,InpFill,InpBack,InpSelection,InpHidden,InpZOrder))

     {

      return;

     }

   ChartRedraw();



   double priceTP=0;



   priceTP=priceEntrance+((priceEntrance-priceStop)*InpRatio);



   if(!RectangleCreate(0,InpNameBear,0,timeEntrance+prediction,priceEntrance,timeStop,priceTP,InpColorBull,InpStyle,

      InpWidth,InpFill,InpBack,InpSelection,InpHidden,InpZOrder))

     {

      return;

     }

   ChartRedraw();



   Comment("BULL POSITION\n\n",

           "Ratio:          1/",InpRatio,

           "\nEntrance:     ",priceEntrance,

           "\nStopLoss:     ",priceStop,

           "\nTake Profit:  ",priceTP);

   Sleep(1000);

  }

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

//|Bear position fuction                                             |

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

void BearPositionOption(const double         priceEntrance=0,

                        datetime             timeEntrance=0,

                        const double         priceStop=0,

                        datetime             timeStop=0)

  {

   datetime prediction=0;

   if(InpPrediction==true)

     {

      prediction=timeEntrance-timeStop;

     }

   Print("BearPosition");

   if(!RectangleCreate(0,InpNameBear,0,timeEntrance+prediction,priceEntrance,timeStop,priceStop,InpColorBear,InpStyle,

      InpWidth,InpFill,InpBack,InpSelection,InpHidden,InpZOrder))

     {

      return;

     }

   ChartRedraw();



   double priceTP=0;



   priceTP=priceEntrance-((priceStop-priceEntrance)*InpRatio);



   if(!RectangleCreate(0,InpNameBull,0,timeEntrance+prediction,priceEntrance,timeStop,priceTP,InpColorBull,InpStyle,

      InpWidth,InpFill,InpBack,InpSelection,InpHidden,InpZOrder))

     {

      return;

     }

   ChartRedraw();



   Comment("BEAR POSITION\n\n",

           "Ratio:          1/",InpRatio,

           "\nEntrance:     ",priceEntrance,

           "\nStopLoss:     ",priceStop,

           "\nTake Profit:  ",priceTP);

   Sleep(1000);

  }

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

//|Rectangle create function                                         |

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

bool RectangleCreate(const long                   chart_ID=0,

                     const string                 name="Rectangle",

                     const int                    sub_window=0,

                     datetime                     time1=0,

                     double                       price1=0,

                     datetime                     time2=0,

                     double                       price2=0,

                     const color                  clr=clrBlue,

                     const ENUM_LINE_STYLE        style=STYLE_SOLID,

                     const int                    width=1,

                     const bool                   fill=false,

                     const bool                   back=false,

                     const bool                   selection=true,

                     const bool                   hidden=true,

                     const long                   z_order=0)

  {

   ChangeRectangleEmptyPoints(time1,price1,time2,price2);



   ResetLastError();



   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2))

     {

      Print(__FUNCTION__,

            ": Fallo al crear el rectangulo!!! Codigo del error: ",GetLastError());

      return(false);

     }

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);

   ObjectSetInteger(chart_ID,name,OBJPROP_FILL,fill);

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

  }

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

//|Change rectangle empty points function                            |

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

void ChangeRectangleEmptyPoints(datetime &time1,double &price1,

                                datetime &time2,double &price2)

  {

   if(!time1)

      time1=TimeCurrent();

   if(!price1)

      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);

   if(!time2)

     {

      datetime temp[10];

      CopyTime(Symbol(),Period(),time1,10,temp);

      time2=temp[0];

     }

   if(!price2)

      price2=price1-300*SymbolInfoDouble(Symbol(),SYMBOL_POINT);

  }

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

//|Init function                                                     |

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

int OnInit()

  {

   for(int i=0;i<2;i++)

     {

      prices[i]=0;

      times[i]=0;

     }



   return(0);

  }

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

//|Mouse parameters function                                         |

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

void OnChartEvent(const int             id,

                  const long            &lparam,

                  const double          &dparam,

                  const string          &sparam)

  {



   if(id==CHARTEVENT_CLICK)

     {

      int            x              =(int)lparam;

      int            y              =(int)dparam;

      datetime       dt             =0;

      double         price          =0;

      int            window         =0;



      if(ChartXYToTimePrice(0,x,y,window,dt,price))

        {

         prices[points]=price;

         times[points]=dt;



        }



      Print("Points: ",points);



      points++;



      if(points==2)

        {



         if(prices[0]>prices[1])

            BullPositionOption(prices[0],times[0],prices[1],times[1]);

         else if(prices[0]<prices[1])

            BearPositionOption(prices[0],times[0],prices[1],times[1]);



         points=0;

        }



     }

  }                  

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

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