EA works only on "step index"

 
//+------------------------------------------------------------------+
//|                                                      MACD EA.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Trade/Trade.mqh>
#include <Trade/PositionInfo.mqh>

//---Declaration of EA Properties
input double               StopLoss      =50;       // Stop Loss in Pips
input double               TakeProfit    =50;       // Take Profit in Pips
input int                  EA_MagicNumber=123406;   // Magic Number
//input double               TickValue;      // Lot Size
input int                  Slippage      =10;
//---Declaration of EA INPUT VARIABLES
input int                  FastEMA       =9;
input int                  SlowEMA       =26;
input int                  MacdSMA       =9;
input ENUM_APPLIED_PRICE   AppliedPrice  =PRICE_CLOSE;

//---Declaration of other global variables
int MacdHandle;

double MainLine[];
double SignalLine[];
   
double STP;
double TKP;
datetime m_prev_bars               =0;        // "0" -> D'1970.01.01 00:00';

//Creating some objects
CTrade *Trade;
CPositionInfo PositionInfo;

//---Minimum lot size
double Min_Lot;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---Getting the Indicator handle
   MacdHandle=iMACD(Symbol(),PERIOD_CURRENT,FastEMA,SlowEMA,MacdSMA,AppliedPrice);
   
   //--- checking if valid handle is obtained
   if(MacdHandle<0)
     {
      Alert("Error obtaining indicator handle. Error: ",GetLastError());
      return(INIT_FAILED);
     }
   
//---Initializing trade objects
Trade = new CTrade;
Trade.SetDeviationInPoints(Slippage);
Trade.SetExpertMagicNumber(EA_MagicNumber);



//--- standardizing the currency digits
   STP=StopLoss*Point();
   TKP=TakeProfit*Point();
   if(Digits() == 5 || Digits() == 3)
     {
      STP=STP*10.0;
      TKP=TKP*10.0;
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- releasing indicator handle
   IndicatorRelease(MacdHandle);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
//---Minimum lot size

 Min_Lot = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
 Alert("Minimum lot size is: ",Min_Lot);
 
 
//--- we work only at the time of the birth of new bar
   datetime time_0=iTime(Symbol(),Period(),0);
   if(time_0==m_prev_bars)
      return;
   m_prev_bars=time_0;
//--- checking if we have open trades
   if(PositionsTotal()>0)
      return;
//---
// defining MQL structures to be used for trading
   MqlTick latest_price;            //To be used to get the latest price information

//--- setting our arrays to the as series flag
   ArraySetAsSeries(MainLine,true);
   ArraySetAsSeries(SignalLine,true);
//--- checking if we have the latest price quote
   if(!SymbolInfoTick(Symbol(),latest_price))
     {
      Alert("Error getting latest price quote. Error: ",GetLastError());
      m_prev_bars=0;
      return;
     }
//--- copy and check indicator values
   if((CopyBuffer(MacdHandle,0,0,3,MainLine)!=3) || (CopyBuffer(MacdHandle,1,0,3,SignalLine)!=3))
     {
      Alert("Error copying the indicator buffers. Error: ",GetLastError());
      m_prev_bars=0;
      return;
     }
//--- buy position condition
   if((MainLine[1]>SignalLine[1]) && (MainLine[0]<SignalLine [0]))
     {
     fBuy();
     }
//--- sell position condition
   if((MainLine[1]<SignalLine[1]) && (MainLine[0]>SignalLine [0]))
     {
      fSell();
     }
  }
//+------------------------------------------------------------------+

//---Entering a buy order
void fBuy()
{
double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
Trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Min_Lot,Ask,Ask-STP,Ask+TKP);
}

//---Entering a sell order
void fSell()
{
double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
Trade.PositionOpen(_Symbol,ORDER_TYPE_SELL,Min_Lot,Bid,Bid+STP,Bid-TKP);
}






Please this EA works only on step index. It doesnt work on volatility indices and boom & crash. Please what could I have done wrongly???
 
Chinwendu Evans: Please this EA works only on step index. It doesnt work on volatility indices and boom & crash. Please what could I have done wrongly???

How on the earth do you expect us to know? Do you seriously expect an answer with so little information?

 
Fernando Carreiro #:

How on the earth do you expect us to know? Do you seriously expect an answer with so little information?

Oh! Sorry, I added the codes but I didn't notice that they didn't appear. I just updated it now, thank you.

 
Chinwendu Evans #: Oh! Sorry, I added the codes but I didn't notice that they didn't appear. I just updated it now, thank you.

Just because you have now added the code, does not make it any more informative.

Please explain in detail what it is you are trying to achieve and what is the problem. Provide details on all the aspects and if possible, provide visual aids such as screenshots.

 
Fernando Carreiro #:

Just because you have now added the code, does not make it any more informative.

Please explain in detail what it is you are trying to achieve and what is the problem. Provide details on all the aspects and if possible, provide visual aids such as screenshots.

The code works fine on currency pairs and step index but it doesn't open trades when placed on a volatility indices and boom and crash. So the challenge is not opening trades on volatility indices and boom and crash
 
Chinwendu Evans #: The code works fine on currency pairs and step index but it doesn't open trades when placed on a volatility indices and boom and crash. So the challenge is not opening trades on volatility indices and boom and crash

I will repeat ... provide details on all the aspects and if possible, provide visual aids such as screenshots.

What specific symbols are you referring to? Show the contract specifications for the affected symbols.

Show the EA inputs being used for each instance of symbol and/or timeframe.

What problems or errors are being reported in the log files?

etc.

 

Hi Chinwendu Evans ...Pleaase change  Min lot  to RISK Money management: to improve the code.. 

#include <Expert\Money\MoneyFixedMargin.mqh>
CMoneyFixedMargin *m_money;
//+------------------------------------------------------------------+
//| Enum Lor or Risk                                                 |
//+------------------------------------------------------------------+
enum ENUM_LOT_OR_RISK
  {
   lot=0,   // Constant lot
   risk=2,  // Risk in percent for a deal
  };

thanks..