Problem of moving average

MQL4 Experts C++

Tâche terminée

Temps d'exécution 1 heure
Commentaires de l'employé
Perfect.
Commentaires du client
super boulot / great job :)

Spécifications

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


Répondu

1
Développeur 1
Évaluation
(620)
Projets
680
57%
Arbitrage
25
16% / 60%
En retard
228
34%
Gratuit
2
Développeur 2
Évaluation
(117)
Projets
138
41%
Arbitrage
30
7% / 77%
En retard
17
12%
Gratuit
3
Développeur 3
Évaluation
(365)
Projets
412
36%
Arbitrage
35
26% / 57%
En retard
63
15%
Gratuit
Commandes similaires
I need help with creating a website traders chatroom, it must show traders online,offline,inactive. the chatroom top section must show four clocks with different times and time scale like this.. the chatroom must have a history data of up to 10days, then longer history must be deleted automatically. if you have better chatroom please say your recommendations
I am looking for an experienced MQL5 developer to help me finalize and optimize an Expert Advisor (EA) for the FTMO challenge. I have already built a significant portion of the code, but it requires further refinement and optimization to ensure it functions according to the trading strategy I intend to use. I am happy to share all the resources, including the current code, reference materials, and detailed
dreams good and have a great Cash out from your smart phone , tuyoywuiy glamorous flood see full idk idk slow so dolls stupid sis workouts who's spark koalas oral waits also doggo idk
BUY AND SELL 30+ USD
Create an Expert Advisor that collaborates between these indicators ETR, MEv2 and STLv3 with these features 1. SL and TP 2. TIME FILTER 3. ETR, MEv2 and STLv3 PARAMETERS BUY ENTRY STEP 1. FIRST candle OPEN above Symphonie Trend Line STEP 2. Check Symphonie Extreme must indicate color BLUE STEP 3. Check Symphonie Emotion must indicate color BLUE STEP 4. Open trade with money management STEP 5. Trade open MUST BE 1
EA MT5 SNR 30 - 100 USD
I need a developer who can work with quickly & details. make an EA MT5 Classic Support aNd Resistance multi time frame marking single Classic support and resistance support type A and Resistance type V make an alert pop-up
Excellent trade 30 - 40 USD
I need a developer that will modify an EA that is made using 4 indicators, example, volume, average true range,RSI and MFI, this EA is user input and input adjustable, any programmer that can do this job should Apply and lets proceed
hi, just like mt5 plateform. there is one another new platefrom called TM9 whose website is( https://trademaster9.com/site/index.html ) i want you to create an API intigration to connect mt5 or mt4 plateform to this platform. i want you to create a copy trading software which can copy trade from mt5/mt4 to trade master 9 plateform. for more information please contact me directly. PRICE CAN BE NEGOTIATED. looking
Requirement: 1. Convert Pivot source code .mq4 to Sierra Chart mq4 source code is provided .mq4 as attached .mq4 2. upon conversion to add a button code on Sierra chart .cpp to allow display/hide the pivot line in Sierra Chart ---- *no need alert, make it light without any alert, just a button to display/hide pivot line will do :) to continue, pivot font text also no need I"ve mark with red cross to remove see
I have 2 (indicators) I coded and I use on Tradingview I just need converted to use on Ninjatrader i will be looking for great developer to bid for it and for more details
Hello, I'm seeking a freelancer with access to a ready-made server solution for an educational forex project. Requirements: Ability to control or manipulate live or historical trading data. Platform to execute simulated trades with exaggerated outcomes. Tools for real-time trade simulation (white-label or virtual dealer solutions). If you have a suitable server or can help me find one, please reach out with details

Informations sur le projet

Budget
30+ USD
TVA (20%): 6 USD
Total: 36 USD
Pour le développeur
27 USD
Délais
à 1 jour(s)