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); } } }
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
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())
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
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
Hi Rashid,
In my case the account supports hedging, and I can see the position in 'Trade' tab. My code is as follows:
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); } } } } }
Forum on trading, automated trading systems and testing trading strategies
Alain Verleyen, 2016.04.15 08:07
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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 .