EA for color MA (BUY when MA Chane to green and Sell When MA change to Red)

ENEZA PETER MKIRAMWENI
280
ENEZA PETER MKIRAMWENI  

hi any one can help me the EA of the attached file of indicator

Buy when Ma change to green and Sell When MA change to Red

#include<Trade\Trade.mqh>

CTrade trade;
MqlTick Tick;


int ma_colored;

datetime MAXIMO=D'2021.10.16 00:00';

double MaBuffer[];

input double VOLUME=0.01;//Lot
input double TP=30; //Take Profit(PIPS)
input double SL=30;//StopLoss(PIPS)

enum ENUM_TYPE_ORDER
{
    ORDER_BUY=0,
    ORDER_SELL=1,
    BUY_AND_SELL=2,
};

input  ENUM_TYPE_ORDER   TYPE_ORDERS=2; 
input string Separate="--------------------------------------";
input string Separate2="----INDICATOR PARAMETERS----";


enum enMATypes
{
   _sma,    // Simple 
   _ema,    // Exponential 
   _smma,   // Smoothed 
   _lwma    // Linear weighted 
};

input int                  MaPeriod    = 9;           // Period    
input enMATypes            MaMethod    = _sma;      // Method   
input ENUM_APPLIED_PRICE   Price       = PRICE_CLOSE;    // Price
double StopLoss;
double TakeProfit;


int OnInit()
  {
   if(MAXIMO<TimeCurrent()){
   return INIT_PARAMETERS_INCORRECT;
   }
  
   double points=SymbolInfoDouble(Symbol(),SYMBOL_POINT);
   StopLoss=SL*points;
   TakeProfit=TP*points;
   //KALMAN_FILTER=iCustom(Symbol(),PERIOD_CURRENT,"Kalman_filter_2",inpTimeFrame,inpPeriod,inpPrice,inpInterpolate);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   ma_colored(MaBuffer);
   double bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
   double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); 
   
   int total=PositionsTotal();
   int OrdersBuy=0, OrdersSell=0;
   for(int i=0; i<total; i++)
     {
      //--- parámetros de la orden
      ulong  position_ticket=PositionGetTicket(i);// ticket de la posición
      string position_symbol=PositionGetString(POSITION_SYMBOL); // símbolo
      ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);  // tipo de posición
       if(type==POSITION_TYPE_BUY)
        {
         OrdersBuy++;
        }
       if(type==POSITION_TYPE_SELL)
        {
         OrdersSell++;
        }
     }
   
   
   if(TYPE_ORDERS==2 || TYPE_ORDERS==1){
   if(MaBuffer[1]==2 && MaBuffer[2]==1  && OrdersSell==0 ){
   Comment("Entro sell",MaBuffer[0]," ",MaBuffer[1]," ",MaBuffer[2]);
   trade.Sell(VOLUME,Symbol(),ask,ask+StopLoss,ask-TakeProfit,"");
   }}
   
   if(TYPE_ORDERS==2 || TYPE_ORDERS==0){
   if (MaBuffer[1]==1 && MaBuffer[2]==2  && OrdersBuy==0){
   Comment("Entro buy",MaBuffer[0]," ",MaBuffer[1]," ",MaBuffer[2]);
   trade.Buy(VOLUME,Symbol(),bid,ask-StopLoss,ask+TakeProfit,"");
   }}
//---
   //Comment(BufferKalman[1]);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+

void ma_colored(double &BufferIndicador[])
  {
   int handleIndicador;
   handleIndicador=iCustom(Symbol(),PERIOD_CURRENT,"ma_colored",MaPeriod,MaMethod,Price);
//ArraySetAsSeries(iMABuffer,true);
   while(CopyBuffer(handleIndicador,1,0,3,BufferIndicador)<0)
     {
      Sleep(5);
     };
   ArrayReverse(BufferIndicador,0,3);}
Files:
Keith Watford
Moderator
28222
Keith Watford  
ENEZA PETER MKIRAMWENI:

hi any one can help me the EA of the attached file of indicator

Buy when Ma change to green and Sell When MA change to Red

I am absolutely certain that you have already been told in your other topics that you MUST create the indicator handle only once and in OnInit().

ENEZA PETER MKIRAMWENI
280
ENEZA PETER MKIRAMWENI  
Keith Watford:

I am absolutely certain that you have already been told in your other topics that you MUST create the indicator handle only once and in OnInit().

#include<Trade\Trade.mqh>

CTrade trade;
MqlTick Tick;


int ma_colored;

