Problem opening position

MQL4 Indicadores Experts C++

Trabalho concluído

Tempo de execução 25 segundos
Comentário do cliente
Nice job :)
Comentário do desenvolvedor
Perfect

Termos de Referência

Hello,

Problem opening position

example:

When I have an order that opens either to bull or sell in the function

if(Counts () == 0

if it's a bull order and my stop loss is hit then it will go to the function

if (Counts () == 1 ect ...

what I want is when my function

if (Counts () == 2

is hit and a bull order is opened and my stop loss is hit then my function

if (Counts () == 3

will open a sell order.

and if my function

if (Counts () == 2

opens a sell order then my function

if (Counts () == 3

will open a bull command



//|                                                       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.03;
extern double  lots3          = 0.10;
extern double  lots4          = 0.01;
extern double  lots5          = 0.03;
extern double  lots6          = 0.10;
extern double  lots7          = 0.01;
extern double  lots8          = 0.03;
extern double  lots9          = 0.10;
extern double  lots10         = 0.01;
extern double  lots11          = 0.03;
extern double  lots12          = 0.10;





input int      TakeProfit1     =   10;
input int      StopLoss1       =   20;
input int      TakeProfit2     =   10;
input int      StopLoss2       =   20;
input int      TakeProfit3     =   10;
input int      StopLoss3       =   20;
input int      TakeProfit4     =   10;
input int      StopLoss4       =   20;
input int      TakeProfit5     =   10;
input int      StopLoss5       =   20;
input int      TakeProfit6     =   10;
input int      StopLoss6       =   20;
input int      TakeProfit7     =   10;
input int      StopLoss7       =   20;
input int      TakeProfit8     =   10;
input int      StopLoss8       =   20;
input int      TakeProfit9     =   10;
input int      StopLoss9       =   20;
input int      TakeProfit10    =   10;
input int      StopLoss10      =   20;
input int      TakeProfit11     =   10;
input int      StopLoss11       =   20;
input int      TakeProfit12     =   10;
input int      StopLoss12       =   20;








input int period=14; // Averagin period for calculation
input int period1=14; 
input int period2=14; 
input int period3=14; 
//input ENUM_APPLIED_PRICE appPrice=PRICE_HIGH; // Applied price
input int OverBought=70; // Over bought level
input int OverSold=30; // Over sold level
input int OverBought1=75; // Over bought level
input int OverSold1=25; // Over sold level
input int OverBought2=80; // Over bought level
input int OverSold2=20; // Over sold level
input int OverBought3=85; // Over bought level
input int OverSold3=15; // Over sold level
extern int     magic          = 118516;
//extern double  Level          = 1.3660;
//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;
double takeprofit11=TakeProfit11;
double stoploss11 =StopLoss11;
double takeprofit12=TakeProfit12;
double stoploss12 =StopLoss12;




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

  {
   RunOnce=false;
   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;
      takeprofit11  =TakeProfit11*10;
      stoploss11    =StopLoss11*10;
      takeprofit12  =TakeProfit12*10;
      stoploss12    =StopLoss12*10;



   


      
     }
   return(INIT_SUCCEEDED);
  }
 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnTimer()
{
OnTick();        
}
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{

  if(IsLastOrderClose())
    {
    OnInit();
    Print("Ea Closed Manually ");
    EaStartTime=TimeCurrent();
    }
      
      double rsi=iRSI(_Symbol,PERIOD_CURRENT,period,PRICE_HIGH,1);
      double rsi1=iRSI(_Symbol,PERIOD_CURRENT,period1,PRICE_HIGH,1);
      double rsi2=iRSI(_Symbol,PERIOD_CURRENT,period2,PRICE_HIGH,1);
      double rsi3=iRSI(_Symbol,PERIOD_CURRENT,period3,PRICE_HIGH,1);
      double MA_Fast1,MA_Low1,MA_Fast2,MA_Low2;

          MA_Fast1=iMA( NULL, PERIOD_M1, 1, 0, MODE_SMA, PRICE_TYPICAL, 0); // áûñòðàÿ ÌÀ
          MA_Low1=iMA( NULL, PERIOD_M1, 20, 7, MODE_SMA, PRICE_CLOSE, 0); // ìåäëåííàÿ ÌÀ 
          MA_Fast2=iMA( NULL, PERIOD_M1, 1, 0, MODE_SMA, PRICE_TYPICAL, 1); // áûñòðàÿ ÌÀ
          MA_Low2=iMA( NULL, PERIOD_M1, 20, 7, MODE_SMA, PRICE_CLOSE, 1); // ìåäëåííàÿ ÌÀ 
          
         






   int ticet;
   int t=MathRand();
   if(CountVsego()==0)
     {
      if(t>16384)
        {
         if(Counts()==0&& (rsi<OverSold))//&&( Close[0] > High[1] ))// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
         {
            ticet=OrderSend(Symbol(),OP_BUY,lots1,Ask,3,Bid-stoploss1*Point,Ask+takeprofit1*Point,"1",magic,0,clrGreen);
            if(ticet>0)
            {
               RunOnce=true;//OverSold
            }
         }
        }
// Partie 1 
     else if(t<16384)
        {
         if(Counts()==0&&(rsi>OverBought ))//&&( Close[0] < Low[1] ))// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
         {
            ticet=OrderSend(Symbol(),OP_SELL,lots1,Bid,3,Ask+stoploss1*Point,Bid-takeprofit1*Point,"1",magic,0,clrRed);
            if(ticet>0)
            {
               RunOnce=true;
            }
         }
        }
     // if(t>16384)
      //  {
         if(Counts()==1&&  (rsi1<OverSold1))// && MA_Fast2<MA_Low2 ))//&&( Close[0] > High[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);
           // if(ticet>0)
          //  {
          //     RunOnce=true;
            }
       //  }
      //  }
// Partie 2 
    // else if(t<16384)
      //  {
         if(Counts()==1&&  (rsi1>OverBought1 ))// && MA_Fast2>MA_Low2   ))//&&( Close[0] < Low[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(ticet>0)
       //     {
       //        RunOnce=true;
            }
        // }
       // }
     // if(t>16384)
      //  {
         if(Counts()==2&&  (rsi2<OverSold2))// && MA_Fast4<MA_Low4 ))//&&( Close[0] > High[1] ))// && (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);
        //    if(ticet>0)
         //   {
         //      RunOnce=true;
            }
        // }
      //  }
//Partie 3 
    // else if(t<16384)
    //    {
         if(Counts()==2&&  (rsi2>OverBought2 ))// && MA_Fast4>MA_Low4   ))//&&( Close[0] < Low[1] ))// && (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(ticet>0)
            //{
            //   RunOnce=true;
            }
       //  }
     //   }                
      // if(t>16384)
      //  {
         if(Counts()==3&&(rsi<OverSold))//&&( Close[0] > High[1] ))// && (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);
          //  if(ticet>0)
           // {
           //    RunOnce=true;
           // }
         }
       // }
// Partie 4 
    // else if(t<16384)
     //   {
         if(Counts()==3&&(rsi>OverBought ))//&&( Close[0] < Low[1] ))// && (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(ticet>0)
        //    {
        //       RunOnce=true;
            }
      //   }
      //  }
    //  if(t>16384)
     //   {
         if(Counts()==4&&  (rsi1<OverSold1))// && MA_Fast2<MA_Low2 ))//&&( Close[0] > High[1] ))// && (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);
        //    if(ticet>0)
        //    {
        //       RunOnce=true;
            }
       //  }
       // }
