MT4 to MT5 code converter - page 48

Mugumya Osman
9
Mugumya Osman  

please members someone to help me convert for me these indicators from mq4 to mq5 they will rilly help us alot thanks

<Decompiled code deleted>

Keith Watford
Moderator
26733
Keith Watford  
Mugumya Osman:

please members someone to help me convert for me these indicators from mq4 to mq5 they will rilly help us alot thanks

<Decompiled code deleted>

Do not post decompiled code, you could be banned

The jPallada code is definitely decompiled

g_ibuf_164[li_4] = g_ibuf_164[li_4 + 1];
      g_ibuf_168[li_4] = g_ibuf_168[li_4 + 1];
      g_ibuf_172[li_4] = g_ibuf_172[li_4 + 1];
      g_ibuf_176[li_4] = g_ibuf_176[li_4 + 1];
      g_ibuf_180[li_4] = g_ibuf_180[li_4 + 1];
      g_ibuf_184[li_4] = g_ibuf_184[li_4 + 1];
      g_ibuf_188[li_4] = g_ibuf_188[li_4 + 1];
      li_8 = fTimeInZone(StartHour, gi_80, EndHour, gi_88, Time[li_4]);
      li_12 = fTimeInZone(StartHour, gi_80, EndHour, gi_88, Time[li_4 + 1]);

and the other is certainly an attempt to hide the fact that it is decompiled.

double u1x5v, u1x8v, u1x13v, u1x21v, u1x34v;
double u2x5v, u2x8v, u2x13v, u2x21v, u2x34v;
double u3x5v, u3x8v, u3x13v, u3x21v, u3x34v;
double u1acv, u2acv, u3acv;

as there is not a single meaningful variable name in there.

Thomas Knudsen
363
Thomas Knudsen  

Hello

Anyone that can convert this script to MT5?

Thank you

//+------------------------------------------------------------------+
//|                                            motu_script_Daily.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "0xff"
#property link      ""
#property show_inputs

string VERSION = "motu_script_Daily";


input int lvl_for_enter = 25; // %fibo +- High and Low monday&tuesday range for entry level
input int sl_for_order = 50; // %fibo +- for stoploss at range
input int tp_in_point = 200; // take profit
input int MagicNumber = 29022020;
/*
Example for lvl_for_enter = 25:
Entry level for buy stop order = 125% fibo at range
Entry level for sell stop order = -25% fibo at range

Example for sl_for_order = 25:
StopLoss level for buy order = High of range - 25% = 75% fibo
StopLoss level for sell order = Low of range + 25% = 25% fibo
*/


void OnStart() {

      if(DayOfWeek() == 3 || DayOfWeek() == 4 || DayOfWeek() == 5)   
      {
      int hh_index = iHighest(NULL, PERIOD_D1, MODE_HIGH, 2, 0);
      if(hh_index != -1) double hh = High[hh_index];

      int ll_index = iLowest(NULL, PERIOD_D1, MODE_LOW, 2, 0);
      if(ll_index != -1) double ll = Low[ll_index];

      if (tp_in_point > 0) {
         double tp_buy = NormalizeDouble(getFibPrice(hh, ll, 100+lvl_for_enter) + tp_in_point*Point, Digits);
         double tp_sell = NormalizeDouble(getFibPrice(hh, ll, 0-lvl_for_enter) - tp_in_point*Point, Digits);
      }

      int order_buy = OrderSend(Symbol(), OP_BUYSTOP, 0.01, getFibPrice(hh, ll, 100+lvl_for_enter), 10, getFibPrice(hh, ll, 100-sl_for_order), tp_buy, NULL, MagicNumber, 0, clrLime);
      int order_sell = OrderSend(Symbol(), OP_SELLSTOP, 0.01, getFibPrice(hh, ll, 0-lvl_for_enter), 10, getFibPrice(hh, ll, 0+sl_for_order), tp_sell, NULL, MagicNumber, 0, clrRed);
   }
}

double getFibPrice(double high, double low, double fiboLevel) {
   fiboLevel = fiboLevel/100;
   double D=high-low;
   double V=D*fiboLevel;
   double price=V+low;
   
   return(NormalizeDouble(price, Digits));
}

fxsaber
19370
fxsaber  
Thomas Knudsen:

