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

MQL4 Uzman Danışmanlar

İş tamamlandı

Tamamlanma süresi: 2 gün

İş Gereklilikleri

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.


Yanıtlandı

1
Geliştirici 1
Derecelendirme
(7)
Projeler
21
33%
Arabuluculuk
1
0% / 0%
Süresi dolmuş
1
5%
Yüklendi
2
Geliştirici 2
Derecelendirme
(13)
Projeler
17
35%
Arabuluculuk
0
Süresi dolmuş
0
Çalışıyor
3
Geliştirici 3
Derecelendirme
(172)
Projeler
221
57%
Arabuluculuk
7
29% / 29%
Süresi dolmuş
7
3%
Çalışıyor
4
Geliştirici 4
Derecelendirme
(334)
Projeler
525
32%
Arabuluculuk
23
65% / 9%
Süresi dolmuş
15
3%
Ücretsiz
5
Geliştirici 5
Derecelendirme
(63)
Projeler
75
55%
Arabuluculuk
0
Süresi dolmuş
0
Ücretsiz
Benzer siparişler
Need to create ea to trade in indian market by placing orders to Indian market platform through API form mqlHere's a basic outline of what script should include: Define Heikin Ashi candle pattern: Convert regular candles to Heikin Ashi candles. Order Execution: Execute orders on the open of the second candle after the signal is generated. Buy Call: When a buy call is generated, initiate a call option order. Set
I want the trade to trigger anytime it sees the opportunity on all time frames, sl tp should be automated and all trades should be trigger anytime on cpi news and etc
Добрый день. Мне нужно создать сигнального бота. У меня есть индикатор на Trading View, который выделяет точку интереса - спрос/предложение. (но я в нем не уверен, подойдет ли он для робота, возможно такой индикатор нужно будет написать). Нужно чтоб все зоны были экстримальные, то есть, если произойдет пробитие зоны то менялся тренд. Как я торгую? Индикатор выделяет зону. Мне нужно увидеть подтверждение в пределах
Good day to you all i need a coder to add two indicators to my EA The EA is working it open and close trade according to rules It uses Two indicators with option to use Joint two indicator or use only a single indicators all function is working perfectly Now you will remove these two indicators and replace it with the two i will give you when you apply i will also describe some other key function which you need to
Im looking for a CTrader to MT4 trade copier dose any one have one of these im sure by now theres a few floating around. Om looking for one for C trade and one For Sway Markets as well
GRID BOT NOT FOR ROOKIES 110 - 180 USD
1 TO 1 WITH THE FILE I SEND BELOW WILL WORK WITH THE SAME DEV FOR ALL FUTUR UPDATES we will talk before moving on selected MAKE SURE YOU READ THE FULL SPEC BEFORE MOVING FOWARD
Trade pad 30 - 70 USD
In need of trade pad that is able to perform the following: 1. Place multiple trades base on lot size risk. Example 1.50 Lot size can be split in 3 entries(according to desired setting) 2. Can auto adjust SL and Tp as per desired rr, and by dragging sL line tp line will adjust even the trade is ongoing. 3. Can manage close all, close profit, close loss, close each symbol/pair. 4. Can close as per desired total loss
This is a Ready Made grid Automatic EA 1.Need some bug fixing and little modification. This EA has some bug like -Place Random Trade after MT4 Restart . add RSI logic if rsi30 open buy trade this is a martingale ea make this logic Revise Order mode. (anti-martingle grid )
Hello there , I need someone to do basic super trend strategy EA MT5 code for based on SuperTrend Basic Note: 1]Should work on all timeframe 2]Everything which has number should be customizable number, like SuperTrend Indicator Input, Qty, TSL etc 3] Entry/Exit should happen on candle close 4] If the trend dont change for long ( e.g 2-3 days) the trade should go on. Its not an intraday trade. Entry condition: On
I need a trading bot 30 - 40 USD
I'm in need of a trading bot, based on 3 mt4 indicators, which are semafor alert, reversals and bluever.I want the signals produced by the indicators to be automated and run on mt5 platform, trade anything including synthetic indices and works on any time frame

Proje bilgisi

Bütçe
30+ USD
Geliştirici için
27 USD
Son teslim tarihi
to 3 gün