Author: 2018 Rice
0 Views
0 Downloads
0 Favorites
tRange2
ÿþ//+------------------------------------------------------------------+

//|                                                       tRange.mq4 |

//|                   Copyright 2005-2014, MetaQuotes Software Corp. |

//|                                              http://www.mql4.com |

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

#property copyright   "2018 Rice"

#property link        "http://www.mql4.com"

#property description "tRange 2.0"

#property strict



//---- indicator settings

#property indicator_chart_window

input double s=100; //Stop level (pips)

input int r=2;  //Ratio (profit 2 / stop 1)

int x;



//| Custom indicator initialization function

void OnDeinit(const int reason)

  {

   ObjectDelete(0,"Stop");

   for(x=1;x<=r; x++)

   {

   ObjectDelete(0,"Profit"+IntegerToString(x));

   }

  }

void HLb(string name,double price, color col)

{   

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

    {

      ObjectCreate(0,name,OBJ_ARROW_RIGHT_PRICE,0,Time[0],price);

      ObjectSetInteger(0,name,OBJPROP_COLOR,col); 

      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT); 

    }

    else

    {

      ObjectMove(0,name,0,Time[0],price);

      ObjectSetInteger(0,name,OBJPROP_COLOR,col); 

      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT); 

    }

}

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

  {

//?@>25@:0 ?0BB5@=0

if ((MathAbs(Open[0]-Close[0])>0.00019) && (MathAbs(Open[0]-Close[0])<0.001))

{

 if (Close[0]-Open[0]>0)//buy

  {

    HLb("Stop",Close[0]-s/100000,clrRed);

    for(x=1;x<=r; x++)

    {

     if (x==1)

      HLb("Profit"+IntegerToString(x) ,Close[0]+x*s/100000,clrYellow);

     else HLb("Profit"+IntegerToString(x) ,Close[0]+x*s/100000,clrLime);

    }

  }

 else //sell

  {

    HLb("Stop",Close[0]+s/100000,clrRed);

    for(x=1;x<=r; x++)

    {

     if (x==1)

      HLb("Profit"+IntegerToString(x) ,Close[0]-x*s/100000,clrYellow);

     else HLb("Profit"+IntegerToString(x) ,Close[0]-x*s/100000,clrLime);

    }

  }

}

 else //C40;8BL

  {

   ObjectDelete(0,"Stop");

   for(x=1;x<=r; x++)

   {

    ObjectDelete(0,"Profit"+IntegerToString(x));

   }

  }

  return(rates_total);

  }

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

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