MA Cross Over + MACD (NEED HELP).

 

Hi 

I need your help with this code i need when my ( fastmaArray[0] < slowmaArray[0]) fastmaArray this is my 5 simple MA and slowmaArray this is my 10 MA .

and they cross i need it to wait for the value of my MACD to reach below zero to sell.

I manged to make it sell when they cross and at the same time my MACD reach below zero I did not wanted like this i need it when cross it has to wait for my MACD to enter sell.

Please Help.

      if(fastmaArray[0] < slowmaArray[0] && fastmaArray[1] > slowmaArray[1]&& MacdValue<0){
     
      printf("sell");
      //sell order
      double bid = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
      double sl = bid -50 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);
      double tp = bid +200 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);

      trade.Sell(1,_Symbol,bid,sl,tp,"sell trade");
      }
 
Take your time :)
 
themasterx7:

Hi 

I need your help with this code i need when my ( fastmaArray[0] < slowmaArray[0]) fastmaArray this is my 5 simple MA and slowmaArray this is my 10 MA .

and they cross i need it to wait for the value of my MACD to reach below zero to sell.

I manged to make it sell when they cross and at the same time my MACD reach below zero I did not wanted like this i need it when cross it has to wait for my MACD to enter sell.

Please Help.


you are trying to bid with ask price

double bid = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
 
Ahmet Metin Yilmaz:

you are trying to bid with ask price

Oh i forgot to change it thank you :)))) ...

back to my main issue see this screenshot the two  ma crossed over and the macd <0 but no sell order was taken whats wrong with my code

 

 
themasterx7:

Hi 

 if(fastmaArray[0] < slowmaArray[0] && fastmaArray[1] > slowmaArray[1]&& MacdValue<0){
     
      printf("sell");
      //sell order
      double bid = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
      double sl = bid -50 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);
      double tp = bid +200 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);

      trade.Sell(1,_Symbol,bid,sl,tp,"sell trade");
      }

Please Help.

is that all your code?

 
Ahmet Metin Yilmaz:

is that all your code?

#include <Trade/Trade.mqh>

CTrade trade;

int OnInit(){

  
   return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
   
}
void OnTick(){

static datetime timestamp;
datetime time = iTime(_Symbol,PERIOD_CURRENT,0);
if(timestamp != time){
   timestamp = time;

      // fast moving average
      static int handlefastma = iMA(_Symbol,PERIOD_CURRENT,14,0,MODE_SMA,PRICE_CLOSE);
      double fastmaArray[];
      CopyBuffer(handlefastma,0,1,4,fastmaArray);
      ArraySetAsSeries(fastmaArray,true);
      
      //slow moving average
      static int handleslowma = iMA(_Symbol,PERIOD_CURRENT,28,0,MODE_SMA,PRICE_CLOSE);
      double slowmaArray[];
      CopyBuffer(handleslowma,0,1,4,slowmaArray);
      ArraySetAsSeries(slowmaArray,true);
      
      //macd
      static int handleMacd = iMACD(_Symbol,PERIOD_CURRENT,12,26,9,PRICE_CLOSE);
      double macdArray [];
      CopyBuffer(handleMacd,0,0,3,macdArray);
      ArraySetAsSeries(macdArray,true);
      double MacdValue=(macdArray[1]);
      //buy
      if(fastmaArray[0] > slowmaArray[0] && fastmaArray[1] < slowmaArray[1]&& fastmaArray[2] < slowmaArray[2]){ 
      if(MacdValue>0.0)   
      printf("buy");
      // buy order
      double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
      double sl = ask -300 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);
      double tp = ask +500 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);

      trade.Buy(1,_Symbol,ask,sl,tp,"buy trade");
      }
      
      
      //sell
      if(fastmaArray[0] < slowmaArray[0] && fastmaArray[1] > slowmaArray[1]&& fastmaArray[2] > slowmaArray[2]){
      if(MacdValue<0.0)
      printf("sell");
      //sell order
      double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
      double sl = bid -300 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);
      double tp = bid +500 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);

      trade.Sell(1,_Symbol,bid,sl,tp,"sell trade");
      }
  

}

   
}
 
themasterx7:

Oh i forgot to change it thank you :)))) ...

back to my main issue see this screenshot the two  ma crossed over and the macd <0 but no sell order was taken whats wrong with my code

 

1. there is no expert working on your chart :)

2. if actually was worked, 

 if(fastmaArray[0] < slowmaArray[0] && fastmaArray[1] > slowmaArray[1]&& fastmaArray[2] > slowmaArray[2]){
      if(MacdValue<0.0)

crossing ma s in [0] bar macdvalue was not <0.0 ( it seems so on the graph ) 

all crossing condition and macd position might be at the same time ( bar )

 
Ahmet Metin Yilmaz:

1. there is no expert working on your chart :)

2. if actually was worked, 

crossing ma s in [0] bar macdvalue was not <0.0 ( it seems so on the graph ) 

all crossing condition and macd position might be at the same time ( bar )

Of course the conditions are not met on the screenshot.


 
I know thats why i need help :) how can i fix it?  i want it to cross(I mean the moving averages) then wait for macd to go under zero to take the sell.
 

its working but not as wanted

it took a buy order

but this is not what i want
 

I think you need to learn more from 

https://www.mql5.com/en/docs

MQL5 Reference - How to use algorithmic/automated trading language for MetaTrader 5
MQL5 Reference - How to use algorithmic/automated trading language for MetaTrader 5
  • www.mql5.com
MetaQuotes Language 5 (MQL5) is a high-level language designed for developing technical indicators, trading robots and utility applications, which automate financial trading. MQL5 has been developed by MetaQuotes Software Corp. for their trading platform. The language syntax is very close to C++ enabling programmers to develop applications in...
Reason: