Navigation:Home > Content >

DuettoFX.mq4

Time: 2010-12-28 | Download file:DuettoFX.mq4

/*
   G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
   Website:  hT T P ://W ww.m E taqu o T es.N E t
   E-mail : s UpP or t @ m e t a Q u oT e S .Net
*/
#property copyright "Copyright © 2012, Andrea Salvatore"
#property link      "http://www.pimpmyea.com"

#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 C'0x40,0x00,0x00'
#property indicator_color2 Black
#property indicator_color3 C'0x00,0x40,0x00'
#property indicator_color4 Black
#property indicator_color5 White
#property indicator_color6 White
#property indicator_color7 Yellow
#property indicator_color8 Yellow
#property indicator_width1 17
#property indicator_level1 50.0
#property indicator_width2 17
#property indicator_level2 60.0
#property indicator_width3 17
#property indicator_level3 40.0
#property indicator_width4 17
#property indicator_level4 70.0
#property indicator_width5 2
#property indicator_level5 30.0
#property indicator_width6 1
#property indicator_level6 55.0
#property indicator_width7 2
#property indicator_level7 45.0

extern int period = 120;
extern string instrument_1 = "EURUSD";
extern string instrument_2 = "USDCHF";
extern int smoothing = 2;
extern double first_pair_lot = 1.0;
extern bool show_spread = TRUE;
extern bool show_spread_ma = FALSE;
extern int MA_period = 24;
extern int MA_mode = 2;
extern bool show_text_interface = TRUE;
extern bool show_crosses = TRUE;
extern int bar = 1;
extern bool show_labels = TRUE;
extern int text_size = 10;
extern string text_font = "Segoe UI";
double G_ibuf_152[];
double G_ibuf_156[];
double G_ibuf_160[];
double G_ibuf_164[];
double G_ibuf_168[];
double G_ibuf_172[];
double G_ibuf_176[];
double G_ibuf_180[];
int G_digits_184;
double Gd_188;
int G_window_196;
string Gs_200;
int G_datetime_208;
int G_datetime_212;
double Gd_216;
double G_iclose_224;
double G_iclose_232;
double Gd_240;
double Gd_248;
double Gd_256;
double Gd_264;
double Gd_272;
double Gd_280;
color G_color_288 = Blue;
string Gs_duettofx_292 = "DuettoFX";
bool Gi_unused_300 = FALSE;

int init() {
   IndicatorBuffers(8);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, G_ibuf_152);
   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(1, G_ibuf_160);
   SetIndexStyle(2, DRAW_HISTOGRAM);
   SetIndexBuffer(2, G_ibuf_156);
   SetIndexStyle(3, DRAW_HISTOGRAM);
   SetIndexBuffer(3, G_ibuf_164);
   SetIndexStyle(4, DRAW_LINE);
   SetIndexBuffer(4, G_ibuf_168);
   SetIndexStyle(5, DRAW_LINE);
   SetIndexBuffer(5, G_ibuf_172);
   if (show_spread) {
      SetIndexStyle(6, DRAW_LINE);
      SetIndexBuffer(6, G_ibuf_176);
   }
   if (show_spread_ma) {
      SetIndexStyle(7, DRAW_LINE);
      SetIndexBuffer(7, G_ibuf_180);
   }
   SetIndexDrawBegin(0, period);
   IndicatorShortName(Gs_duettofx_292);
   G_digits_184 = Digits;
   if (G_digits_184 == 3 || G_digits_184 == 5) Gd_188 = 10.0 * Point;
   else Gd_188 = Point;
   Comment("");
   return (0);
}

int deinit() {
   ObjectsDeleteAll();
   Comment("");
   return (0);
}

int start() {
   double Ld_0;
   string name_8;
   string name_16;
   int Li_24;
   int Li_28;
   G_window_196 = WindowFind(Gs_duettofx_292);
   int ind_counted_32 = IndicatorCounted();
   if (Bars <= period) return (0);
   if (ind_counted_32 < 1) {
      for (int Li_36 = 1; Li_36 <= period; Li_36++) {
         G_ibuf_152[Bars - Li_36] = 0.0;
         G_ibuf_156[Bars - Li_36] = 0.0;
         G_ibuf_160[Bars - Li_36] = 0.0;
         G_ibuf_164[Bars - Li_36] = 0.0;
         G_ibuf_168[Bars - Li_36] = 0.0;
         G_ibuf_172[Bars - Li_36] = 0.0;
         G_ibuf_176[Bars - Li_36] = 0.0;
         G_ibuf_180[Bars - Li_36] = 0.0;
      }
   }
   Li_36 = Bars - period - 1;
   if (ind_counted_32 >= period) Li_36 = Bars - ind_counted_32 - 1;
   while (Li_36 >= 0) {
      G_ibuf_168[Li_36] = 0;
      G_ibuf_172[Li_36] = 0;
      for (int count_40 = 0; count_40 < smoothing; count_40++) {
         G_ibuf_168[Li_36] += iRSI(instrument_1, 0, period, PRICE_CLOSE, Li_36 + count_40);
         G_ibuf_172[Li_36] += iRSI(instrument_2, 0, period, PRICE_CLOSE, Li_36 + count_40);
      }
      G_ibuf_168[Li_36] = G_ibuf_168[Li_36] / smoothing;
      G_ibuf_172[Li_36] = G_ibuf_172[Li_36] / smoothing;
      G_ibuf_176[Li_36] = G_ibuf_168[Li_36] - G_ibuf_172[Li_36] + 50.0;
      Ld_0 = G_ibuf_168[Li_36] - G_ibuf_172[Li_36];
      if (Ld_0 > 0.0) {
         G_ibuf_156[Li_36] = G_ibuf_168[Li_36];
         G_ibuf_164[Li_36] = G_ibuf_172[Li_36];
         G_ibuf_152[Li_36] = EMPTY_VALUE;
         G_ibuf_160[Li_36] = EMPTY_VALUE;
      } else {
         G_ibuf_156[Li_36] = EMPTY_VALUE;
         G_ibuf_164[Li_36] = EMPTY_VALUE;
         G_ibuf_152[Li_36] = G_ibuf_172[Li_36];
         G_ibuf_160[Li_36] = G_ibuf_168[Li_36];
      }
      if (G_ibuf_168[Li_36 + 1 + bar] < G_ibuf_172[Li_36 + 1 + bar] && G_ibuf_168[Li_36 + bar] > G_ibuf_172[Li_36 + bar]) {
         name_8 = Gs_duettofx_292 + instrument_1 + instrument_2 + "BUY" + ((Time[Li_36 + bar]));
         if (show_crosses) {
            ObjectCreate(name_8, OBJ_VLINE, 0, Time[Li_36 + bar], 0);
            ObjectSet(name_8, OBJPROP_BACK, TRUE);
            ObjectSet(name_8, OBJPROP_TIME1, Time[Li_36 + bar]);
            ObjectSet(name_8, OBJPROP_COLOR, Green);
            ObjectSet(name_8, OBJPROP_STYLE, STYLE_DOT);
         }
         G_datetime_208 = iTime(Symbol(), 0, Li_36 + bar);
      }
      if (G_ibuf_168[Li_36 + 1 + bar] > G_ibuf_172[Li_36 + 1 + bar] && G_ibuf_168[Li_36 + bar] < G_ibuf_172[Li_36 + bar]) {
         name_16 = Gs_duettofx_292 + instrument_1 + instrument_2 + "SELL" + ((Time[Li_36 + bar]));
         if (show_crosses) {
            ObjectCreate(name_16, OBJ_VLINE, 0, Time[Li_36 + bar], 0);
            ObjectSet(name_16, OBJPROP_BACK, TRUE);
            ObjectSet(name_16, OBJPROP_TIME1, Time[Li_36 + bar]);
            ObjectSet(name_16, OBJPROP_COLOR, Maroon);
            ObjectSet(name_16, OBJPROP_STYLE, STYLE_DOT);
         }
         G_datetime_212 = iTime(Symbol(), 0, Li_36 + bar);
      }
      Li_36--;
   }
   Li_36 = Bars - period - 1;
   if (ind_counted_32 >= period) Li_36 = Bars - ind_counted_32 - 1;
   while (Li_36 >= 0) {
      G_ibuf_180[Li_36] = iMAOnArray(G_ibuf_176, 0, MA_period, 0, MA_mode, Li_36);
      Li_36--;
   }
   if (show_text_interface) {
      if (G_datetime_208 > G_datetime_212) {
         G_iclose_224 = iClose(instrument_1, 0, iBarShift(instrument_1, 0, G_datetime_208, FALSE));
         G_iclose_232 = iClose(instrument_2, 0, iBarShift(instrument_2, 0, G_datetime_208, FALSE));
         Gd_240 = iClose(instrument_1, 0, 0) - G_iclose_224;
         Gd_248 = G_iclose_232 - iClose(instrument_2, 0, 0);
      } else {
         G_iclose_224 = iClose(instrument_1, 0, iBarShift(instrument_1, 0, G_datetime_212, FALSE));
         G_iclose_232 = iClose(instrument_2, 0, iBarShift(instrument_2, 0, G_datetime_212, FALSE));
         Gd_240 = G_iclose_224 - iClose(instrument_1, 0, 0);
         Gd_248 = iClose(instrument_2, 0, 0) - G_iclose_232;
      }
      Gd_240 /= Gd_188;
      Gd_248 /= Gd_188;
      Li_24 = period * Period() / 60;
      Li_28 = Li_24 / 24;
      Li_24 %= 24;
      Gd_256 = f0_2(instrument_1, PERIOD_D1, Li_28, 0);
      Gd_264 = f0_2(instrument_2, PERIOD_D1, Li_28, 0);
      Gd_272 = 100.0 * f0_3(instrument_1, instrument_2, period, 0);
      Gd_280 = first_pair_lot * (Gd_256 / Gd_264);
      Gd_216 = Gd_240 * first_pair_lot + Gd_248 * Gd_280;
      Gs_200 = "\n              DUETTO FX v1.0" 
         + "\n         by www.pimpmyea.com\n" + "   ------------------------------------------------\n" + "   Spread on: " + instrument_1 + " - " + instrument_2 
         + "\n" 
         + "   Period: " + period + " bars (" + Li_28 + " days " + Li_24 + " hours)\n" + "   Period Correlation: " + DoubleToStr(Gd_272, 0) + "% \n" + "   ------------------------------------------------\n" + "   " + instrument_1 + " ADR: " + DoubleToStr(Gd_256, 2) + "   pips\n   " + instrument_1 + " Lot Size: " + DoubleToStr(first_pair_lot, 2) + " lots \n" + "   " + instrument_1 + " Entry Level @ " + DoubleToStr(G_iclose_224, Digits) 
         + "\n" 
         + "   " + instrument_1 + " Gain: " + DoubleToStr(Gd_240, 2) + " pips \n" + "   ------------------------------------------------\n" + "   " + instrument_2 + " ADR: " + DoubleToStr(Gd_264, 2) + "   pips\n   " + instrument_2 + " Lot Size: " + DoubleToStr(Gd_280, 2) + " lots \n" + "   " + instrument_2 + " Entry Level @ " + DoubleToStr(G_iclose_232, Digits) 
         + "\n" 
      + "   " + instrument_2 + " Gain: " + DoubleToStr(Gd_248, 2) + " pips\n" + "   -------------------------------------------------\n" + "   Total Normalized Pips: " + DoubleToStr(Gd_216,
         2) + " pips";
      Comment(Gs_200);
      if (G_ibuf_176[0] < 50.0) G_color_288 = f0_0(255, 0, 0, 0, 0, 0, 0, 4.61512, MathLog(MathAbs(G_ibuf_176[0] - 50.0)));
      if (G_ibuf_176[0] > 50.0) G_color_288 = f0_0(0, 255, 0, 0, 0, 0, 0, 4.61512, MathLog(MathAbs(G_ibuf_176[0] - 50.0)));
      if (Seconds() % 5 == 0) {
         for (int count_44 = 0; count_44 < 8; count_44++) {
            for (int count_48 = 0; count_48 < 10; count_48++) {
               ObjectDelete(Gs_duettofx_292 + "background" + count_44 + count_48);
               ObjectDelete(Gs_duettofx_292 + "background" + count_44 + ((count_48 + 1)));
               ObjectDelete(Gs_duettofx_292 + "background" + count_44 + ((count_48 + 2)));
               ObjectCreate(Gs_duettofx_292 + "background" + count_44 + count_48, OBJ_LABEL, 0, 0, 0);
               ObjectSetText(Gs_duettofx_292 + "background" + count_44 + count_48, "n", 30, "Wingdings", G_color_288);
               ObjectSet(Gs_duettofx_292 + "background" + count_44 + count_48, OBJPROP_XDISTANCE, 20 * count_44);
               ObjectSet(Gs_duettofx_292 + "background" + count_44 + count_48, OBJPROP_YDISTANCE, 23 * count_48 + 7);
            }
         }
      }
   }
   if (show_labels) {
      ObjectDelete(Gs_duettofx_292 + "Pair1");
      ObjectCreate(Gs_duettofx_292 + "Pair1", OBJ_TEXT, G_window_196, TimeCurrent(), G_ibuf_168[0]);
      ObjectSetText(Gs_duettofx_292 + "Pair1", "                           " + instrument_1 + ": " + DoubleToStr(G_ibuf_168[0], 2), text_size, text_font, Lime);
      ObjectDelete(Gs_duettofx_292 + "Pair2");
      ObjectCreate(Gs_duettofx_292 + "Pair2", OBJ_TEXT, G_window_196, TimeCurrent(), G_ibuf_172[0]);
      ObjectSetText(Gs_duettofx_292 + "Pair2", "                           " + instrument_2 + ": " + DoubleToStr(G_ibuf_172[0], 2), text_size, text_font, Red);
      ObjectDelete(Gs_duettofx_292 + "Spread");
      ObjectCreate(Gs_duettofx_292 + "Spread", OBJ_TEXT, G_window_196, TimeCurrent(), G_ibuf_176[0]);
      ObjectSetText(Gs_duettofx_292 + "Spread", "                         SPREAD: " + DoubleToStr(G_ibuf_176[0] - 50.0, 2), text_size, text_font, Yellow);
   }
   return (0);
}

