Problem with total amount of open orders - page 5

 

You need to re-think your code.

buy_hedge==0 && sell_hedge==0 && OrderOpenPrice()>Bid+Hedge*Pip)

These will always be true as you set them both to zero and don't change them. You don't enclose the following block of code in curly braces {}

You don't use the GV to check anything and you name it with an integer. The check does nothing as you don't assign the returned bool to any variable.

Check whether the OrderSend fails, and if it does, print the error code.

 
GumRai:

You need to re-think your code.

These will always be true as you set them both to zero and don't change them. You don't enclose the following block of code in curly braces {}

You don't use the GV to check anything and you name it with an integer. The check does nothing as you don't assign the returned bool to any variable.

Check whether the OrderSend fails, and if it does, print the error code.

Thank you.  I think I am on the right track, but now it will open multiple hedge trades even though it states total<=1.  My code now looks like this:

if(total<=1 && OrderOpenPrice()>Bid+Hedge*Pip){
               GlobalVariableCheck(ticket);
               sell_hedge=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,Bid+StopLossHedge*Pip,0,"Hedge",0,0,Blue);
               sell_hedge=GlobalVariableGet(ticket);
               sell_hedge=sell_hedge+1;
               GlobalVariableSet(ticket,sell_hedge);
               int New_SellHedge=GlobalVariableGet(ticket);
               if(sell_hedge!=New_SellHedge) {sell_hedge=New_SellHedge;}
              }
            }
 

Thank you for this advice.  I finally figured it out and it now works.  The bit of code looks like this:

if(GlobalVariableCheck("InTrade")){
      }
      else if(OrderOpenPrice()>Bid+Hedge*point){
         sell_ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,Bid+StopLossHedge*point,0,"Hedge",magic,0,Blue);{
         GlobalVariableSet("InTrade",1);
         GlobalVariableDel("InTrade");
         return(0);
        }
     }
   }
 
         GlobalVariableSet("InTrade",1);
         GlobalVariableDel("InTrade");

What is the point of setting the GV then immediately deleting it?

 
GumRai:

What is the point of setting the GV then immediately deleting it?

Makes sense thank you.  So is it better like this:

if(GlobalVariableCheck("InTrade")){
  }
   else if(OrderOpenPrice()>Bid+Hedge*Pip){
      sell_ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,Bid+StopLossHedge*Pip,0,"Hedge",magic,0,Blue);{
         GlobalVariableSet("InTrade",1);
         return(0);
        }
      }
    }
GlobalVariableDel("InTrade");
 
Trader3000:

Makes sense thank you.  So is it better like this:

 

No, it still makes no sense at all.

There should be a reason to delete the GV

 
GumRai:

No, it still makes no sense at all.

There should be a reason to delete the GV

Thank you again.  How about this?

int total=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
      if(OrderSelect(i,SELECT_BY_POS) && OrderMagicNumber()==0 && OrderSymbol()==
         total++;
        }
if(GlobalVariableCheck("InTrade")){
  }
   else if(total==1 && OrderOpenPrice()>Bid+Hedge*Pip){
      sell_ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,Bid+StopLossHedge*Pip,0,"Hedge",magic,0,Blue);{
         GlobalVariableSet("InTrade",1);
            if(total<1) GlobalVariableDel("InTrade");
            return(0);
           }
         }
       }
 
Trader3000:

Thank you again.  How about this?

 

It still doesn't make sense

   else if(total==1 && OrderOpenPrice()>Bid+Hedge*Pip){
      sell_ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,Bid+StopLossHedge*Pip,0,"Hedge",magic,0,Blue);{
         GlobalVariableSet("InTrade",1);
            if(total<1) GlobalVariableDel("InTrade");
            return(0);
           }
         }

The code block is only executed if total==1, so the check if(total<1) will always be false.

Reason: