I would like to request TRO Dynamic SR Indicator from MQ4 to LUA.
Here is mq4 files of TRO Dynamic SR Indicator.
- Code: Select all
//+------------------------------------------------------------------+
//| TRO_DYNAMIC_FIBS_SR_Trail |
//| |
//| Copyright © 2009, Avery T. Horton, Jr. aka TheRumpledOne |
//| |
//| PO BOX 43575, TUCSON, AZ 85733 |
//| |
//| GIFTS AND DONATIONS ACCEPTED |
//| All my indicators should be considered donationware. That is |
//| you are free to use them for your personal use, and are |
//| under no obligation to pay for them. However, if you do find |
//| this or any of my other indicators help you with your trading |
//| then any Gift or Donation as a show of appreciation is |
//| gratefully accepted. |
//| |
//| Gifts or Donations also keep me motivated in producing more |
//| great free indicators. :-) |
//| |
//| PayPal - THERUMPLEDONE@GMAIL.COM |
//+------------------------------------------------------------------+
//| Use http://therumpledone.mbtrading.com/fx/ as your forex broker |
//| ...tell them therumpledone sent you! |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Avery T. Horton, Jr. aka TRO"
#property link "http://www.therumpledone.com/"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Aqua
#property indicator_color4 Magenta
//---- input parameters
extern bool Sound.Alert = true ;
extern bool Trigger.Lines = false ;
extern bool Plot.Triggers = true;
extern bool bDrawBoxes = true;
extern bool bResetOnNewDay = false;
extern int max_bars = 300;
extern int iPeriods = 5;
extern int iThreshold = 0;
extern int iPipsTrigger = 5;
extern color iColorRes = Red ;
extern color iColorSup = Blue ;
extern color iColorBuy = Aqua ;
extern color iColorShort = Magenta ;
extern int iAlertLineStyle = STYLE_DOT ;
extern int myBoxWidth = 3;
extern int myWingDing = 119 ;
//---- buffers
double DynR[];
double DynS[];
double LgTrig[];
double ShTrig[];
double xLgTrig;
double xShTrig;
string tRes0 = "Res_0" ;
string tSup0 = "Sup_0" ;
string tLgTrig = "LgTrig_0" ;
string tShTrig = "ShTrig_0" ;
string tAlertBuy = "Buy_sr" ;
string tAlertShort = "Short_sr";
datetime Trigger ;
double iAlertBuy, iAlertShort, xThreshold, point;
string symbol, tChartPeriod, tShortName ;
int digits, period, h, l ;
bool GreenCandle, RedCandle ;
double PipsTrigger = 5;
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,myWingDing);
SetIndexBuffer(0,DynR);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,myWingDing);
SetIndexBuffer(1,DynS);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,myWingDing);
SetIndexBuffer(2,LgTrig);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,myWingDing);
SetIndexBuffer(3,ShTrig);
SetIndexEmptyValue(3,0.0);
period = Period();
tChartPeriod = TimeFrameToString(period) ;
symbol = Symbol() ;
digits = Digits ;
Trigger = Time[0] ;
point = Point ;
if(digits == 5 || digits == 3) { digits = digits - 1 ; point = point * 10 ; }
xThreshold = iThreshold * point ;
PipsTrigger = iPipsTrigger * point ;
deinit() ;
return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete(tRes0);
ObjectDelete(tSup0);
ObjectDelete(tLgTrig);
ObjectDelete(tShTrig);
ObjectDelete(tAlertBuy);
ObjectDelete(tAlertShort);
//----
return(0);
}
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars < 0)
return(-1);
//----
int limit=Bars-counted_bars;
DynR[0] = Close[0];
DynS[0] = Close[0];
double nHH, nLL;
double range;
int processBars=MathMin(limit, max_bars);
for(int i=processBars;i>=0;i--){
if ((Period() < PERIOD_D1) && //if timeframe below day
(TimeDay(Time[i])!=TimeDay(Time[i+1])) && // new day
(bResetOnNewDay)) { // reset if different day
DynR[i] = High[i];
DynS[i]= Low[i];
} //end if
else
{
h = Highest(NULL,0,MODE_HIGH,iPeriods,i) ;
l = Lowest(NULL,0,MODE_LOW,iPeriods,i) ;
nHH = High[h];
nLL = Low[l];
DynR[i] = nHH;
DynS[i] = nLL;
if(Plot.Triggers) {LgTrig[i] = Low[l] + PipsTrigger; ShTrig[i] = High[h] - PipsTrigger; }
if ((DynR[i] != High[i]) && (DynR[i] < DynR[i+1]) && ( DynR[i+1] != 0 ))
{
DynR[i] = DynR[i+1];
if(Plot.Triggers) { ShTrig[i] = ShTrig[i+1]; }
}
if (( DynS[i] != Low[i]) && (DynS[i] > DynS[i+1] ) && ( DynS[i+1] != 0 ))
{
DynS[i] = DynS[i+1];
if(Plot.Triggers) { LgTrig[i] = LgTrig[i+1]; }
}
}
} //end for
iAlertBuy = LgTrig[0] + xThreshold ;
iAlertBuy = NormalizeDouble( iAlertBuy , digits ) ;
iAlertShort = ShTrig[0] - xThreshold ;
iAlertShort = NormalizeDouble( iAlertShort , digits ) ;
GreenCandle = Close[0] > Open[0] ;
RedCandle = Open [0] > Close[0] ;
if ( Trigger != Time[0] && Sound.Alert )
{
if( Ask >= iAlertBuy && Low[0] <= iAlertBuy && GreenCandle )
{ Trigger = Time[0] ; Alert(symbol," ", tChartPeriod, DoubleToStr(iAlertBuy ,digits), " DYN SR Buy " ); }
if( Bid <= iAlertShort && High[0] >= iAlertShort && RedCandle )
{ Trigger = Time[0] ; Alert(symbol," ", tChartPeriod, DoubleToStr(iAlertShort ,digits), " DYN SR Short "); }
}
if( Trigger.Lines )
{
ObjectDelete(tAlertBuy);
ObjectCreate(tAlertBuy,OBJ_HLINE,0,0,0);
ObjectSet(tAlertBuy,OBJPROP_COLOR,iColorBuy);
ObjectSet(tAlertBuy,OBJPROP_STYLE,iAlertLineStyle);
ObjectDelete(tAlertShort);
ObjectCreate(tAlertShort,OBJ_HLINE,0,0,0);
ObjectSet(tAlertShort,OBJPROP_COLOR,iColorShort);
ObjectSet(tAlertShort,OBJPROP_STYLE,iAlertLineStyle);
ObjectMove(tAlertBuy,0,Time[0],iAlertBuy);
ObjectMove(tAlertShort,0,Time[0],iAlertShort);
}
if( bDrawBoxes )
{
if (ObjectFind(tRes0) != 0)
{
ObjectCreate(tRes0,OBJ_ARROW,0,Time[0],DynR[0]);
ObjectSet(tRes0,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(tRes0,OBJPROP_COLOR,Red);
ObjectSet(tRes0,OBJPROP_WIDTH,myBoxWidth);
}
else
{
ObjectMove(tRes0,0,Time[0],DynR[0]);
}
if (ObjectFind(tSup0) != 0)
{
ObjectCreate(tSup0,OBJ_ARROW,0,Time[0],DynS[0]);
ObjectSet(tSup0,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(tSup0,OBJPROP_COLOR,Blue);
ObjectSet(tSup0,OBJPROP_WIDTH,myBoxWidth);
}
else
{
ObjectMove(tSup0,0,Time[0],DynS[0]);
}
ObjectDelete(tLgTrig);
if (ObjectFind(tLgTrig) != 0)
{
ObjectCreate(tLgTrig,OBJ_ARROW,0,Time[0],iAlertBuy);
ObjectSet(tLgTrig,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(tLgTrig,OBJPROP_COLOR,iColorBuy);
ObjectSet(tLgTrig,OBJPROP_WIDTH,myBoxWidth);
}
else
{
ObjectMove(tLgTrig,0,Time[0],iAlertBuy);
}
if (ObjectFind(tShTrig) != 0)
{
ObjectCreate(tShTrig,OBJ_ARROW,0,Time[0],iAlertShort);
ObjectSet(tShTrig,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(tShTrig,OBJPROP_COLOR,iColorShort);
ObjectSet(tShTrig,OBJPROP_WIDTH,myBoxWidth);
}
else
{
ObjectMove(tShTrig,0,Time[0],iAlertShort);
}
}
//----
WindowRedraw() ;
return(0);
}
//+------------------------------------------------------------------+
string TimeFrameToString(int tf)
{
string tfs;
switch(tf) {
case PERIOD_M1: tfs="M1" ; break;
case PERIOD_M5: tfs="M5" ; break;
case PERIOD_M15: tfs="M15" ; break;
case PERIOD_M30: tfs="M30" ; break;
case PERIOD_H1: tfs="H1" ; break;
case PERIOD_H4: tfs="H4" ; break;
case PERIOD_D1: tfs="D1" ; break;
case PERIOD_W1: tfs="W1" ; break;
case PERIOD_MN1: tfs="MN";
}
return(tfs);
}
//+--------- TRO MODIFICATION ---------------------------------------+
/*
Comment(
"iPipsTrigger =", DoubleToStr(iPipsTrigger,Digits) , "\n" ,
"Point =", DoubleToStr(Point,6) , "\n" ,
"PipsTrigger =", DoubleToStr(PipsTrigger,Digits) , "\n" ,
"LgTrig[0] =", DoubleToStr(LgTrig[0],Digits) , "\n" ,
"ShTrig[0] =", DoubleToStr(ShTrig[0],Digits) , "\n" ,
"") ;
Alert( DoubleToStr(iAlertShort ,digits), " DYN SR Short ");
Comment(
"High[0]= ", DoubleToStr(High[0] ,digits) , "\n",
"iAlertShort= ", DoubleToStr(iAlertShort ,digits) , "\n",
"Bid= ", DoubleToStr(Bid ,digits) , "\n",
"Low[0]= ", DoubleToStr(Low[0] ,digits) , "\n",
" ", "\n",
"High[0]= ", DoubleToStr(High[0] ,digits) , "\n",
"Ask= ", DoubleToStr(Ask ,digits) , "\n",
"iAlertBuy= ", DoubleToStr(iAlertBuy ,digits) , "\n",
"Low[0]= ", DoubleToStr(Low[0] ,digits) , "\n",
"") ;
*/