Download MetaTrader 5
To add comments, please log in or register
Code Base will help you in mastering your theoretical skills. Come and learn!
Samuel Oyeniyi
373
Samuel Oyeniyi 2016.06.11 16:40 

I am running the strategy tester but keeps getting error 10036- position already closed!! The returned message fron the server has the position ID supposing it is an open position!!!!

Your help will be grately appreciated .

error 10036 

Alain Verleyen
Moderator
30183
Alain Verleyen 2016.06.11 17:07  
Help with what ? Show your code !
Samuel Oyeniyi
373
Samuel Oyeniyi 2016.06.11 17:54  
Samuel Oyeniyi:

I am running the strategy tester but keeps getting error 10036- position already closed!! The returned message fron the server has the position ID supposing it is an open position!!!!

Your help will be grately appreciated .

 

       
           if ( (PositionsTotal()>0) &&   (PositionSelect(Symbol())==true)){           
         if (((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) &&  (myPosition.StopLoss()==0) ){ 
           //--- preparing a request
            MqlTradeRequest request;
            ZeroMemory(request);
            ZeroMemory(mresult);
            ZeroMemory(mcheck);            
            //--- placing an immediate order
            mrequest.action=TRADE_ACTION_SLTP;
            //--- instrument
            mrequest.symbol=Symbol();
            //--- Stop Loss 
            Sleep(1000);
           // mrequest.sl=NormalizeDouble(getSellStopLoss(Symbol(),LTF),_Digits);
                        if (StringSubstr(Symbol(),3,3)=="JPY"){
            mrequest.sl=NormalizeDouble(myPosition.PriceOpen() + (STL*_Point*100+mySymbol.StopsLevel()*_Point),_Digits);
           }else{
            mrequest.sl=NormalizeDouble(myPosition.PriceOpen() + (STL*_Point+mySymbol.StopsLevel()*_Point),_Digits);}
            
            //--- Take Profit is not specified
             if (StringSubstr(Symbol(),3,3)=="JPY"){
            mrequest.tp=NormalizeDouble(myPosition.PriceOpen() - (TKP*_Point*100+mySymbol.StopsLevel()*_Point),_Digits);
         }else{
          mrequest.tp=NormalizeDouble(myPosition.PriceOpen() - (TKP*_Point+mySymbol.StopsLevel()*_Point),_Digits);}
          
           // MqlTradeResult result;
            //ZeroMemory(result);
            MqlTradeCheckResult CheckResult;
            //--- sending the order
            if(OrderCheck(mrequest,CheckResult)) {OrderSend(mrequest,mresult);}
            else
              {
               //--- printing the server response to the log  
               Print(CheckResult.retcode,"  -error ");
               Print(mrequest.sl,"  ","  <sell sl "," Bprice=",Bprice," Sprice=",Sprice," id=",myPosition.Identifier()+" tikect="+myPosition.Ticket()+",HistoryOrdersTotal()=",HistoryOrdersTotal()+" HTicket"+myHistory.Ticket());
               Print(__FUNCTION__,":",CheckResult.comment);
              }
         
         }
        }
        
AnkaSoftware
178
AnkaSoftware 2016.07.12 12:46  

Hi,

    Any update on this. Am facing the same error, ie Position is already open, however when a MqlTradeRequest with action = TRADE_ACTION_SLTP, is sent a Position Closed error 10036 is returned. This works fine in demo, but not in real account.

 

Regards

 

Vivek 

Nguyen Nga
5294
Nguyen Nga 2016.07.13 10:40  
Samuel Oyeniyi:

I am running the strategy tester but keeps getting error 10036- position already closed!! The returned message fron the server has the position ID supposing it is an open position!!!!

Your help will be grately appreciated .

 

i think you must use  myPosition.Select(Symbol())

Rashid Umarov
Admin
11676
Rashid Umarov 2016.07.17 10:27  
Samuel Oyeniyi:

I am running the strategy tester but keeps getting error 10036- position already closed!! The returned message fron the server has the position ID supposing it is an open position!!!!

Your help will be grately appreciated .

 

It is not clear if your trade account support hedging? For hedging account you should go through all pisitions on selested symbol
AnkaSoftware
178
AnkaSoftware 2016.07.17 20:06  
Rashid Umarov:
It is not clear if your trade account support hedging? For hedging account you should go through all pisitions on selested symbol

Hi Rashid,

    In my case the account supports hedging, and I can see the position in 'Trade' tab. My code is as follows:

 

int total = (int) PositionsTotal();
for ( int i = 0; i < total; i++ ) 
{
   if ( PositionSelect( PositionGetSymbol( i )))
   {
      if ( PositionGetSymbol( i ) != _Symbol )
         continue;
   
      // Send MQL MqlTradeRequest to modify the SL, which gives position closed error
   }
}

Regards

 

Vivek 


Rashid Umarov
Admin
11676
Rashid Umarov 2016.07.18 15:43  
AnkaSoftware:

Hi Rashid,

    In my case the account supports hedging, and I can see the position in 'Trade' tab. My code is as follows:


Why do not you use proper fucntion PositionGetTicket()?
AnkaSoftware
178
AnkaSoftware 2016.07.18 18:45  
Can use  PositionGetTicket(), but dont think it will effect the error which is being ging by  MqlTradeRequest
Samuel Oyeniyi
373
Samuel Oyeniyi 2016.10.07 20:08  

My broker allows hedging , but despite looping through the orders to select by index I still get error 10036 " OnTick: Position does not exist".  Am I missing something please in my code? 

 

2016.10.07 12:04:47.654 Zetha1.4Test (AUDUSD,M5) 10036  -error 

 

2016.10.07 12:04:47.654 Zetha1.4Test (AUDUSD,M5) OnTick:Position doesn't exist

 

      for ( int i = 0; i < total; i++ ){
       if ( PositionSelect( PositionGetSymbol( i ))){
            if ( PositionGetSymbol( i ) == Symbol() ) {
        // continue;
   
      // Send MQL MqlTradeRequest to modify the SL, which gives position closed error
      string symb =PositionGetSymbol( i );
      
               
 
         if (((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) &&  (myPosition.StopLoss()==0) ){ 
         
           //--- preparing a request
            MqlTradeRequest request;
            ZeroMemory(request);
            ZeroMemory(mresult);
            ZeroMemory(mcheck);            
            //--- placing an immediate order
            mrequest.action=TRADE_ACTION_SLTP;
            //--- instrument
            mrequest.symbol=symb;
            //--- Stop Loss 
            mrequest.sl=NormalizeDouble(myPosition.PriceOpen()+getBullPrice(symb),_Digits);
            
            //--- Take Profit is not specified
          mrequest.tp=NormalizeDouble(myPosition.PriceOpen() - getBearPrice(symb),_Digits);//}
          
           // MqlTradeResult result;
           // ZeroMemory(result);
            MqlTradeCheckResult CheckResult;
            //--- sending the order
            if(OrderCheck(mrequest,CheckResult)) {OrderSend(mrequest,mresult);}
            else
              {
               //--- printing the server response to the log  
               Print(CheckResult.retcode,"  -error ");
               Print(mrequest.sl,"  ","  <sell sl "," Bprice =",Bprice ," Sprice =",Sprice  );
               Print(__FUNCTION__,":",CheckResult.comment);
              }
        }
      }
     }
    }  
        
   
Alain Verleyen
Moderator
30183
Alain Verleyen 2016.10.08 00:17  

Forum on trading, automated trading systems and testing trading strategies

Closing a position

Alain Verleyen, 2016.04.15 08:07

When modifying or closing a position in the hedging system, make sure to specify its ticket (MqlTradeRequest::ticket). You can specify a ticket in the netting system as well, however positions are identified by a symbol name.

/ /12
To add comments, please log in or register