Anyone that can convert this script to MT5?

#define MT4_TICKET_TYPE // Обязываем OrderSend и OrderTicket возвращать значение такого же типа, как в MT4 - int.
#include <KimIVToMT5.mqh> // https://www.mql5.com/ru/forum/93352/page32#comment_10603352
#undef MODE_HIGH
#undef MODE_LOW

//+------------------------------------------------------------------+
//|                                            motu_script_Daily.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "0xff"
#property link      ""
#property script_show_inputs

string VERSION = "motu_script_Daily";


input int lvl_for_enter = 25; // %fibo +- High and Low monday&tuesday range for entry level
input int sl_for_order = 50; // %fibo +- for stoploss at range
input int tp_in_point = 200; // take profit
input int MagicNumber = 29022020;
/*
Example for lvl_for_enter = 25:
Entry level for buy stop order = 125% fibo at range
Entry level for sell stop order = -25% fibo at range

Example for sl_for_order = 25:
StopLoss level for buy order = High of range - 25% = 75% fibo
StopLoss level for sell order = Low of range + 25% = 25% fibo
*/


void OnStart() {
  double hh = 0, ll = 0;
  double tp_buy = 0, tp_sell = 0;

    #define double
      if(DayOfWeek() == 3 || DayOfWeek() == 4 || DayOfWeek() == 5)   
      {
      int hh_index = iHighest(NULL, PERIOD_D1, MODE_HIGH, 2, 0);
      if(hh_index != -1) double hh = High[hh_index];

      int ll_index = iLowest(NULL, PERIOD_D1, MODE_LOW, 2, 0);
      if(ll_index != -1) double ll = Low[ll_index];

      if (tp_in_point > 0) {
         double tp_buy = NormalizeDouble(getFibPrice(hh, ll, 100+lvl_for_enter) + tp_in_point*Point, Digits);
         double tp_sell = NormalizeDouble(getFibPrice(hh, ll, 0-lvl_for_enter) - tp_in_point*Point, Digits);
      }
    #undef double
      int order_buy = OrderSend(Symbol(), OP_BUYSTOP, 0.01, getFibPrice(hh, ll, 100+lvl_for_enter), 10, getFibPrice(hh, ll, 100-sl_for_order), tp_buy, NULL, MagicNumber, 0, clrLime);
      int order_sell = OrderSend(Symbol(), OP_SELLSTOP, 0.01, getFibPrice(hh, ll, 0-lvl_for_enter), 10, getFibPrice(hh, ll, 0+sl_for_order), tp_sell, NULL, MagicNumber, 0, clrRed);
   }
}

double getFibPrice(double high, double low, double fiboLevel) {
   fiboLevel = fiboLevel/100;
   double D=high-low;
   double V=D*fiboLevel;
   double price=V+low;
   
   return(NormalizeDouble(price, Digits));
}
Thomas Knudsen
363
Thomas Knudsen  
fxsaber:

Thank you very much. That was quick! Now i would like to combine it with this MT4 code, so that the lines are drawn on the chart too.

The idea is to:

- Run the script
- Create the objects
- And place the pending orders from the last script.

Here is the code:

//+------------------------------------------------------------------+
//|                                                      Sundays.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
//default settings

  int       cnt;
  string    cnttxt;
  double    tmp1; 
  double    tmp2; 
  int       tdw;

  double values[5];

int start()
  {
  
  ObjectsDeleteAll();
  tmp1=WindowPriceMax();
  tmp2=WindowPriceMin();
 
 for(cnt=0;cnt<100;cnt++)
  {
  
   tdw=TimeDayOfWeek(iTime(NULL,1440,cnt));

   if(tdw==2)
   {

   cnttxt=IntegerToString(cnt,3);
 //  ObjectCreate("DayOpenTime"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),tmp2,iTime(NULL,1440,cnt+1),tmp1);
   ObjectSet("DayOpenTime"+cnttxt,OBJPROP_COLOR,DarkGray);
   ObjectSet("DayOpenTime"+cnttxt,OBJPROP_BACK,1);
   ObjectSet("DayOpenTime"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("DayOpenTime"+cnttxt,OBJPROP_STYLE,2);
   ObjectSetText("DayOpenTime"+cnttxt,"Monday");
//~~~~~~~~~~~~~~~~~~~~~~
   
   double Hi=iHigh(NULL,1440,cnt+1); if(iHigh(NULL,1440,cnt+1)<iHigh(NULL,1440,cnt)) {Hi=iHigh(NULL,1440,cnt);}
   double Lo=iLow(NULL,1440,cnt+1);  if(iLow(NULL,1440,cnt+1)>iLow(NULL,1440,cnt))    {Lo=iLow(NULL,1440,cnt);}


   ObjectCreate("Fib1"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Hi,iTime(NULL,1440,cnt+1)+(5*1440*60),Hi);
   ObjectSetText("Fib1"+cnttxt," ");
   ObjectSet("Fib1"+cnttxt,OBJPROP_COLOR,DarkGray);
   ObjectSet("Fib1"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib1"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib1"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib1"+cnttxt,OBJPROP_RAY,0);

   ObjectCreate("Fib2"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Lo,iTime(NULL,1440,cnt+1)+(5*1440*60),Lo);
   ObjectSetText("Fib2"+cnttxt," ");
   ObjectSet("Fib2"+cnttxt,OBJPROP_COLOR,DarkGray);
   ObjectSet("Fib2"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib2"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib2"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib2"+cnttxt,OBJPROP_RAY,0);

   ObjectCreate("Fib3"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Hi+((Hi-Lo)*.10),iTime(NULL,1440,cnt+1)+(5*1440*60),Hi+((Hi-Lo)*.10));
   ObjectSetText("Fib3"+cnttxt,"Long");
   ObjectSet("Fib3"+cnttxt,OBJPROP_COLOR,Green);
   ObjectSet("Fib3"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib3"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib3"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib3"+cnttxt,OBJPROP_RAY,0);

   ObjectCreate("Fib4"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Lo-((Hi-Lo)*.10),iTime(NULL,1440,cnt+1)+(5*1440*60),Lo-((Hi-Lo)*.10));
   ObjectSetText("Fib4"+cnttxt,"Short");
   ObjectSet("Fib4"+cnttxt,OBJPROP_COLOR,Crimson);
   ObjectSet("Fib4"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib4"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib4"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib4"+cnttxt,OBJPROP_RAY,0);

   ObjectCreate("Fib5"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Lo+((Hi-Lo)*.50),iTime(NULL,1440,cnt+1)+(5*1440*60),Lo+((Hi-Lo)*.50));
   ObjectSetText("Fib5"+cnttxt,"??");
   ObjectSet("Fib5"+cnttxt,OBJPROP_COLOR,DarkOrange);
   ObjectSet("Fib5"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib5"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib5"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib5"+cnttxt,OBJPROP_RAY,0);
   }

  }
  return(0);
  }
//+------------------------------------------------------------------+
fxsaber
19370
fxsaber  
Thomas Knudsen:

Thank you very much. That was quick! Now i would like to combine it with this MT4 code, so that the lines are drawn on the chart too.

Further already themselves.

Thomas Knudsen
363
Thomas Knudsen  
fxsaber:

Further already themselves.

What do you mean? If i add it to the code, it will give error. Does not seem to work in MT5.

Thomas Knudsen
363
Thomas Knudsen  

Im trying to make this code draw objects in MT5. I have come so far that i makes no errors. But I think there is a fault in the array where it count to 100. 

tdw=TimeDayOfWeek(iTime(NULL,1440,cnt));

This part wont return other than a value of 1, but i need it to count through the days of the week to make the "if" function work and draw correct.
Right now all the object is drawn in front of the current bar.

Im including mql4compat.mph

Any one that can trouble shoot on this?

Full code here:

#define MT4_TICKET_TYPE
#include <mql4compat.mqh>

//+------------------------------------------------------------------+
//|                                              MoTu_Fib_levels.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
//default settings

  int       cnt;
  string    cnttxt;
  double    tmp1; 
  double    tmp2; 
  int       tdw;

//  double values[5];

int OnStart()
{
  
  ObjectsDeleteAllMQL4();
  tmp1=WindowPriceMax();
  tmp2=WindowPriceMin();
 
 for(cnt=0;cnt<100;cnt++)
  {
  
   tdw=TimeDayOfWeek(iTime(NULL,1440,cnt));

   if(tdw==2)
   {

   cnttxt=IntegerToString(cnt,3);
//   ObjectCreate("DayOpenTime"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),tmp2,iTime(NULL,1440,cnt+1),tmp1);
   ObjectSet("DayOpenTime"+cnttxt,OBJPROP_COLOR,DarkGray);
   ObjectSet("DayOpenTime"+cnttxt,OBJPROP_BACK,1);
   ObjectSet("DayOpenTime"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("DayOpenTime"+cnttxt,OBJPROP_STYLE,2);
   ObjectSetText("DayOpenTime"+cnttxt,"Monday",8,NULL,clrAliceBlue);
//~~~~~~~~~~~~~~~~~~~~~~
   
   double Hi=iHigh(NULL,1440,cnt+1); if(iHigh(NULL,1440,cnt+1)<iHigh(NULL,1440,cnt)) {Hi=iHigh(NULL,1440,cnt);}
   double Lo=iLow(NULL,1440,cnt+1);  if(iLow(NULL,1440,cnt+1)>iLow(NULL,1440,cnt))    {Lo=iLow(NULL,1440,cnt);}
   
   ObjectCreateMQL4("Fib1"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Hi,iTime(NULL,1440,cnt+1)+(5*1440*60),Hi);
   ObjectSetText("Fib1"+cnttxt," ",8,NULL,clrAliceBlue);
   ObjectSet("Fib1"+cnttxt,OBJPROP_COLOR,DarkGray);
   ObjectSet("Fib1"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib1"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib1"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib1"+cnttxt,OBJPROP_RAY,0);

   ObjectCreateMQL4("Fib2"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Lo,iTime(NULL,1440,cnt+1)+(5*1440*60),Lo);
   ObjectSetText("Fib2"+cnttxt," ",8,NULL,clrAliceBlue);
   ObjectSet("Fib2"+cnttxt,OBJPROP_COLOR,DarkGray);
   ObjectSet("Fib2"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib2"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib2"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib2"+cnttxt,OBJPROP_RAY,0);

   ObjectCreateMQL4("Fib3"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Hi+((Hi-Lo)*.10),iTime(NULL,1440,cnt+1)+(5*1440*60),Hi+((Hi-Lo)*.10));
   ObjectSetText("Fib3"+cnttxt,"Long",8,NULL,clrAliceBlue);
   ObjectSet("Fib3"+cnttxt,OBJPROP_COLOR,Green);
   ObjectSet("Fib3"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib3"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib3"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib3"+cnttxt,OBJPROP_RAY,0);

   ObjectCreateMQL4("Fib4"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Lo-((Hi-Lo)*.10),iTime(NULL,1440,cnt+1)+(5*1440*60),Lo-((Hi-Lo)*.10));
   ObjectSetText("Fib4"+cnttxt,"Short",8,NULL,clrAliceBlue);
   ObjectSet("Fib4"+cnttxt,OBJPROP_COLOR,Crimson);
   ObjectSet("Fib4"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib4"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib4"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib4"+cnttxt,OBJPROP_RAY,0);

   ObjectCreateMQL4("Fib5"+cnttxt,OBJ_TREND,0,iTime(NULL,1440,cnt+1),Lo+((Hi-Lo)*.50),iTime(NULL,1440,cnt+1)+(5*1440*60),Lo+((Hi-Lo)*.50));
   ObjectSetText("Fib5"+cnttxt,"??",8,NULL,clrAliceBlue);
   ObjectSet("Fib5"+cnttxt,OBJPROP_COLOR,DarkOrange);
   ObjectSet("Fib5"+cnttxt,OBJPROP_BACK,0);
   ObjectSet("Fib5"+cnttxt,OBJPROP_WIDTH,1);
   ObjectSet("Fib5"+cnttxt,OBJPROP_STYLE,2);
   ObjectSet("Fib5"+cnttxt,OBJPROP_RAY,0);
   }
  }
  return(0);
}
//+------------------------------------------------------------------+
msK146
45
msK146  
Hi traders, Can someone convert this indicator to mt5 please? thank you
Files:
Pivot.mq4 17 kb
masayuki1313
73
masayuki1313  
Could anyone convert this indicator to mq5 file?
Files: