OrderTotal Help ? - page 3

 
themasterx7:

sorry for the late replay, I thought I answered you I don't know what you mean maybe you mean this :

like  remcous told me, I have two variables in this case I have three Global values :

so I think that what you mean is my variable code is If(Buy_trade or Sell_Trade >0 ||<0) and they get its value from the global but do I need to assign a value of my global variable inside my code because it doesn't work . If I didn't answer you give me an Example of a variable code and its value.

How can you not know what I mean? It's in your code!

          if(CODE)
        {         
         closeticket=OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
        }
   if(OrdersTotal()<x) 
   if(CODE)
   {
   ticket= OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0,0,NULL,0,0,Red);
   
   }
   if(OrderType()==OP_BUY &&OrderSymbol()==Symbol())
   if(CODE)
   {
   closeticket=OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
   }
  if(CODE)
   {
   ticket= OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,0,0,NULL,0,0,Red);
   }
 

you mean this I thought its not relevant here it is :

//+------------------------------------------------------------------+
//|                                                       febo01.mq4 |
//|                                                    helmy gabriel |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "helmy gabriel"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


double lotSize=0.01;
int ticket;
int closeticket;
int select;
int i;
int MagicNumber=1234;
int Buy_trade=0;
int Sell_trade=0;


input int trendMa =50;
input int trendMaShift = 0;
input int trendMaMode = MODE_SMA;
input int trendMaPrice = PRICE_CLOSE;
int x =2;// how many trades


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
    //////////////////////////////////////////////////////////////////////////////// trend ma
    double trendMaV1 = iMA(NULL,0,trendMa,trendMaShift,trendMaMode,trendMaPrice,1);
    double trendMaV2 = iMA(NULL,0,trendMa,trendMaShift,trendMaMode,trendMaPrice,2);

   ///////////////////////////////////////////////////////////////////Object
    int highC = iHighest(_Symbol,_Period,MODE_HIGH,100,0);
    int lowC = iLowest(_Symbol,_Period,MODE_LOW,100,0);//Hline
    ObjectDelete("HH");
    ObjectCreate(0,"HH",OBJ_FIBO,0,Time[0],High[highC],Time[100],Low[lowC]);

    /////levels   
    double level100=ObjectGetDouble(0,"HH",OBJPROP_PRICE,0);  
    double level0=ObjectGetDouble(0,"HH",OBJPROP_PRICE,1);
    double Q=MathAbs(level100-level0);
    double level50=((level100+level0)/2);
    double levelAbove0 = (level0+(Q*0.236));//above zero 23.6
    double level_618 =(level0+(Q*0.618));// 61.8
    double level_382 = (level0+(Q*0.382));//38.2
    double levelBelow100 =(level100-(Q*0.236));//below 100 (23.6)
    
    Comment(level_618);
    double levelAbove100=(level100 +(Q*0.618));//161.8% stoplose for sell
    double levelBelow0 = (level0 - (Q*0.618));//stoplose for buy 
    if(OrdersTotal()<x)
    { 
    
    if(Sell_trade>0)             ///////////////////////////////////////////////////SELL
    {
  
  for(i=0;i<OrdersTotal();i++)
      { 
         select= OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      
          if(OrderType()==OP_SELL &&OrderSymbol()==Symbol())
          if(Close[1]<=level0||Close[1]>=level100)
        {        
         closeticket=OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
        }
   
     }
    }
    else
    {
    //if(OrdersTotal()<x) 
   if(Close[1]<trendMaV1&&Close[1]<level50&&Close[2]>level50&&Close[1]>level_382)
   {
   ticket= OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0,0,NULL,0,0,Red);
   
   }
   }
   if(Buy_trade>0)                   /////////////////////BUY
    {
    for(i=0;i<OrdersTotal();i++)
      { 
      select= OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      
   if(OrderType()==OP_BUY &&OrderSymbol()==Symbol())
   if(Close[1]>=level100||Close[1]<=level0)
   {
   closeticket=OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
   }
    }
       
  }
  else
  {
  if(Close[1]>trendMaV1&&Close[1]>level50&&Close[2]<level50&&Close[1]<level_618)
   {
   ticket= OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,0,0,NULL,0,0,Red);
   }
  }
  
 } 
    } 






    //this FNC outside my code its a secondary project maybe I'll use it here
    int CountTrades()
  {
   int count=0;
   for(int trade=OrdersTotal()-1; trade>=0; trade--)
     {
      if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
         Print("Error");
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber)
         continue;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
         if(OrderType()==OP_SELL || OrderType()==OP_BUY)
            count++;
     }
   return (count);
  }
 

hi

so you know why it doesn't work ?

 
themasterx7:

hi

so you know why it doesn't work ?

Hello,

What doesn't work ? Have you try to debug step by step ? Have you used my sample function to get buy/sell trade opened ?

 
remcous:

Hello,

What doesn't work ? Have you try to debug step by step ? Have you used my sample function to get buy/sell trade opened ?

yea I used Comment("") command to debug but something is missing I need to do more I'll try to debug it again.

you see anything missing ? I assigned A value of the global variable Sell and Buy_Trade in my orignal code   

 
remcous:

Hello,

What doesn't work ? Have you try to debug step by step ? Have you used my sample function to get buy/sell trade opened ?

I didn't use the function but I used the Sell_trade and Buy_trade global variable I like this better its simpler but I couldn't get it to work. 

 
themasterx7:

I didn't use the function but I used the Sell_trade and Buy_trade global variable I like this better its simpler but I couldn't get it to work. 

Where do you reset global variables to 0 when you close orders ?

Global variables are great, but imagine MT4 crash or close, you reopen it and you have 2 orders already open, how do you handle this ?

ps : by debug i don't wanna say "comment" function, but run code step by step... with a view on variables.
 
remcous:

Where do you reset global variables to 0 when you close orders ?

Global variables are great, but imagine MT4 crash or close, you reopen it and you have 2 orders already open, how do you handle this ?

ps : by debug i don't wanna say "comment" function, but run code step by step... with a view on variables.

OK I'll try to use the function , I did reset the global variables but in my original code same issue.

Imma gonna try now the function and get back to you.

 
remcous:

Where do you reset global variables to 0 when you close orders ?

Global variables are great, but imagine MT4 crash or close, you reopen it and you have 2 orders already open, how do you handle this ?

ps : by debug i don't wanna say "comment" function, but run code step by step... with a view on variables.

HI, Thanks brother the function worked, I've learned a lot from our discussion, Thanks to all .

I will open a discussion about multiple time frames soon hope you share your thoughts and everybody will learn from it.

Be Safe     

Reason: