My MQL5 EA is not giving any trades.

 

Hi Guys,

I have been learning MQL5 for about 30 days. I have been trying to write an EA as a learning process. I have been facing this problem , My trade always sends a requote. I dont really know how to solve this problem. Please help me.

Screenshot and codes Sell codes are shown below :


double TakeProfit = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits) - reward * MathAbs(NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits) - StopLossValue);
                        if(NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits) > (EntryValue))
                              {
                                    if(Trade.Sell(0.01,_Symbol,NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits),SlowEmaValue,TakeProfit))
                                    {
                                       reset = "fasle";
                                    }
                                    else
                                    {
                                        reset = "fasle";
                                    }
                              }
                  }  
Files:
error.jpg  700 kb
 

Allow a slippage in your code. 

Normally people use 10 as default value of slippage.

 

After reading from the contents , I even tried adding deviations like this. Still not working. Please help.

 Trade.SetDeviationInPoints(Deviation);
 Trade.SetExpertMagicNumber(MAGICNUMBER);
 if(Trade.Sell(0.01,_Symbol,NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits),StopLossValue,TakeProfit))
 
Satyam Shivam #:

Allow a slippage in your code. 

Normally people use 10 as default value of slippage.

Thanks for the Reply Bro. I added Deviations like I comment . But its still not working. Can you help me out please. 
 
Kindly send your full code and I will run it at my end and try to provide you proper feedback.
 
Satyam Shivam #:
Kindly send your full code and I will run it at my end and try to provide you proper feedback.

here is my full code :

//+------------------------------------------------------------------+

//|                                                       EMA 1R.mq5 |

//|                                                       RRLaishram |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "RRLaishram"

#property link      "https://www.mql5.com"

#property version   "1.00"

#include  <Trade\Trade.mqh>



//Global Initializations



double FastEmaArray[], SlowEmaArray[], MidEmaArray[];

double EntryEma[], StopLossEma[];



int FastEmaHandle,SlowEmaHandle,MidEmaHandle;

int EntryHandle, StopLossHandle;



double FastEmaValue, MidEmaValue, SlowEmaValue;

double EntryValue, StopLossValue;



int MAGICNUMBER = 9991;

string ConditionRest = "true";



double high, low;



string reset = "true";

int reward = 2;



ulong Deviation = 10;



CTrade Trade;



void OnTick()

  {

      FastEmaHandle = iMA(_Symbol,PERIOD_CURRENT,10,0,MODE_EMA,PRICE_CLOSE);

      MidEmaHandle = iMA(_Symbol,PERIOD_CURRENT,20,0,MODE_EMA,PRICE_CLOSE);

      SlowEmaHandle = iMA(_Symbol,PERIOD_CURRENT,40,0,MODE_EMA,PRICE_CLOSE);

      EntryHandle = iMA(_Symbol,PERIOD_CURRENT,7,0,MODE_EMA,PRICE_CLOSE);

      StopLossHandle = iMA(_Symbol,PERIOD_CURRENT,45,0,MODE_EMA,PRICE_CLOSE);

      

      ArraySetAsSeries(FastEmaArray,true);

      ArraySetAsSeries(MidEmaArray,true);

      ArraySetAsSeries(SlowEmaArray,true);

      ArraySetAsSeries(EntryEma,true);

      ArraySetAsSeries(StopLossEma,true);

      

      CopyBuffer(FastEmaHandle,0,0,3,FastEmaArray);

      CopyBuffer(MidEmaHandle,0,0,3,MidEmaArray);

      CopyBuffer(SlowEmaHandle,0,0,3,SlowEmaArray);

      CopyBuffer(EntryHandle,0,0,3,EntryEma);

      CopyBuffer(StopLossHandle,0,0,3,StopLossEma);

      

      FastEmaValue = NormalizeDouble(FastEmaArray[0],_Digits);

      MidEmaValue = NormalizeDouble(MidEmaArray[0],_Digits);

      SlowEmaValue = NormalizeDouble(SlowEmaArray[0],_Digits);

      EntryValue = NormalizeDouble(EntryEma[0],_Digits);

      StopLossValue = NormalizeDouble(StopLossEma[0],_Digits);

      

      //Comment("Fast : ",FastEmaValue, " Mid  :  ", MidEmaValue, " Slow  :  ", SlowEmaValue);

      

      high = NormalizeDouble(iHigh(_Symbol,PERIOD_CURRENT,1),_Digits);

      low = NormalizeDouble(iLow(_Symbol,PERIOD_CURRENT,1),_Digits);

      //Alert ("Reset Condition  : ", reset);

      if (reset == "true")

      {

         EmaCondition();

        // Alert ("Reset Condition  : ", reset);

      }

       // reset market

      if (FastEmaValue < MidEmaValue && MidEmaValue > SlowEmaValue)

      {

         reset = "true";

      }

      if (FastEmaValue > MidEmaValue && MidEmaValue < SlowEmaValue)

      {

         reset = "true";

      }

   

  }



void EmaCondition()

{

      Comment("Fast : ",FastEmaValue, " Mid  :  ", MidEmaValue, " Slow  :  ", SlowEmaValue);

      if (FastEmaValue > MidEmaValue && MidEmaValue > SlowEmaValue)

      {

         //Alert("Ema Value Satisfied");

            if (high > FastEmaValue && low > FastEmaValue)

            {

               // if (MathAbs(FastEmaValue - SlowEmaValue) >=(10 * _Point) && MathAbs(FastEmaValue - SlowEmaValue) <= (40 * _Point))

                 // Buy COndition

                 Comment("Buy Condition Satisfied");

                 //Alert (5 * _Point);

                 {

                        double TakeProfit = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits) + reward * (MathAbs(NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits) - StopLossValue));

                        if(NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits)< (EntryValue))

                              {

                                 

                                 Trade.SetDeviationInPoints(Deviation);

                                 Trade.SetExpertMagicNumber(MAGICNUMBER);

                                    if(Trade.Buy(0.01,_Symbol,NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits),StopLossValue,TakeProfit))

                                    {

                                       reset = "fasle";

                                    }

                                    else

                                    {

                                        reset = "fasle";

                                    }

                              }

                 }    

            }

      }

      

      if (FastEmaValue < MidEmaValue && MidEmaValue < SlowEmaValue)

      {

            if (high < FastEmaValue && low < FastEmaValue)

            {

                  // Sell Condition

                  Comment("Sell Condition Satisfied");

                 // if (MathAbs(FastEmaValue - SlowEmaValue) >=(30 * _Point) && MathAbs(FastEmaValue - SlowEmaValue) <= (100 * _Point))

                 

                  {

                        double TakeProfit = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits) - reward * MathAbs(NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits) - StopLossValue);

                        if(NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits) > (EntryValue))

                              {

                                 Trade.SetDeviationInPoints(Deviation);

                                 Trade.SetExpertMagicNumber(MAGICNUMBER);

                                 Alert (StopLossValue,"   "  ,TakeProfit);

                                    if(Trade.Sell(0.01,_Symbol,NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits),StopLossValue,TakeProfit))

                                    {

                                       reset = "fasle";

                                    }

                                    else

                                    {

                                        reset = "fasle";

                                    }

                              }

                  }  

             }

      }  

   

   

     

}
 
  1. Please edit your post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  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/OnCalculate (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 (2010)

 
William Roeder #:
  1. Please edit your post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  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/OnCalculate (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 (2010)

William Roeder,

           Thank you very much for the advices. I have read all. And I will follow the instructions next time. And about the third part of your comment, You were giving a hint on using handle, shift and count. Were you referencing those to my problem ? 

 
The code seems to work in the tester with the visual mode set to off. I dont know how to rectify it yet. Unlike other codes that I have tested, This code seems to show two lines :- one red line above the candle and a grey line below each candle. I dont know how to remove it . Please help.
Files:
error.jpg  700 kb
 
please check the file attached. I have made some change in the code . It is working fine at my end. I tried several time and there is no such issue. 
 
ChiefDark Rakesh #:
The code seems to work in the tester with the visual mode set to off. I dont know how to rectify it yet. Unlike other codes that I have tested, This code seems to show two lines :- one red line above the candle and a grey line below each candle. I dont know how to remove it . Please help.


red line is the ASK  price

grey line is BID PRICE


If you right click on chart, and go to properties, you will see a checkbox to  hide/show the ASK line.. Using that check box you can hide the ASK line.