int f0_2(string A_symbol_0, int A_timeframe_8, int Ai_12, int Ai_16) {
   double Ld_20;
   double Ld_28 = Ai_16 + Ai_12;
   while (Ai_16 < Ld_28) {
      Ld_20 += MathPow(10, Digits - 1) * (iHigh(A_symbol_0, A_timeframe_8, Ai_16) - iLow(A_symbol_0, A_timeframe_8, Ai_16));
      Ai_16++;
   }
   return (MathRound(Ld_20 / Ai_12));
}

double f0_3(string A_symbol_0, string A_symbol_8, int A_period_16, int A_timeframe_20) {
   double ima_24 = iMA(A_symbol_8, A_timeframe_20, A_period_16, 0, MODE_SMA, PRICE_CLOSE, 0);
   double ima_32 = iMA(A_symbol_0, A_timeframe_20, A_period_16, 0, MODE_SMA, PRICE_CLOSE, 0);
   double Ld_40 = 0;
   double Ld_48 = 0;
   double Ld_56 = 0;
   for (int Li_64 = 0; Li_64 <= A_period_16; Li_64++) {
      Ld_40 += (iClose(A_symbol_8, A_timeframe_20, Li_64) - ima_24) * (iClose(A_symbol_0, A_timeframe_20, Li_64) - ima_32);
      Ld_48 += MathPow(iClose(A_symbol_8, A_timeframe_20, Li_64) - ima_24, 2);
      Ld_56 += MathPow(iClose(A_symbol_0, A_timeframe_20, Li_64) - ima_32, 2);
   }
   Ld_48 = MathSqrt(Ld_48);
   Ld_56 = MathSqrt(Ld_56);
   double Ld_68 = Ld_48 * Ld_56;
   double Ld_ret_76 = Ld_40 / Ld_68;
   return (Ld_ret_76);
}

int f0_1(int Ai_0, int Ai_4, int Ai_8) {
   int Li_ret_12 = MathMin(255, MathAbs(Ai_0)) + 256.0 * MathMin(255, MathAbs(Ai_4)) + 65536.0 * MathMin(255, MathAbs(Ai_8));
   return (Li_ret_12);
}

int f0_0(int Ai_0, int Ai_4, int Ai_8, int Ai_12, int Ai_16, int Ai_20, double Ad_24, double Ad_32, double Ad_40) {
   double Ld_48 = Ad_32 - Ad_24;
   Ad_40 = Ad_32 - Ad_40;
   double Ld_56 = (Ai_0 - Ai_12) / (Ld_48 - 1.0);
   double Ld_64 = (Ai_4 - Ai_16) / (Ld_48 - 1.0);
   double Ld_72 = (Ai_8 - Ai_20) / (Ld_48 - 1.0);
   return (f0_1(Ai_0 - Ld_56 * Ad_40, Ai_4 - Ld_64 * Ad_40, Ai_8 - Ld_72 * Ad_40));
}

Recommend