In the tester, I am getting an "Error Code 0 internal error" on BUY side orders ONLY and not sell side orders.
2 questions:
1. What is an "internal error" tied to Error code 0 which I thought was no error?
2. Why am I getting this error only on buy side orders?
The specific result printed is: "Error During Modifying Stop and TP of Buy Order !!! Error code: 0 internal error"
which corresponds to the first modification. As far as I can tell the buy side code is correct.
Here is the code used for the function below...the code may seem to have redundancy, however it is designed to make sure hard stops and hard tps are sent and posted after the order has been filled for ecn / stp type brokers.
Code Reposted Outside of FF Code Box:
*******************************
void set_stop_tp()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
if(!OrderSelect(i, SELECT_BY_POS)) {
Print(TimeToStr(TimeCurrent(),TIME_SECONDS), " CHECK Function > ", __FUNCTION__," !!!!! ", " Error code = ", GetLastError()); }
int result;
int check;
{
// Modify Stop and TP on Server if not during Order Entry
if (((OrderStopLoss() == 0) || (OrderTakeProfit() == 0)) && (OrdersTotal() > 0) && (UseHardStop == true)) { RefreshRates();
// Modify both SL and TP if both not set yet
if ((OrderType() == OP_BUY) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() == 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-HardStop,OrderOpenPrice()+HardTP,0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying Stop and TP of Buy Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
if ((OrderType() == OP_SELL) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() == 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+HardStop,OrderOpenPrice()-HardTP,0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying Stop and TP of Sell Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
// Modify TP only if not set yet
if ((OrderType() == OP_BUY) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() != 0) && (OrderTakeProfit() == 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+HardTP,0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying TP of Buy Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
if ((OrderType() == OP_SELL) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() != 0) && (OrderTakeProfit() == 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-HardTP,0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying TP of Sell Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
// Modify SL only if not set yet
if ((OrderType() == OP_BUY) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() != 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-HardStop,OrderTakeProfit(),0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying Stop of Buy Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
if ((OrderType() == OP_SELL) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() != 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+HardStop,OrderTakeProfit(),0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying Stop of Sell Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
}
2 questions:
1. What is an "internal error" tied to Error code 0 which I thought was no error?
2. Why am I getting this error only on buy side orders?
The specific result printed is: "Error During Modifying Stop and TP of Buy Order !!! Error code: 0 internal error"
which corresponds to the first modification. As far as I can tell the buy side code is correct.
Here is the code used for the function below...the code may seem to have redundancy, however it is designed to make sure hard stops and hard tps are sent and posted after the order has been filled for ecn / stp type brokers.
Inserted Code
void set_stop_tp() { int totalorders = OrdersTotal(); for(int i=totalorders-1;i>=0;i--) { if(!OrderSelect(i, SELECT_BY_POS)) { Print(TimeToStr(TimeCurrent(),TIME_SECONDS), " CHECK Function > ", __FUNCTION__," !!!!! ", " Error code = ", GetLastError()); } int result; int check; { // Modify Stop and TP on Server if not during Order Entry if (((OrderStopLoss() == 0) || (OrderTakeProfit() == 0)) && (OrdersTotal() > 0) && (UseHardStop == true)) { RefreshRates(); // Modify both SL and TP if both not set yet if ((OrderType() == OP_BUY) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() == 0))) result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-HardStop,OrderOpenPrice()+HardTP,0,0); check = GetLastError(); if(check != 0) { Print("Error During Modifying Stop and TP of Buy Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); } if ((OrderType() == OP_SELL) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() == 0))) result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+HardStop,OrderOpenPrice()-HardTP,0,0); check = GetLastError(); if(check != 0) { Print("Error During Modifying Stop and TP of Sell Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); } // Modify TP only if not set yet if ((OrderType() == OP_BUY) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() != 0) && (OrderTakeProfit() == 0))) result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+HardTP,0,0); check = GetLastError(); if(check != 0) { Print("Error During Modifying TP of Buy Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); } if ((OrderType() == OP_SELL) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() != 0) && (OrderTakeProfit() == 0))) result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-HardTP,0,0); check = GetLastError(); if(check != 0) { Print("Error During Modifying TP of Sell Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); } // Modify SL only if not set yet if ((OrderType() == OP_BUY) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() != 0))) result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-HardStop,OrderTakeProfit(),0,0); check = GetLastError(); if(check != 0) { Print("Error During Modifying Stop of Buy Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); } if ((OrderType() == OP_SELL) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() != 0))) result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+HardStop,OrderTakeProfit(),0,0); check = GetLastError(); if(check != 0) { Print("Error During Modifying Stop of Sell Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); } }
Code Reposted Outside of FF Code Box:
*******************************
void set_stop_tp()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
if(!OrderSelect(i, SELECT_BY_POS)) {
Print(TimeToStr(TimeCurrent(),TIME_SECONDS), " CHECK Function > ", __FUNCTION__," !!!!! ", " Error code = ", GetLastError()); }
int result;
int check;
{
// Modify Stop and TP on Server if not during Order Entry
if (((OrderStopLoss() == 0) || (OrderTakeProfit() == 0)) && (OrdersTotal() > 0) && (UseHardStop == true)) { RefreshRates();
// Modify both SL and TP if both not set yet
if ((OrderType() == OP_BUY) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() == 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-HardStop,OrderOpenPrice()+HardTP,0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying Stop and TP of Buy Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
if ((OrderType() == OP_SELL) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() == 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+HardStop,OrderOpenPrice()-HardTP,0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying Stop and TP of Sell Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
// Modify TP only if not set yet
if ((OrderType() == OP_BUY) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() != 0) && (OrderTakeProfit() == 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+HardTP,0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying TP of Buy Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
if ((OrderType() == OP_SELL) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() != 0) && (OrderTakeProfit() == 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-HardTP,0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying TP of Sell Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
// Modify SL only if not set yet
if ((OrderType() == OP_BUY) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() != 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-HardStop,OrderTakeProfit(),0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying Stop of Buy Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
if ((OrderType() == OP_SELL) && (OrdersTotal() > 0) && (OrderSymbol() == Trade) && ((OrderStopLoss() == 0) && (OrderTakeProfit() != 0)))
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+HardStop,OrderTakeProfit(),0,0);
check = GetLastError();
if(check != 0) { Print("Error During Modifying Stop of Sell Order !!! Error code: ", GetLastError(), " ", ErrorDescription(check)); }
}