datetime MAXIMO=D'2021.10.16 00:00';

double MaBuffer[];

input double VOLUME=0.01;//Lot
input double TP=30; //Take Profit(PIPS)
input double SL=30;//StopLoss(PIPS)

enum ENUM_TYPE_ORDER
{
    ORDER_BUY=0,
    ORDER_SELL=1,
    BUY_AND_SELL=2,
};

input  ENUM_TYPE_ORDER   TYPE_ORDERS=2; 
input string Separate="--------------------------------------";
input string Separate2="----INDICATOR PARAMETERS----";


enum enMATypes
{
   _sma,    // Simple 
   _ema,    // Exponential 
   _smma,   // Smoothed 
   _lwma    // Linear weighted 
};

input int                  MaPeriod    = 9;           // Period    
input enMATypes            MaMethod    = _sma;      // Method   
input ENUM_APPLIED_PRICE   Price       = PRICE_CLOSE;    // Price
double StopLoss;
double TakeProfit;


int OnInit()
  {
   if(MAXIMO<TimeCurrent()){
   return INIT_PARAMETERS_INCORRECT;
   }
  
   double points=SymbolInfoDouble(Symbol(),SYMBOL_POINT);
   StopLoss=SL*points;
   TakeProfit=TP*points;
   ma_colored=iCustom(Symbol(),PERIOD_CURRENT,"ma_colored",MaPeriod,MaMethod,Price);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   ma_colored(MaBuffer);
   double bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
   double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); 
   
   int total=PositionsTotal();
   int OrdersBuy=0, OrdersSell=0;
   for(int i=0; i<total; i++)
     {
      //--- parámetros de la orden
      ulong  position_ticket=PositionGetTicket(i);// ticket de la posición
      string position_symbol=PositionGetString(POSITION_SYMBOL); // símbolo
      ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);  // tipo de posición
       if(type==POSITION_TYPE_BUY)
        {
         OrdersBuy++;
        }
       if(type==POSITION_TYPE_SELL)
        {
         OrdersSell++;
        }
     }
   
   
   if(TYPE_ORDERS==2 || TYPE_ORDERS==1){
   if(MaBuffer[1]==2 && MaBuffer[2]==1  && OrdersSell==0 ){
   Comment("Entro sell",MaBuffer[0]," ",MaBuffer[1]," ",MaBuffer[2]);
   trade.Sell(VOLUME,Symbol(),ask,ask+StopLoss,ask-TakeProfit,"");
   }}
   
   if(TYPE_ORDERS==2 || TYPE_ORDERS==0){
   if (MaBuffer[1]==1 && MaBuffer[2]==2  && OrdersBuy==0){
   Comment("Entro buy",MaBuffer[0]," ",MaBuffer[1]," ",MaBuffer[2]);
   trade.Buy(VOLUME,Symbol(),bid,ask-StopLoss,ask+TakeProfit,"");
   }}
//---
   //Comment(BufferKalman[1]);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+

void ma_colored(double &BufferIndicador[])
  {
  // int handleIndicador;
 //  handleIndicador=iCustom(Symbol(),PERIOD_CURRENT,"ma_colored",MaPeriod,MaMethod,Price);
//ArraySetAsSeries(iMABuffer,true);
   //while(CopyBuffer(handleIndicador,1,0,3,BufferIndicador)<0)
     {
      Sleep(5);
     };
   ArrayReverse(BufferIndicador,0,3);}
Can you help me the EA that Can do that
William Roeder
24287
William Roeder  
  1. Where do you attempt to read values from an indicator?

    Just get the value(s) of the indicator(s) into EA/indicator (using iCustom) and do what you want with it.

  2. Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
              How to call indicators in MQL5 - MQL5 Articles 12 March 2010

ENEZA PETER MKIRAMWENI
280
ENEZA PETER MKIRAMWENI  
William Roeder:
  1. Where do you attempt to read values from an indicator?

    Just get the value(s) of the indicator(s) into EA/indicator (using iCustom) and do what you want with it.

  2. Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
              How to call indicators in MQL5 - MQL5 Articles 12 March 2010

OK CAN YOU HELP ME TO GET EA OF THE ATTACHED INDICATOR

Keith Watford
Moderator
28222
Keith Watford  
ENEZA PETER MKIRAMWENI:

OK CAN YOU HELP ME TO GET EA OF THE ATTACHED INDICATOR

Please do not post in capital letters. It is very impolite.

People are unlikely to help you if you shout at them.

ENEZA PETER MKIRAMWENI
280
ENEZA PETER MKIRAMWENI  
Keith Watford:

Please do not post in capital letters. It is very impolite.

People are unlikely to help you if you shout at them.

sory my friend is not my intention

ENEZA PETER MKIRAMWENI
280
ENEZA PETER MKIRAMWENI  
Keith Watford:

Please do not post in capital letters. It is very impolite.

People are unlikely to help you if you shout at them.

sory my friend is not my intention

can you help me

Ernst Van Der Merwe
7650
Ernst Van Der Merwe  
#resource "\\Indicators\\MA Colored.ex5"
//--- input parameters
#include<Trade\Trade.mqh>

CTrade trade;
MqlTick Tick;


int ma_colored;
int handleIndicador=INVALID_HANDLE;

datetime MAXIMO=D'2021.10.16 00:00';

double MaBuffer[];

input double VOLUME=0.01;//Lot
input double TP=30; //Take Profit(PIPS)
input double SL=30;//StopLoss(PIPS)

enum ENUM_TYPE_ORDER
{
    ORDER_BUY=0,
    ORDER_SELL=1,
    BUY_AND_SELL=2,
};

input  ENUM_TYPE_ORDER   TYPE_ORDERS=2; 
input string Separate="--------------------------------------";
input string Separate2="----INDICATOR PARAMETERS----";

input int                  MaPeriod    = 9;             // Period    
input ENUM_MA_METHOD       MaMethod    = MODE_SMA;      // Method   
input ENUM_APPLIED_PRICE   Price       = PRICE_CLOSE;   // Price
double StopLoss;
double TakeProfit;


int OnInit()
  {
   if(MAXIMO<TimeCurrent()){
   return INIT_FAILED;
   }
  
   double points=SymbolInfoDouble(Symbol(),SYMBOL_POINT);
   StopLoss=SL*points*10;
   TakeProfit=TP*points*10;
   //KALMAN_FILTER=iCustom(Symbol(),PERIOD_CURRENT,"Kalman_filter_2",inpTimeFrame,inpPeriod,inpPrice,inpInterpolate);
   if((handleIndicador=iCustom(Symbol(),PERIOD_CURRENT,"::Indicators\\MA Colored.ex5",MaPeriod,MaMethod,Price))==INVALID_HANDLE)
      return(INIT_PARAMETERS_INCORRECT);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   IndicatorRelease(handleIndicador);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(!MAColored(MaBuffer))
      return;
      
   double bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
   double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); 
   
   int total=PositionsTotal();
   int OrdersBuy=0, OrdersSell=0;
   for(int i=0; i<total; i++)
     {
      //--- parámetros de la orden
      ulong  position_ticket=PositionGetTicket(i);// ticket de la posición
      string position_symbol=PositionGetString(POSITION_SYMBOL); // símbolo
      ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);  // tipo de posición
       if(type==POSITION_TYPE_BUY)
        {
         OrdersBuy++;
        }
       if(type==POSITION_TYPE_SELL)
        {
         OrdersSell++;
        }
     }
   
   
   if(TYPE_ORDERS==2 || TYPE_ORDERS==1){
   if(MaBuffer[1]==1 && MaBuffer[2]==0  && OrdersSell==0 ){
   Comment("Entro sell",MaBuffer[0]," ",MaBuffer[1]," ",MaBuffer[2]);
   trade.Sell(VOLUME,Symbol(),ask,bid+StopLoss,ask-TakeProfit,"");
   }}
   
   if(TYPE_ORDERS==2 || TYPE_ORDERS==0){
   if(MaBuffer[1]==0 && MaBuffer[2]==1  && OrdersBuy==0){
   Comment("Entro buy",MaBuffer[0]," ",MaBuffer[1]," ",MaBuffer[2]);
   trade.Buy(VOLUME,Symbol(),bid,ask-StopLoss,bid+TakeProfit,"");
   }}
//---
   //Comment(BufferKalman[1]);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+

bool MAColored(double &BufferIndicador[])
  {
   ArraySetAsSeries(BufferIndicador,true);
//---
   return(CopyBuffer(handleIndicador,1,0,3,BufferIndicador)>-1);
  }
//+------------------------------------------------------------------+
Files:
ENEZA PETER MKIRAMWENI
280
ENEZA PETER MKIRAMWENI  
Ernst Van Der Merwe:

thank you very much

ENEZA PETER MKIRAMWENI
280
ENEZA PETER MKIRAMWENI  
Ernst Van Der Merwe:

is possible to make it to take single trade per condition