This EA is not working as per my strategy. Need your help to modify the same.

 
//+------------------------------------------------------------------+
//|                                                    Mahim.mq4 |
//|                           |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#include <stdlib.mqh>      //library for managing errors between different
#include <WinUser32.mqh>   //library to use the dialogs

extern double lot = 0.1;      // lot of the order
extern double take_profit= 50; //pips

int magic = 666;
bool pos;
int stop;
int cntp, cntg;
string sym;
int ordre;
int spread;
double prixA, prixV;
double eqA, eqV, eqAF, eqVF;
int ticketA, ticketV, ticketF;
int total;
double i;
int Prev_Orders = -1;
int MagicNumber = 460;  

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   sym = Symbol();
   stop = 0;
   pos= false;             // dual position open or not
   cntg = 0;               // position number Won
   cntp = 0;               // number of lost position
   ordre = 0;              // number of orders remaining
   spread = MarketInfo (sym, MODE_SPREAD);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
 
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

      
   if (pos == false) {
      Print ("first tick");
      debug ();
      total = OrdersHistoryTotal();
         for(i = total - 1; i >= 0; i--)
         {
         OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
         if(OrderSymbol() == Symbol())
         {
      if(TimeCurrent() - OrderCloseTime()==1)
      {
       if(OrderClosePrice() == OrderTakeProfit())
      
      OrderSend (sym, OP_BUY, lot, Ask, 3, 0,Ask+take_profit*Point, "buy!!!", magic, 0, Blue);
      OrderSend (sym, OP_SELL, lot, Bid, 3, 0,Bid-take_profit*Point, "sell !!!", magic, 0, Red);
      
      }
      }}
          
     
     return(0);
   }
   }
//----
   
  
I want to modify above mentioned code in such a way that it opens BUY and SELL order first then Once Take Profit is hit it again open BUY and SELL order with same quantity again and again
 
3986:
I want to modify above mentioned code in such a way that it opens BUY and SELL order first then Once Take Profit is hit it again open BUY and SELL order with same quantity again and again
OK,  where are you having problems ?
 
  1.   OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
      OrderSend (sym, OP_BUY, lot, Ask,...
    What are Function return values ? How do I use them ? - MQL4 forum
  2. if(OrderClosePrice() == OrderTakeProfit())
    A SL/TP becomes a market order. The close price will never be equal. Working with Doubles in MQL4 - MQL4 Articles
  3.  if(TimeCurrent() - OrderCloseTime()==1)
    What happens if there is no tick in the second the previous order closed?
  4. OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
    if(OrderSymbol() == Symbol())
    No magic number makes the EA incompatable with ever other (including itself on other TFs) and manual trading.


 

Dear RaptorUK,

When I run this EA on live trade. I have to put first Buy and Sell order manually. EA put Buy order only once Profit taking hit. Some time it puts 2-3 Buy order simultaneously. It should put one Sell order along with one Buy order. And if it can be modified in a way that first manual order of Buy and Sell should not be put  then it would be of great help. I have been using these strategy since one year and it has been profitable for me.

Thank you very much in advance for your help. 

Thanks

Manoj 

 
3986:

Dear RaptorUK,

When I run this EA on live trade. I have to put first Buy and Sell order manually. EA put Buy order only once Profit taking hit. Some time it puts 2-3 Buy order simultaneously. It should put one Sell order along with one Buy order. And if it can be modified in a way that first manual order of Buy and Sell should not be put  then it would be of great help. I have been using these strategy since one year and it has been profitable for me.

I'm sure it can be modified . . .  but you haven't explained what part of the coding you are having problems with ?
 
 total = OrdersHistoryTotal();
         for(i = total - 1; i >= 0; i--)
         {
         OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
         if(OrderSymbol() == Symbol())
         {
      if(TimeCurrent() - OrderCloseTime()==1)
      {
       if(OrderClosePrice() == OrderTakeProfit())
      
      OrderSend (sym, OP_BUY, lot, Ask, 3, 0,Ask+take_profit*Point, "buy!!!", magic, 0, Blue);
      OrderSend (sym, OP_SELL, lot, Bid, 3, 0,Bid-take_profit*Point, "sell !!!", magic, 0, Red);
      
      }
      }}
          
     
     return(0);
RaptorUK
:

I'm sure it can be modified . . .  but you haven't explained what part of the coding you are having problems with ?


 If condition to identify the last order close can be made accurate and order send is not triggering both order. Is it not possible to modify coding as per strategy I have mentioned above using MQ4 language?
 
3986:

 If condition to identify the last order close can be made accurate and order send is not triggering both order. Is it not possible to modify coding as per strategy I have mentioned above using MQ4 language?

I am looking forward to receive any feedback soon!
 
3986:

I am looking forward to receive any feedback soon!
I'm looking forward to seeing your attempt at coding what you want to happen . .