Help for limit order

 

I want to limit orders only one position for each entry point 

but I don't want use buy limit or sell limit



 
Hadi Ein Jafari:

I want to limit order only one position for each entry point 

but I don't want use buy limit



hi hadi

your request are unclear


Request 1:

    int TotalOpenOrder       = 0;
    int TotalBuyOrder        = 0;
    int TotalSellOrder       = 0;
    for (int i = 0; i < OrdersTotal(); i++)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            if ((OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderSymbol() == Symbol() && (OrderComment() == "SF_Sell_H4" || OrderComment() == "SF_Buy_H4"))
                TotalOpenOrder++;
            if (OrderType() == OP_BUY)
                TotalBuyOrder++;
            if (OrderType() == OP_SELL)
                TotalSellOrder++;
        }
    }


Request 2:

int TradesBuyWin         = 0;
int TradesBuyLost        = 0;
int TradesSellWin        = 0;
int TradesSellLost       = 0;
int TradesWin            = 0;
int TradesLost           = 0;
int TotalClosedBuyOrder  = 0;
int TotalClosedSellOrder = 0;
int TotalClosedOrder     = 0;
for (int h = OrdersHistoryTotal() - 1; h >= 0; h--)
{
    if (OrderSelect(h, SELECT_BY_POS, MODE_HISTORY))
    {
        if (OrderSymbol() == Symbol() && TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent()) && (OrderComment() == "SF_Sell_H4" || OrderComment() == "SF_Buy_H4"))
        {
            TotalClosedOrder++;
            if (OrderProfit() + OrderCommission() + OrderSwap() <= 0)
                TradesLost++;
            if (OrderProfit() + OrderCommission() + OrderSwap() > 0)
                TradesWin++;
            if (OrderProfit() + OrderCommission() + OrderSwap() <= 0 && OrderType() == OP_BUY)
                TradesBuyLost++;
            if (OrderProfit() + OrderCommission() + OrderSwap() > 0 && OrderType() == OP_BUY)
                TradesBuyWin++;
            if (OrderProfit() + OrderCommission() + OrderSwap() <= 0 && OrderType() == OP_SELL)
                TradesSellLost++;
            if (OrderProfit() + OrderCommission() + OrderSwap() > 0 && OrderType() == OP_SELL)
                TradesSellWin++;
            if ((OrderType() == OP_BUY))
                TotalClosedBuyOrder++;
            if ((OrderType() == OP_SELL))
                TotalClosedSellOrder++;
        }
    }
}
 
Koros Jafarzadeh:

Hi Hadi Jan, Say you understand the nation.

You know what you wrote, Farsi say, help me as much as you know.

Please post only in English on this forum. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation.
 
This is an English language forum.
Please only post in English.
Use the site's translation tool if necessary.


You have already been told and continued to post.

I have deleted the posts that were not in English language.

 
Keith Watford:
This is an English language forum.
Please only post in English.
Use the site's translation tool if necessary.


You have already been told and continued to post.

I have deleted the posts that were not in English language.

 dear keith

I wrote in English and just copy and paste first post to show which code belong to paragraph.

sorry for inconvenience

 
Koros Jafarzadeh:

hi hadi

your request are unclear


Request 1:


Request 2:

Hi dear koros. tnq for code 

//+------------------------------------------------------------------+
//|                                                    Lasttrade.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

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

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(Last_Trade_H4_Sell())
     {
      Print("Last_Trade_H4_Sell : ",Time[0]);
     }
   if(Last_Trade_H1_Sell())
     {
      Print("Last_Trade_H1_Sell : ",Time[0]);
     }
   if(Last_Trade_M30_Sell())
     {
      Print("Last_Trade_M30_Sell : ",Time[0]);
     }
   if(Last_Trade_M15_Sell())
     {
      Print("Last_Trade_M15_Sell : ",Time[0]);
     }
   if(Last_Trade_M5_Sell())
     {
      Print("Last_Trade_M5_Sell : ",Time[0]);
     }
//-------------------------------------------------------------
    if(Last_Trade_H4_Buy())
     {
      Print("Last_Trade_H4_Buy : ",Time[0]);
     }
   if(Last_Trade_H1_Buy())
     {
      Print("Last_Trade_H1_Buy : ",Time[0]);
     }
   if(Last_Trade_M30_Buy())
     {
      Print("Last_Trade_M30_Buy : ",Time[0]);
     }
   if(Last_Trade_M15_Buy())
     {
      Print("Last_Trade_M15_Buy : ",Time[0]);
     }
   if(Last_Trade_M5_Buy())
     {
      Print("Last_Trade_M5_Buy : ",Time[0]);
     }

  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
bool Last_Trade_H4_Sell()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*240)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+
bool Last_Trade_H1_Sell()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*60)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+
bool Last_Trade_M30_Sell()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*30)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+
bool Last_Trade_M15_Sell()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*15)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+
bool Last_Trade_M5_Sell()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*5)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
bool Last_Trade_H4_Buy()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*240)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+
bool Last_Trade_H1_Buy()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*60)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+
bool Last_Trade_M30_Buy()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*30)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+
bool Last_Trade_M15_Buy()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*15)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+
bool Last_Trade_M5_Buy()
  {
   static datetime lastTrade=0;
   datetime CurrentBar=Time[0];
   if(CurrentBar>=lastTrade+7*Period()*5)
     {
      lastTrade=CurrentBar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                      ForTest.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

bool  Bool_OrderCommnet_H4_Sell=False,Bool_OrderCommnet_H4_Buy=False;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   //int S=OrderSend(Symbol(),OP_SELL,0.01,Bid,0,0,0,"SF_Sell_H4",0,0,clrNONE);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

  
   Bool_OrderCommnet_H4_Sell=False;
   if(OrdersTotal()==0)
     {
      int S=OrderSend(Symbol(),OP_SELL,0.01,Bid,0,0,0,"SF_Sell_H4",0,0,clrNONE);
     }
   else if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) && (OrderType()==OP_SELL) && (OrderSymbol()==Symbol()) && (OrderComment()=="SF_Sell_H4"))
     {
      Bool_OrderCommnet_H4_Sell=True;
     }
   else
     {
      for(int i=OrdersTotal()-1; i>0; i--)
         // for(int i=0;i<OrdersTotal()+1;i++)
        {
         Print("i : ",i);

         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
           {
            if((OrderType()==OP_SELL) && (OrderSymbol()==Symbol()) && (OrderComment()=="SF_Sell_H4"))
              {
               Bool_OrderCommnet_H4_Sell=True;

              }
            else if(Bool_OrderCommnet_H4_Sell==False)
              {

               int S=OrderSend(Symbol(),OP_SELL,0.01,Bid,0,0,0,"SF_Sell_H4",0,0,clrNONE);
               Bool_OrderCommnet_H4_Sell=True;
               Sleep(2000);
              }
           }
        }
     }
  }

//+------------------------------------------------------------------+
Reason: