Problem of moving average

MQL4 Experts C++

Trabalho concluído

Tempo de execução 1 hora
Comentário do desenvolvedor
Perfect.
Comentário do cliente
super boulot / great job :)

Termos de Referência

Hello,
My problem is that my order opens with how, whereas I would like my order to open
only when my moving average crosses.

Exemple:

when my moving average of 5 and 25 it crosses then my order opens, and if my first
order touches the stop loss then the next function
if (Counts () == 1) opens, and if my stop loss is still affected then the function
if (Counts () == 2) ect
and if my take profit is affected then everything starts again from the beginning

CODE
//+------------------------------------------------------------------+
//|                                                       test35.mq4 |
//|                                                              xxx |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "xxx"
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
extern double  lots1          = 0.01;
extern double  lots2          = 0.02;
extern double  lots3          = 0.03;
extern double  lots4          = 0.04;
extern double  lots5          = 0.05;
extern double  lots6          = 0.06;
extern double  lots7          = 0.07;
extern double  lots8          = 0.08;
extern double  lots9          = 0.09;
extern double  lots10         = 0.10;
extern double  lots11          = 0.11;
extern double  lots12          = 0.12;
extern double  lots13          = 0.13;
extern double  lots14          = 0.14;
extern double  lots15          = 0.15;
extern double  lots16          = 0.16;
extern double  lots17          = 0.17;
extern double  lots18          = 0.18;
extern double  lots19          = 0.19;
extern double  lots20         = 0.20;
extern double  lots21          = 0.21;
extern double  lots22          = 0.22;
extern double  lots23          = 0.23;
extern double  lots24          = 0.24;
extern double  lots25          = 0.25;
extern double  lots26          = 0.26;
extern double  lots27          = 0.27;
extern double  lots28          = 0.28;
extern double  lots29          = 0.29;
extern double  lots30         = 0.30;
extern double  lots31          = 0.31;
extern double  lots32          = 0.32;
extern double  lots33          = 0.33;
extern double  lots34          = 0.34;
extern double  lots35          = 0.35;
extern double  lots36          = 0.36;
extern double  lots37          = 0.37;
extern double  lots38          = 0.38;
extern double  lots39          = 0.39;
extern double  lots40         = 0.40;
input int      TakeProfit1     =   12;
input int      StopLoss1       =   10;
input int      TakeProfit2     =   14;
input int      StopLoss2       =   10;
input int      TakeProfit3     =   16;
input int      StopLoss3       =   10;
input int      TakeProfit4     =   21;
input int      StopLoss4       =   10;
input int      TakeProfit5     =   26;
input int      StopLoss5       =   10;
input int      TakeProfit6     =   32;
input int      StopLoss6       =   10;
input int      TakeProfit7     =   38;
input int      StopLoss7       =   10;
input int      TakeProfit8     =   44;
input int      StopLoss8       =   10;
input int      TakeProfit9     =   50;
input int      StopLoss9       =   10;
input int      TakeProfit10    =   55;
input int      StopLoss10      =   10;






//extern int     MovingPeriod         = 2;
//extern int     MovingShift          = 1;
//extern int Period_PCh = 20;
extern int     magic=232654;
//extern double  Level          = 1.4220;
//extern double  MaxDeviation   = 9;         // Max Deviation, points

bool RunOnce=false;
int last_order_check=false;
datetime EaStartTime=TimeCurrent();
double takeprofit1=TakeProfit1;
double stoploss1=StopLoss1;
double takeprofit2=TakeProfit2;
double stoploss2=StopLoss2;
double takeprofit3=TakeProfit3;
double stoploss3=StopLoss3;
double takeprofit4=TakeProfit4;
double stoploss4=StopLoss4;
double takeprofit5=TakeProfit5;
double stoploss5=StopLoss5;
double takeprofit6=TakeProfit6;
double stoploss6=StopLoss6;
double takeprofit7=TakeProfit7;
double stoploss7=StopLoss7;
double takeprofit8=TakeProfit8;
double stoploss8=StopLoss8;
double takeprofit9=TakeProfit9;
double stoploss9=StopLoss9;
double takeprofit10=TakeProfit10;
double stoploss10=StopLoss10;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()

  {
   MathSrand(GetTickCount());
   if(Digits==5 || Digits==3)
     {
      takeprofit1  =TakeProfit1*10;
      stoploss1    =StopLoss1*10;
      takeprofit2  =TakeProfit2*10;
      stoploss2    =StopLoss2*10;
      takeprofit3  =TakeProfit3*10;
      stoploss3    =StopLoss3*10;
      takeprofit4  =TakeProfit4*10;
      stoploss4    =StopLoss4*10;
      takeprofit5  =TakeProfit5*10;
      stoploss5    =StopLoss5*10;
      takeprofit6  =TakeProfit6*10;
      stoploss6    =StopLoss6*10;
      takeprofit7  =TakeProfit7*10;
      stoploss7    =StopLoss7*10;
      takeprofit8  =TakeProfit8*10;
      stoploss8    =StopLoss8*10;
      takeprofit9  =TakeProfit9*10;
      stoploss9    =StopLoss9*10;
      takeprofit10  =TakeProfit10*10;
      stoploss10    =StopLoss10*10;
     
     }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnTimer()
  {
   OnTick();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  
  {
   if (RunOnce)// ExpertRemove();
   if(IsLastOrderClose())
     {
      OnInit();
      Print("Ea Closed Manually ");
      EaStartTime=TimeCurrent();
     }

   int ticet;
   int t=MathRand();
     double MA_Fast,MA_Low;


   if(CountVsego()==0)
     {
      //if(t>16383)
      //  {
        // if(Counts()==0) //  && (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0))
          //if(Volume[0]>1) return;
          MA_Fast=iMA( NULL, 0, 5, 0, MODE_SMA, PRICE_TYPICAL, 1); // áûñòðàÿ ÌÀ
          MA_Low=iMA( NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, 1); // ìåäëåííàÿ ÌÀ 
          
          
         
           
           if(Counts()==0  &&  (MA_Fast>MA_Low && Open[0]<Open[1] ))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots1,Ask,3,Bid-stoploss1*Point,Ask+takeprofit1*Point,"1",magic,0,clrGreen);
           }
        
      // Partie 1 
      // else if(t<16383)
       //  {
         if(Counts()==0  && (MA_Fast<MA_Low && Open[0]>Open[1]))
           {
            ticet=OrderSend(Symbol(),OP_SELL,lots1,Bid,3,Ask+stoploss1*Point,Bid-takeprofit1*Point,"1",magic,0,clrRed);
           }
          
        
      // Partie 1 
      // else if(t<16383)
         
         //if(Counts()==0//  && (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0))
   
        
        
        
      if(t>0)
        {
         if(Counts()==1)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
          {
            ticet=OrderSend(Symbol(),OP_BUY,lots2,Ask,3,Bid-stoploss2*Point,Ask+takeprofit2*Point,"2",magic,0,clrGreen);
           }
        }
      // Partie 2 
     // else if(t<16383)
      //  {
       //  if(Counts()==1)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
       //    {
        //    ticet=OrderSend(Symbol(),OP_SELL,lots2,Bid,3,Ask+stoploss2*Point,Bid-takeprofit2*Point,"2",magic,0,clrRed);
        //   }
           
           
           
      //  }
     // if(t>16383)
     //   {
      //   if(Counts()==2)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
       //    {
       //     ticet=OrderSend(Symbol(),OP_BUY,lots3,Ask,3,Bid-stoploss3*Point,Ask+takeprofit3*Point,"3",magic,0,clrGreen);
        //   }
      // }
      //Partie 3 
     // else if(t<16383)
     //   {
        if(Counts()==2)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_SELL,lots3,Bid,3,Ask+stoploss3*Point,Bid-takeprofit3*Point,"3",magic,0,clrRed);
           }
           
           
           
     //   }
      if(t>0)
        {
         if(Counts()==3)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots4,Ask,3,Bid-stoploss4*Point,Ask+takeprofit4*Point,"4",magic,0,clrGreen);
           }
        }
      //Partie 4 
    // else if(t<16383)
     //   {
      //   if(Counts()==3)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
       //    {
        //    ticet=OrderSend(Symbol(),OP_SELL,lots4,Bid,3,Ask+stoploss4*Point,Bid-takeprofit4*Point,"4",magic,0,clrRed);
        //   }
           
           
           
     //   }
    // if(t>0)
     //   {
      //   if(Counts()==4)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
       //   {
       //     ticet=OrderSend(Symbol(),OP_BUY,lots5,Ask,3,Bid-stoploss5*Point,Ask+takeprofit5*Point,"5",magic,0,clrGreen);
       //    }
      //  }
      // Partie 5 
     // else if(t<16383)
      //  {
         if(Counts()==4)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_SELL,lots5,Bid,3,Ask+stoploss5*Point,Bid-takeprofit5*Point,"5",magic,0,clrRed);
           }
           
           
           
      //  }
      if(t>0)
        {
         if(Counts()==5)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots6,Ask,3,Bid-stoploss6*Point,Ask+takeprofit6*Point,"8",magic,0,clrGreen);
           }
        }
      //Partie 8 
    //  else if(t<16383)
      //  {
      //  if(Counts()==5)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
       //    {
       //    ticet=OrderSend(Symbol(),OP_SELL,lots6,Bid,3,Ask+stoploss6*Point,Bid-takeprofit6*Point,"8",magic,0,clrRed);
        //   }
           
           
           
           
    //   }
     // if(t>0)
      //  {
       //  if(Counts()==6)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
        //   {
        //    ticet=OrderSend(Symbol(),OP_BUY,lots7,Ask,3,Bid-stoploss7*Point,Ask+takeprofit7*Point,"7",magic,0,clrGreen);
         //  }
       // }
      //Partie 7 
     // else if(t<16383)
      //  {
         if(Counts()==6)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
          {
            ticet=OrderSend(Symbol(),OP_SELL,lots7,Bid,3,Ask+stoploss7*Point,Bid-takeprofit7*Point,"7",magic,0,clrRed);
           }
           
           
           
//}
      if(t>0)
        {
         if(Counts()==7)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots8,Ask,3,Bid-stoploss8*Point,Ask+takeprofit8*Point,"8",magic,0,clrGreen);
           }
       }
      //Partie 8 
    //  else if(t<16383)
      //  {
       // if(Counts()==7)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
        //   {
         //  ticet=OrderSend(Symbol(),OP_SELL,lots8,Bid,3,Ask+stoploss8*Point,Bid-takeprofit8*Point,"8",magic,0,clrRed);
         //  }
           
           
           
           
     //  }
     // if(t>0)
       // {
       //  if(Counts()==8)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
        //   {
        //    ticet=OrderSend(Symbol(),OP_BUY,lots9,Ask,3,Bid-stoploss9*Point,Ask+takeprofit9*Point,"9",magic,0,clrGreen);
        //   }
       // }
      //Partie 9 
    // else if(t<16383)
    //    {
         if(Counts()==8)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
          {
            ticet=OrderSend(Symbol(),OP_SELL,lots9,Bid,3,Ask+stoploss9*Point,Bid-takeprofit9*Point,"8",magic,0,clrRed);
           
           }
           
//}
      if(t>0)
        {
         if(Counts()==9)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots10,Ask,3,Bid-stoploss10*Point,Ask+takeprofit10*Point,"9",magic,0,clrGreen);
           }
        }
      //Partie 9 
    //  else if(t<16383)
      //  {
       //  if(Counts()==9)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
        //   {
        //    ticet=OrderSend(Symbol(),OP_SELL,lots10,Bid,3,Ask+stoploss10*Point,Bid-takeprofit10*Point,"9",magic,0,clrRed);
         //  }
      //  }
      
      
      
      
      
     
           
           
       // }
     // if(t>0)
      //  {
       //  if(Counts()==10)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
       //   {
        //    ticet=OrderSend(Symbol(),OP_BUY,lots11,Ask,3,Bid-stoploss11*Point,Ask+takeprofit11*Point,"2",magic,0,clrGreen);
        //   }
      //  }
      // Partie 2 
    //  else if(t<16383)
    //    {
      
        
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountSELL()
  {
   int count=0;
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountBUY()
  {
   int count=0;
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
int Counts()
  {
   int count=0,i;

   for(i=OrdersHistoryTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderOpenTime()>=EaStartTime)
           {
            if(OrderProfit()>0)
              {
               if(count==0)
                 {
                  OnInit();
                  EaStartTime=TimeCurrent();
                  RunOnce = true;
                  return(count);
                                              
                }
              }
            else
              {
               count++;
              }
           }
         if(count>39 )
            {
               OnInit();
               EaStartTime=TimeCurrent();
               RunOnce = true;
              return(count);
            }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountVsego()
  {
   int Vsego;
   Vsego=CountBUY()+CountSELL();

   return(Vsego);
  }
//+------------------------------------------------------------------+
bool IsLastOrderClose()
  {
   bool signal=false;
   for(int i=OrdersHistoryTotal()-1;i>=0;i--)
     {
      bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
      if(select && OrderSymbol()==_Symbol && OrderMagicNumber()==magic)
        {
         if(OrderType()==OP_BUY && OrderOpenTime()>=EaStartTime)
           {
            if(OrderClosePrice()>OrderStopLoss() && OrderClosePrice()<OrderTakeProfit())
              {
               signal=true;
              }
            break;
           }
         else if(OrderType()==OP_SELL && OrderOpenTime()>=EaStartTime)
           {
            if(OrderClosePrice()<OrderStopLoss() && OrderClosePrice()>OrderTakeProfit())
              {
               signal=true;
              }
            break;
           }
        }
     }
   return(signal);
  }
//+------------------------------------------------------------------+


Respondido

1
Desenvolvedor 1
Classificação
(620)
Projetos
680
57%
Arbitragem
25
16% / 60%
Expirado
228
34%
Livre
2
Desenvolvedor 2
Classificação
(117)
Projetos
138
41%
Arbitragem
30
7% / 77%
Expirado
17
12%
Livre
3
Desenvolvedor 3
Classificação
(365)
Projetos
412
36%
Arbitragem
35
26% / 57%
Expirado
63
15%
Livre
Pedidos semelhantes
I have an EA and want to add few new logic to fetch profit taking factors and other values from an external master data and use it in existing EA
My trust wallet was hacked and I have tokens to claim which unlock almost daily but the person who hacked the wallet drains the tokens as soon as I claim them in the hacked wallet. I have contacted the support for that crypto but they were not helpful. There is no way to claim this crypto to another wallet. I need a bot or another solution that can transfer the crypto out of the hacked wallet into my other wallet as
I want a program that will help calculate and enter the market on full margin for me. I just need to put in the price for entry, Stop loss and TP then it will calculate the lot sizes for entering the trade on full margin on Mt5
I want to design a website like https://www.ngnrates.com/ we will change some stuff but not much, if you can deliver a website like this let me know your budget and readiness to implement
Hi, I need a robot, which wil get instructions to trade in 3 symbols at the same time based on few parameters and calculations. Example: There is 1 symbol called Gold-Near and the rate for it is 1000-1002 If i specify that when the rate reaches 1050, it should sell 1 lot Upon execution it will have to sell 1 lot of cme gold, buy 3 lots of mcx gold and buy currently (lots will be based on calculation). All the
I have a full code ,, There are some errors in this.It does not add to the chart, does not show arrow marks, does not alert ,, fix this problem and work properly,, Contact on telegram @Gw_rakib1
Hey, great developer I have a thinkorswim script I want to convert it into TradingView. Can you please let me know if you can i will be looking for great developer that will bid for it best regards
Hey, great developer I have a thinkorswim script I want to convert it into TradingView. Can you please let me know if you can i will be looking for great developer that will bid for it best regards
Tradingview developer 30 - 35 USD
Hey greetings. I am in need of tradingview developer that can modify an open source PineScript indicator code to add additional features. Kindly bid for this project if it is what you handle and let proceed with the project
hi. I hv a strategy on tradingview need to convert to MT4/MT5 expert advisor for algo trading. would like to add some tradingview strategy setting to the EA(not included in my tradingview code): recalculate after order is filled, order size: xx% of equity

Informações sobre o projeto

Orçamento
30+ USD
IVA (20%): 6 USD
Total: 36 USD
Desenvolvedor
27 USD
Prazo
para 1 dias