this EA doesnt work

 

#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Trade/Trade.mqh>

CTrade trade;


int handlefastma, handlemiddlema, handleslowma;


double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);




int OnInit()
  {
  
  handlefastma = iMA(NULL,PERIOD_CURRENT,10,0,MODE_SMA,PRICE_CLOSE);
  handlemiddlema = iMA(NULL,PERIOD_CURRENT,50,0,MODE_SMA,PRICE_CLOSE);
  handleslowma = iMA(NULL,PERIOD_CURRENT,100,0,MODE_SMA,PRICE_CLOSE);

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

   
  }
  
  
  
  

void OnTick()
  {
  
  int bars = iBars(_Symbol,PERIOD_CURRENT);
  if(barstotal < bars){
  
  barstotal = bars;
  
  }
  
  double fastma[], middlema[], slowma[];
  
  CopyBuffer(handlefastma,MAIN_LINE,1,2,fastma);
  CopyBuffer(handlemiddlema,MAIN_LINE,1,2,middlema);
  CopyBuffer(handleslowma,MAIN_LINE,1,2,slowma);

   
   double close1 = iClose(_Symbol,PERIOD_CURRENT,1);
   double close2 = iClose(_Symbol,PERIOD_CURRENT,2);
 
   
          if(fastma[1] > middlema[1] && middlema[1] > slowma[1])
               {
   
                     if (close1 > fastma[1] && close2 < fastma[0])
  
  
                               {
                               
                               
                               
                                  trade.Buy(1,NULL,Ask,20*Point(),40*Point());
                               
                               }
     
               }
   
     }


can anyone help me to know why this code doesnt open any trade?


Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • 2023.10.08
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
mat-ebr: can anyone help me to know why this code doesnt open any trade?

Don't just state that "it does not work"! That is useless and meaningless. Explain in detail and describe what you are having difficult with.

  • Usually people who can't code don't receive free help on this forum.
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
  • To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Documentation.
  • If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
  • Finally, you also have the option to hire a programmer in the Freelance section.