Fix my practiced code, help me to get the value at D1 when the current chat is H1

MQL4 Experts

Job finished

Execution time 2 days

Specification

Here is a a simply EMA crossing up and down strategy for coding practice, just 2 criteria, 

For opening long:

1. n D1 chart, EMA 24 over EMA 60
2. In H1 chart, EMA 24 crossing up EMA 60

For opening short:
  
1. In D1 chart, EMA 24 below EMA 60
2. In H1 chart, EMA 24 crossing down EMA 60


I tried to code myself, pls help me to fix it, and the most tackle part is when the current chat I am using is H1, how can I get the values of D1 (I know it seems not easy to do that in Mql4, hope you can teach me a simply way)

And for H1 chart crossing up and down, it seems I made mistakes too, cos the backtesting doen’t really show me the signal when it is crossing up and down, so pls help me to review them too





And here is my code:

//+------------------------------------------------------------------+
//|                                       Basic Learning Modules.mq4 |
//|                        Copyright 2022, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


//1.Basic Setting
//2.Basic detect Enter & Exit
//3.Simple EA by EMA crossover & RSI

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

//1.Basic Settng
// Define global variables
extern int Profit_target=200;//extern可在外面改動數值
extern int Stop_loss=100;
extern int fastema = 24;
extern int slowema = 60;
input int Magic_num = 0001;
extern double Lot_size = 10;



//2.Basic detect Enter & Exit


void OnTick()
  {
//---
   // Get the profit target price and the stop loss price
   double Long_TakeProfitLevel = Bid + Profit_target*Point; //0.0001
   double Long_StopLossLevel = Bid - Stop_loss*Point;
   double Short_TakeProfitLevel = Ask - Profit_target*Point; //0.0001
   double Short_StopLossLevel = Ask + Stop_loss*Point;   
   
   // Check if the long condition happen and place order accordingly
   if (Enter_long()&& OrdersTotal()==0 ) //if more the one signal, could be Enter_long1, Enter long2 or Signal1, Signal2... //OrdersTotal depend on strategy
   {   
  
   Open_Enter_long(Lot_size,Long_TakeProfitLevel,Long_StopLossLevel,"First_Enter");  

   }
   else if (Exit_long() && OrdersTotal()>0)
   {
      Close_Exit_long("Close_Exit_long");
   }
   
   // Check if the short condition happen and place order accordingly
   if (Enter_short()&& OrdersTotal()==0 ) //if more the one signal, could be Enter_long1, Enter long2 or Signal1, Signal2... //OrdersTotal depend on strategy
   {   
  
   Open_Enter_short(Lot_size,Short_TakeProfitLevel,Short_StopLossLevel,"First_Enter");  

   }
   else if (Exit_short() && OrdersTotal()>0)
   {
      Close_Exit_short("Close_Exit_short");
   }   
   
  }



//3.EMA position in 1D chat

double get_daily_ma(int value, int mode,int shift=0){
   return iMA(NULL,1440,value,0,mode,PRICE_CLOSE,shift);
}

double daily_fast_ema_1 = get_daily_ma(fastema,1,1);
double daily_slow_ema_1 = get_daily_ma(slowema,1,1);

bool daily_ok_long()
{
  bool result=false;

  
  if ((daily_fast_ema_1 > daily_slow_ema_1)  && OrdersTotal()==0 )
  {
     result=true;
  }
  else
  {
    result=false;
  }
  
  return(result);
}



bool daily_ok_short()
{
  bool result=false;

  
  if ((daily_fast_ema_1 < daily_slow_ema_1)  && OrdersTotal()==0 )
  {
     result=true;
  }
  else
  {
    result=false;
  }
  
  return(result);
}





//4.Simple EA by EMA crossover in current chat

// Function used to calculate the current EMAs, should be Global 

double get_ma(int value, int mode,int shift=0){
   return iMA(NULL,0,value,0,mode,PRICE_CLOSE,shift);
}


//Global variables to use in Enter & Exit checking

double fast_ema_1 = get_ma(fastema,1,1);
double fast_ema_2 = get_ma(fastema,1,2);
double slow_ema_1 = get_ma(slowema,1,1);
double slow_ema_2 = get_ma(slowema,1,2);


  
// Function to check if enter long condition happen
bool Enter_long()
{
  bool result=false;

 
  if ((fast_ema_1 >= slow_ema_1 && fast_ema_2 < slow_ema_2)  && OrdersTotal()==0 )
  {
     result=true;
  }
  else
  {
    result=false;
  }
  
  return(result);
}


bool Enter_short()
{
  bool result=false;

  // sma20_0 > sma50_0 && sma20_1 < sma50_1 && rsi9 <=RSI_lower && OrdersTotal()==0
  if (( slow_ema_1 >= fast_ema_1 &&  slow_ema_2 < fast_ema_2)  && OrdersTotal()==0 )
  {
     result=true;
  }
  else
  {
    result=false;
  }
  
  return(result);
}


// Function to check if exit long condiftion happens

bool Exit_long()
{
  bool result=false;

  
  if ((fast_ema_1 <= slow_ema_1 && fast_ema_2 > slow_ema_2)  && OrdersTotal()>0)
  {
     result=true;
  }
  else
  {
    result=false;
  }
  
  return(result);
}


// Function to check if exit short // Function to check if exit long condiftion happens

bool Exit_short()
{
  bool result=false;

  
  if ((slow_ema_1 <= fast_ema_1 && slow_ema_2 > fast_ema_2) && OrdersTotal()>0)
  {
     result=true;
  }
  else
  {
    result=false;
  }
  
  return(result);
} 



// Function to place long order 
void Open_Enter_long(double lot,double profit_target, double stop_loss,string COMMENT)
  {
//---
      int ticket=OrderSend(NULL , OP_BUY, lot, Ask, 10, stop_loss, profit_target);
  
      
      if (ticket<0)
         {      
         Print("OrderSelect returned the error of ",GetLastError());
         }      
  }
  
// Function to exit long order

void Close_Exit_long(string COMMENT)
{
 
   for (int i=OrdersTotal()-1;i>=0;i--)
   {
      if (OrderSelect(i,SELECT_BY_POS)&& OrderType()==OP_BUY)
      {
         bool result=OrderClose(OrderTicket(),OrderLots(),Bid,10,Red);
         if (result==false)
         {
           Print("Orders could not be closed due to the error "+string(GetLastError()));
         }       
         
      
      }
     else if (OrderSelect(i,SELECT_BY_POS)&& OrderType()==OP_SELL)
      {
         bool result=OrderClose(OrderTicket(),OrderLots(),Ask,10,Red);
         if (result==false)
         {
           Print("Orders could not be closed due to the error "+string(GetLastError()));
         }       
         
      
      }
     
   }
   Print("Orders close due to:"+COMMENT); 
 

}

// Function to place short order 
void Open_Enter_short(double lot,double profit_target, double stop_loss,string COMMENT)
  {
//---
      int ticket=OrderSend(NULL , OP_SELL, lot, Bid, 10, stop_loss, profit_target);
  
      
      if (ticket<0)
         {      
         Print("OrderSelect returned the error of ",GetLastError());
         }      
  }
  
// Function to exit short order

void Close_Exit_short(string COMMENT)
{
 
   for (int i=OrdersTotal()-1;i>=0;i--)
   {
      if (OrderSelect(i,SELECT_BY_POS)&& OrderType()==OP_SELL)
      {
         bool result=OrderClose(OrderTicket(),OrderLots(),Ask,10,Red);
         if (result==false)
         {
           Print("Orders could not be closed due to the error "+string(GetLastError()));
         }       
         
      
      }
     else if (OrderSelect(i,SELECT_BY_POS)&& OrderType()==OP_BUY)
      {
         bool result=OrderClose(OrderTicket(),OrderLots(),Bid,10,Red);
         if (result==false)
         {
           Print("Orders could not be closed due to the error "+string(GetLastError()));
         }       
         
      
      }
     
   }
   Print("Orders close due to:"+COMMENT); 
 

}


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

i am not good at coding, i hope you can give me simple description on important line of code to tell how or why you need to fix it , and the code must be testable by backtest , then i can check it faster and pay you faster, and both of us win-wn.


Responded

1
Developer 1
Rating
(7)
Projects
20
35%
Arbitration
1
0% / 0%
Overdue
1
5%
Loaded
2
Developer 2
Rating
(10)
Projects
15
33%
Arbitration
0
Overdue
0
Working
3
Developer 3
Rating
(167)
Projects
215
57%
Arbitration
8
25% / 25%
Overdue
7
3%
Working
4
Developer 4
Rating
(329)
Projects
519
32%
Arbitration
23
65% / 9%
Overdue
15
3%
Free
5
Developer 5
Rating
(63)
Projects
75
55%
Arbitration
0
Overdue
0
Free
Similar orders
Good day programmers ,I need a simple robot that will not place trade, that doesn't do anything, like I want it to be like a strategy tester to me , I want to do things manually
Hello here I am in need of an NT8 developer which can create a custom strategy for NT8 Kindly bid on this if you are an Expert in Ninjatrader Thank you
Hello I have two files in mt4 , I want to convert them to mt5 if you are available and ready to take the job, please let me know I am interested to start the job immediately. Need good experience in socket programming. Regards
Hey greetings to you all. I need an expert Metatrader 5 developer that have successfully developed a profitable Mt5 EA I can buy with high win rate . Kindly bid if you have one with backtesting results prove and let discuss about the price . Thanks
Hello! i want to create a simple EA that enters trade and exit with TP SL trailling stop and breakEven / Lots Size options , 2 indicators volume and Vwap that i already have ( vwap is in mt4 need to be transfered to mt5 . ) Requierement : buy at next candle when it close above the vwap / sell at next candle when it close beyond the vwap volume indicator should be green to enter the trade exemple of the strategy in
Guten Tag, benötigt wird eine Software die Trades auf einem MT4 oder MT5 kopiert und auf die xStation übergibt: http://developers.xstore.pro/documentation/ Auf dem MT4/5 Chart muss ein Hinweis stehen und wie die aktuelle Verbindung ist. Einstellbar wie zum Beispiel https://forexcopier.com/features Es reicht wenn man es in MT4/5 Settings einstellen kann. Es muss kein Extra Programm sein. Gerne aber als Option mit
I hope this message finds you well. I am in search of a FREE skilled developer to transform three indicators into a fully functional trading robot. These indicators consist of two MACD indicators, each displaying two colors (red and green), along with a RED arrow signal. Here are the specific requirements for the project: The robot should execute trades only when the RED arrow signal appears and both MACD indicators
Hello, Thank you for reviewing the job description. We're in need of an experienced developer to finalize an EA that's currently in progress. We'll provide the source code of the EA for implementing necessary changes to resolve the existing bugs. The EA is primarily based on price action patterns and includes risk management features and an indicator. All required features have been added to the EA; we simply need to
Commentaire - permet au conseiller d'afficher un commentaire lorsqu'il prend un ordre. Trade Buy - activation/désactivation d'un achat . Trade Sell - activation/désactivation d'une vente. Utiliser la couverture - permet au conseiller de négocier dans les deux sens, achat et vente. Taille de lot - taille de lot pour chaque commande. Utiliser Money Management - activation/désactivation du calcul
p.p1 {margin: 0.0px 0.0px 12.0px 0.0px; font: 16.0px Times; color: #353535; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 12.0px 0.0px; font: 16.0px Times; color: #353535; background-color: #ffffff; min-height: 19.0px} I want to be clear before we start, so you are going to build me an expert advisor that works on MT5, that will also require an authorisation to work (like a license key, like the expert advisor

Project information

Budget
30+ USD
For the developer
27 USD
Deadline
to 3 day(s)