Problem of moving average

MQL4 Uzman Danışmanlar C++

İş tamamlandı

Tamamlanma süresi: 1 saat
Geliştirici tarafından geri bildirim
Perfect.
Müşteri tarafından geri bildirim
super boulot / great job :)

İş Gereklilikleri

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);
  }
//+------------------------------------------------------------------+


Yanıtlandı

1
Geliştirici 1
Derecelendirme
(620)
Projeler
680
57%
Arabuluculuk
25
16% / 60%
Süresi dolmuş
228
34%
Serbest
2
Geliştirici 2
Derecelendirme
(117)
Projeler
138
41%
Arabuluculuk
30
7% / 77%
Süresi dolmuş
17
12%
Serbest
3
Geliştirici 3
Derecelendirme
(365)
Projeler
412
36%
Arabuluculuk
35
26% / 57%
Süresi dolmuş
63
15%
Serbest
Benzer siparişler
Hello The EA will work on particular zone choose by the user and can mark it on any TF and with some rules can open trades and mange the trade by some unique rules. the EA need to check the difference by RSI as well and with some extra rules . developer should have good attitude and good communication (englsih) with high performence and knowledge with coding EA
Create mt4 ea 50+ USD
To convert the provided MT4 indicator script into an Expert Advisor (EA) and implement prompt functionality for user input, we need to modify the code to handle external parameters and provide a user-friendly interface. Below is the EA code that incorporates prompts for user inputs
I WRITE a code i want to conect this for automatic trading through vps .and als advanced features for this code .i attached afile please watch .and give me perfect ea
Hello The EA will work on particular zone choose by the user and can mark it on any TF and with some rules can open trades and mange the trade by some unique rules. the EA need to check the difference by RSI as well and with some extra rules . developer should have good attitude and good communication (englsih) with high performence and knowledge with coding EA. THREE TYPES OF ENTRIES 1: AGGRESSIVE 2: DIVERGENCE 3
I need a simple panel to execute both buy and sell operations with very basic things like stopp loss take profit that functions for both market orders such as buy stop sell stop buy limit sell limit I don't care about colors or design I just want how you can do it what interests me most are the functions
I want to create an EA that can take bids according to information of a logic I have developed to give indication of a BUY or SELL opportunity. The EA will then be able to activate the BUY at the lowest possible position once the indicator clears it for a BUY and take bid upwards or identify the highest point and clears it for a SELL and take bids downwards. As you can see from example of JULY 2024 data to see how
Hello, I‘m interested in an indicator to predict the next candles probability (bullish or bearish). But honestly I have no idea how to do this. Would be interested in your opinion how we can create such an indicator. Please let me know if you‘ve done similar work
Hey greetings. Am in need of a developer that has already made profitable MT4 or MT5 EA that I can buy with the backtesting and proven result. How is the draw down ? What is the winning rate ? Kindly reply and let proceed
I need a TradingView script (not mine) converted to an Mt5 EA. There is some specifications for the robots on when to be able to take a trade. Attached bellow is the file of the script I want translated and converted to MT5 then EA
GOODAY TO YOU I AM NEED OF A FAST, TALENTED AND HIGH QUALITY CODER TO THIS JOB FOR ME. THE EA TRADE MANAGER WILL HAVE THE FOLLOWING: STOPLOSS & TAKEPROFIT IN PIPS LOT SIZE IN PIPS NUMBER OF TRADES (1-30 TRADES MAXIMUM) PLEASE LOOK AT THE PICTURE ABOVE FOR A GUIDE

Proje bilgisi

Bütçe
30+ USD
KDV (20%): 6 USD
Toplam: 36 USD
Geliştirici için
27 USD
Son teslim tarihi
to 1 gün