Sudden Closing of Trades

Back to topics list To post a new topic, please log in or register
avatar
11
blue_stacks 2016.02.23 06:07
 

Hi everyone,


I have created an expert which has 2 CButton which is Buy and Sell. If you click on "Buy" it will enter a trade on buy same as if you click "Sell" button, the problem arises when after the trade has been executed, it will close the newly opened trade. I thought that the code that i use for closing is the reason. I have disable the logic for closing and tried to trade again but the results are the same. After the execution of the new trade, i will close automatically. Does anyone of you experienced this kind of stuff in one of your experts?


Thanks...

avatar
Moderator
3418
GumRai 2016.02.23 08:07 #
 

Without seeing the code, it is not possible to advise much.

Just be sure that you have nothing in the code to close trades and that you do not have an EA on another chart that will close the trades.

avatar
11
blue_stacks 2016.02.23 09:21 #
 
GumRai:

Without seeing the code, it is not possible to advise much.

Just be sure that you have nothing in the code to close trades and that you do not have an EA on another chart that will close the trades.

I have already disabled the code that closes trades when it reach certain conditions and that is the only "closing code" that is included on the EA.


void CPanelDialog::OnClickSell(void)
{

   double sp=StringToDouble(edit2.Text())/pow(10,MarketInfo(Symbol(),MODE_DIGITS));
   
   if(ReturnRow(edit5.Text())>-1)
   {
      cmd=OP_SELL;
      vol=volume_array[ReturnRow(edit5.Text())][0]; 
      open_price=MarketInfo(Symbol(),MODE_BID);
      group=edit4.Text()+":1";
      ticket=OrderSend(Symbol(),cmd,vol,open_price,0,0,0,group,0,0,clrNONE);
      if(ticket>0)
      {
         pending=open_price+(100/(pow(10,MarketInfo(Symbol(),MODE_DIGITS))));
         vol=volume_array[ReturnRow(edit5.Text())][1];
         group=edit4.Text()+":2";
         
         int ticketA=OrderSend(Symbol(),OP_SELLLIMIT,vol,pending,0,0,0,group,0,0,clrNONE);
         if(ticketA>0)
         {
            stop_loss=open_price+(1000/(pow(10,MarketInfo(Symbol(),MODE_DIGITS))))+sp;
            take_profit=open_price-(200/(pow(10,MarketInfo(Symbol(),MODE_DIGITS)))-sp;
            
            if(OrderModify(ticket,OrderOpenPrice(),stop_loss,take_profit,0,clrNONE))
            {}
         }
      }
      else
      {
         MessageBox(ErrorDescription(GetLastError()));
      }
   }
   else
   {
      MessageBox("Invalid Volume");
   }
}


After you "click" this button, it will open a trade on sell and before it will open a pending order as the code suggested above, it will close the newly opened sell trade.



avatar
13000
WHRoeder 2016.02.23 13:12 #
 
  1. int ticketA=OrderSend(Symbol(),OP_SELLLIMIT,vol,pending,0,0,0,group,0,0,clrNONE);
             if(ticketA>0)
             {
                stop_loss=open_price+(1000/(pow(10,MarketInfo(Symbol(),MODE_DIGITS))))+sp;
                take_profit=open_price-(200/(pow(10,MarketInfo(Symbol(),MODE_DIGITS)))-sp;
                
                if(OrderModify(ticket,OrderOpenPrice(),stop_loss,take_profit,0,clrNONE)){}
    You can not use any Trade Functions unless you select the order first.
  2. Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. MarketInfo(Symbol(),MODE_BID);
    MarketInfo(Symbol(),MODE_DIGITS)
    Since you are using the current symbol  and current timeframe why use a function call instead of just the predefined variables Bid and Digits?
    1000/(pow(10,MarketInfo(Symbol(),MODE_DIGITS))
    Why are you computing 1/10^Digits
    1000/(pow(10,Digits)
    When it's the same a point.
    1000*_Point

  4. blue_stacks: After you "click" this button, it will open a trade on sell and before it will open a pending order as the code suggested above, it will close the newly opened sell trade.
    There is no such thing a auto close (except if you see stop out in the log) and your code doesn't contain a close or a delete. Therefor your statement is wrong. Add print statements at the beginning and end of your functions and track it down.
Back to topics list  

To add comments, please log in or register