Number Of Orders Expression Help maybe OrdersHistoryTotal ?

 
Hi gurus

I'm trying to design code that would limit the number of trades per (time frame)
I am confident with my knowledge of making time codes thanks to the gurus in the forums etc.

I'm considering making some code and OrdersHistoryTotal to accomplish this.
Am I headed in the right direction ?

Thanks
 
datetime lastCloseTime;
    for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)  // Only orders w/
    &&  OrderMagicNumber()  == Magic.Number             // my magic number
    &&  OrderSymbol()       == chart.symbol             // and my pair.
    &&  OrderType()         <= OP_SELL//Avoid cr/bal forum.mql4.com/32363#325360
    ){  
        datetime oct = OrderCloseTime()
        if (lastCloseTime < oct) lastCloseTime = oct;
    }
datetime now = TimeCurrent();  #define HR2 7200 // 2 hours
if (now < lastCloseTime + HR2) return; // must wait 2 hours before next trade.
 
Agent86:
Hi gurus

I'm trying to design code that would limit the number of trades per (time frame)

I'm not clear on what you mean . . . . but if you mean that you want to trade the same symbol on different timeframes then you will need to employ a magic number. I generate my Magic Number automatically based on the EA Number and timeframe.

Edit: I don't use Symbol any longer as part of my Magic Number.

 
Since you can filter by magic number and symbol, you need to be able to filter by timeframe. I just use a range of magic numbers.
extern int      Magic.Number.Base               = 20111213;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int     magic.number;                           // Export to ModifyStops
string  tf.text,                                // Export to NewBar
int     init(){
   :
    {//++++ Adjust for the current chart timeframe
    int     TFperiod[]  = { PERIOD_M1,  PERIOD_M5,  PERIOD_M15, PERIOD_M30,
                            PERIOD_H1,  PERIOD_H4,  PERIOD_D1,  PERIOD_W1,
                            PERIOD_MN1  };
    string  TFtext[]    = { "M1",       "M5",       "M15",      "M30",
                            "H1",       "H4",       "D1",       "W1",
                            "MN1"       };
    for(int iTF=0; TFperiod[iTF] < Period(); iTF++){}
    tf.text         = TFtext[iTF];
    magic.number    = Magic.Number.Base + iTF;
    }//---- Adjust for the current chart timeframe
   :
}
 
WHRoeder:


Ahhh really cool, I get it, I could do a bunch of stuff with that.
OrderHistoryTotal, then OrderSelect and I can create an if(blahblahblah..&& between my time range && OrderType..) {duplicatetradenotallow....code} or something similar
for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)  // Only orders w/
    &&  OrderMagicNumber()  == Magic.Number             // my magic number
    &&  OrderSymbol()       == chart.symbol             // and my pair.
    &&  OrderType()         <= OP_SELL//Avoid cr/bal forum.mql4.com/32363#325360
    ){  


I think I was making it more complicated probably because I didn't consider OrderSelect (....,MODE_HISTORY)

Thanks people, I'll keep reading

 
RaptorUK:

I'm not clear on what you mean . . . . but if you mean that you want to trade the same symbol on different timeframes then you will need to employ a magic number. I generate my Magic Number automatically based on the EA Number and timeframe.

Edit: I don't use Symbol any longer as part of my Magic Number.


After reading my post I don't think worded the question very good sorry.

But I think I understand it now, thanks
 
WHRoeder:
Since you can filter by magic number and symbol, you need to be able to filter by timeframe. I just use a range of magic numbers.

OH GREAT, arrays of time frames and magic.numbers

Well I'll have to chew on this for while to understand it, arrays make my head spin cause I'm not fluent with them yet but.
But I'll enjoy learning it.

Sincere thanks
 
You don't need an array of TF & MN. Each EA is running on one chart, one pair, one TF. It only needs one unique MN/symbol/TF combination.
 
WHRoeder:
You don't need an array of TF & MN. Each EA is running on one chart, one pair, one TF. It only needs one unique MN/symbol/TF combination.
I see, thanks again