EA (new bie)

 
I am a computer engineer. interested in writing MQL4 EA programming. I am happy to assist or work together to write good EA for any one. Please let me know if you need any of my assitance. Thank you.
 

Please can you or anybody in this forum help and give me the right code for solving the situation below:

1. my EA trade very good but it open a new position immediately after taking profit even if the market is going other way.

2. i want a code that will not allow two same order-type from following each other after taking profit.( once it takes profit for example on buy trade, it should wait for next sell signal before opening new position for that same symbol)


i used OrderHistoryTotal but i did not get the right coding.

 

what is going on with u how many times u need to post your question

something like this

bool Signal = false;

if (we have a signal)
   {
   Signal = true;
   }
   
if (Signal)
   {
   int Ticket = OrderSend(.......);
   if (Ticket > -1)
      {
      Signal = false;
      }
   }
 

If you can't do it yourself you could always email this forum offer : https://www.mql5.com/en/forum/108714

 
grmvarma:
I am a computer engineer. interested in writing MQL4 EA programming. I am happy to assist or work together to write good EA for any one. Please let me know if you need any of my assitance. Thank you.

Dear grmvarma and others,

Could you please help me to solve my following EA so that it can open multiple order. I would like to add more than one order in the same direction after I already opened an order. However, my EA opens only 1 order instead of more than one order as I want.

The following chart is my entry/exit rule and my EA.

In general, I want to open a sell order #1 when moving average (240) is higher than the cross value between MA (240) and MA (480) about 10 pips, and MA(120) < MA(240). The second and later sell order will be open as the conditions as the first sell order if the Ask is higher than the last OrderOpenPrice() about 10 pip and current MA(120) is higher than the value of MA (120) at last order. I will exit all of my sell order when the conditions are opposite to my first sell order entry conditions.

Thank you very much in advance.


Following is part of my EA for entry signal and the attachment is my completed EA that I asked for your help

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+

//Signal for buy entry
if (MVA_240_0 < MVA_480_shift-100*Point && MVA_240_0 < MVA_480_0 && MVA_120_0 > MVA_240_0) Order = SIGNAL_BUY; // Sigal for first buy entry
if (Ask < OrderOpenPrice() - 100*Point && MVA_120_0 < MVA_120_shift - 100*Point && MVA_240_0 < MVA_480_shift-100*Point && MVA_240_0 < MVA_480_0 && MVA_120_0 > MVA_240_0) Order = SIGNAL_BUY1;//Signal for second/third/ buy entry

//Signal for sell entry

if (MVA_240_0 > MVA_480_shift+100*Point && MVA_240_0 > MVA_480_0 && MVA_120_0 < MVA_240_0) Order = SIGNAL_SELL; // Sigal for first sell entry
if (Ask > OrderOpenPrice() + 100*Point && MVA_120_0 > MVA_120_shift + 100*Point && MVA_240_0 > MVA_480_shift+100*Point && MVA_240_0 > MVA_480_0 && MVA_120_0 < MVA_240_0) Order = SIGNAL_SELL1;//Signal for second/third/ sell entry

   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
                        } else {
                                Print("Error opening BUY order : ", GetLastError());
                        }
         }

         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

//------
//Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
        
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
                        } else {
                                Print("Error opening SELL order : ", GetLastError());
                        }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }
//------

///---
}
Files:
Reason: