Need help to open order maximum 4 time with 4 condition per H1 Candle

 

Hi ,

I need help , badly stuck in maximum order stuff. Crawled a lot on web but didnt find the solution.
The thing is , My code have 2 condition with M5 & M15 , both should open buy/sell or both at a time.

So M5 buy/sell  , M15  buy/sell  : Total orders is 4 per H1 candle

If i select order with magic number & add below code , then I will get only 1 order per candle instead of max 4 orders.


datetime LastBarTraded = 0;


void OnTick()

{
 
if(M5 Condition)  // M5 Buy condition   
  {
     if (LastBarTraded != Time[0])
        {
        OrderSend()
        LastBarTraded = Time[0]
        }
  }



 if(M5 Condition)  // M5 Sell condition   
  {
     if (LastBarTraded != Time[0])
        {
         OrderSend()
         LastBarTraded = Time[0]
        }
  }



 if(M15 Condition)  // M15 Buy condition   
  {
     if (LastBarTraded != Time[0])
        {
         OrderSend()
         LastBarTraded = Time[0]
        }
  }



 if(M15 Condition)  // M15 Sell condition   
  {
     if (LastBarTraded != Time[0])
        {
         OrderSend()
         LastBarTraded = Time[0]
        }
  }
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
  1. You are trying to differentiate M5 from M15 orders. You need two Magic number for that.
  2. Count the number of orders (per TF) before opening.
 

Hi,

what do you think about a simple counter, which will be reseted every new hour:

int HourCount = 0;

...

void OnTick()
{
        datetime ServerTime = (datetime) MarketInfo(Symbol(), MODE_TIME);
        if ((TimeMinute(ServerTime) == 0) && (TimeSeconds(ServerTime) == 0)) HourCount = 0;

...

        if (HourCount < 4)
        {
                OrderSend();
                HourCount++;
        }

Best regards

 
William Roeder:
  1. You are trying to differentiate M5 from M15 orders. You need two Magic number for that.
  2. Count the number of orders (per TF) before opening.

Using seprate Magic number for each condition.

Counting order number seprately with bool.