// Partie 5 
  //   else if(t<16384)
    //    {
         if(Counts()==4&&  (rsi1>OverBought1 ))// && MA_Fast2>MA_Low2   ))//&&( Close[0] < Low[1] ))// && (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(ticet>0)
          //  {
            //   RunOnce=true;
           // }
        // }
     
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 && OrderCloseTime()>=EaStartTime)
          {
             if(OrderProfit()>0)
             {
               if(count==0)
               {
                   OnInit();
                   EaStartTime=TimeCurrent();
               }
               return count;
             }else
             {
               count++;
             }
          }
          if(count > 11 && OrderCloseTime()>=EaStartTime) count=0;
         }
      }
   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 && OrderCloseTime()>=EaStartTime)
       {
       if(OrderClosePrice()>OrderStopLoss() && OrderClosePrice()<OrderTakeProfit())
         {
         signal = true;
         
         }
         break;
       }
     else if(OrderType()==OP_SELL && OrderCloseTime()>=EaStartTime)
       {
       if(OrderClosePrice()<OrderStopLoss() && OrderClosePrice()>OrderTakeProfit())
         {
         signal = true;
         
         }
         break;
       }
       break;
     }
  }
return(signal);
}

Respondido

1
Desenvolvedor 1
Classificação
(117)
Projetos
138
41%
Arbitragem
30
7% / 77%
Expirado
17
12%
Livre
2
Desenvolvedor 2
Classificação
(89)
Projetos
136
14%
Arbitragem
43
21% / 28%
Expirado
14
10%
Livre
Publicou: 2 códigos
3
Desenvolvedor 3
Classificação
(94)
Projetos
148
59%
Arbitragem
16
38% / 13%
Expirado
25
17%
Livre
Publicou: 1 código
4
Desenvolvedor 4
Classificação
(620)
Projetos
680
57%
Arbitragem
25
16% / 60%
Expirado
228
34%
Livre
Pedidos semelhantes
THE STUDY : Add 4 study overlay in the input settings and color bar based on alert condition is sg1=1 I want it to trail the order instead of flat to avoid too much slippage What I do is the 15-Minutes chart I have filter also in the 10tick chart if those filters are meet the bar is green or red using sierrachar color bar based on alert condition I overlay the 4 in the study in the 6tick Renko chart that will
want an aggressive scalping Expert Advisor (EA) for XAUUSD (Gold) on M1 timeframe with the following features: ✅ Uses a combination of EMA, RSI, and ATR for entry signals. ✅ Recovery Mode to increase lot size on confirmed setups to recover losses safely. ✅ Trailing Stop functionality with adjustable start and step parameters. ✅ Stop trading after daily target or daily loss limit is reached. ✅ Money Management (fixed
Hello! I've been working on a strategy that uses Ninzarenko candles from ninza.co, and while I am making incremental progress, i think I need someone to get me 100% across the finish line. This is a simple standard deviation strategy, take a look at the screenshot and see if this is something you think we can do together. Basic requirements below .. . let me know if you have any questions! Goal of the Strategy Trade
I have an account on (MT4 AxiTrader) I need some support from you I need to add a bank account on the Client Portal. Once its verify my bank account, I can submit a withdrawal. If you can do that for me then send me an offer please If you can can help how to add a bank account on the (Client Portal) please I will be very appreciate
to compile all the suitable markets for buy and place a buy for the shortest timeframe and place a sell for also a shortest timeframe it should work with all brokers and can automatically place a trade as long as its connected to the internet it should inform where the contracts are placed and for how long
ATAS trading bot. 40 - 70 USD
Hello expert developer i am interested in an ATAS trading bot. i already know what I want it to do. What are your terms regarding confidentiality? After I have hired you for a project, does the final product remain solely mine, and will it not be replicated? I am open to any suggestions on how it can be improved. or any limitation you may notice i'll be looking forward to expert developer only to work with thanks
i am looking for an indicator that gives buy sell signal by placing arrows on the chart, signals must not repaint or be placed with an offset, i want it to be accurate enough so i can trade from signal to signal and actually make profit, do any one have a strategy and skill to create such an indicator, and also it is to mql5, ( Important is, It must have No repainting and No offset ), if you know it is something you
The PRD: 1. Plugin ensures that individual opening positions come from MT4 to our colocated virtual machine 2. A score is returned from a lookup 3. Binary decision based on score. 4. Matches closing position with opening position; doesn't score, simply closes the trade. The plugin UX should have the following: 1. Risk threshold per grouping, easily entered by the client 2. Reporting of revenue comparisons To confirm
Mql5 indicator 30+ USD
I'm looking for an indicator that gives buy sell signals by placing arrows on the chart Signals must not repaint or be placed with an offset I want it to be accurate enough so j can trade from signal to signal amd actually make profit Do anyone have a strategy and skill to create such an indicatore First priority is to mql5
I need help listing all the studies from a chart. * I’m trying to build a scoring engine and show the score as a text message right on the chart, so I don’t have to keep checking multiple charts. Another project I’m working on—I’ve subscribed to OrderFlowLabs indicators and want to use Python to build better scoring logic. I started working on it using Claude.ai Max, but I got a bit distracted. Now, i need to

Informações sobre o projeto

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