Problem with total amount of open orders

Back to topics list  | 1 2 3 4 5 To post a new topic, please log in or register
avatar
Moderator
3427
GumRai 2016.05.17 15:36 #
 

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.

avatar
74
Trader3000 2016.05.18 12:27 #
 
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;}
              }
            }

 

avatar
74
Trader3000 2016.05.19 18:10 #
 

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);
        }
     }
   }

 

avatar
Moderator
3427
GumRai 2016.05.19 23:52 #
 
         GlobalVariableSet("InTrade",1);
         GlobalVariableDel("InTrade");

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

avatar
74
Trader3000 2016.05.20 13:57 #
 
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");

 

avatar
Moderator
3427
GumRai 2016.05.20 14:14 #
 
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

avatar
74
Trader3000 2016.05.24 10:53 #
 
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);
           }
         }
       }

 

avatar
Moderator
3427
GumRai 2016.05.24 12:47 #
 
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.

Back to topics list   | 1 2 3 4 5  

To add comments, please log in or register