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

MQL4 전문가

작업 종료됨

실행 시간 2 일

명시

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.


응답함

1
개발자 1
등급
(8)
프로젝트
22
32%
중재
1
0% / 0%
기한 초과
1
5%
로드됨
2
개발자 2
등급
(13)
프로젝트
17
35%
중재
0
기한 초과
0
작업중
3
개발자 3
등급
(172)
프로젝트
221
57%
중재
7
29% / 29%
기한 초과
7
3%
작업중
4
개발자 4
등급
(334)
프로젝트
525
32%
중재
23
65% / 9%
기한 초과
15
3%
무료
5
개발자 5
등급
(63)
프로젝트
75
55%
중재
0
기한 초과
0
무료
비슷한 주문
Requirements All features of indicators, plus enter into trades (buy, sell) TP and SL according to the indicator [TP1 and TP2] Can make MT5 from MT4 indicator? Add trailing stop loss trading hours trading days Max spread Possibility of Multiple charts through one window Daily profit Target [yes/no]
hello... saya menginginkan EA GRID?AVERAGING dengan kondisi : > bisa meletakan sell&buy Limit pada nilai tertentu > bisa meletakkan sell&buy stop pada nilai tertentu > bisa melakukan order sell/buy limit/stop (sesuai setting) berdasarkan Nilai RSI > bisa membatasi jumlah order > ada fungsi TP dan SL > rangkuman hasil kerja EA selama mingguan terimakasih, semoga bisa bekerjasama dengan baik
I already have the EA completed. I just need to add 2 params and fix the feature (GV) to make sure that no order is missed for any reason. Maybe GV is not enough and need to add another feature
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

프로젝트 정보

예산
30+ USD
개발자에게
27 USD
기한
 3 일