EA open position per tick

 

Hi everyone,

I've created EA that using ichimoku indi as a condition to open order. In the EA I've created 2 magic number to open a STRONG or WEAK open position. The problem of this EA is when the indicator indicates there's a WEAK open position and start to open position every tick like the ss I've attached. Here's my code for the WEAK open position.

   if(IsNewCandle())
     {
      if(!CheckIfOpenOrdersByMagicNumber(magicNumberWeak)) //check if there's open position with specific magic number
        {
         if(FuncOpenPosition() == 3)
           {
            double stopLossPrice    = NormalizeDouble((Bid + spread) - (stoploss*Point()),Digits);
            double takeProfitPrice  = NormalizeDouble((Bid + spread) + takeProfitWeakPosition*Point(),Digits);
            double lotSize          = NormalizeDouble(OptimalLotSize(riskPerTrade,Ask,stopLossPrice)/lotType,2);
            orderId                 = OrderSend(Symbol(),OP_BUY,lotSize,Ask,0,stopLossPrice,takeProfitPrice,"Weak BUY",magicNumberStrong);
           }
         if(FuncOpenPosition() == 4)
           {
            double stopLossPrice    = NormalizeDouble((Bid + stoploss*Point()),Digits);
            double takeProfitPrice  = NormalizeDouble(Bid - takeProfitWeakPosition*Point(),Digits);
            double lotSize          = NormalizeDouble(OptimalLotSize(riskPerTrade,Bid,stopLossPrice)/lotType,2);
            orderId                 = OrderSend(Symbol(),OP_SELL,lotSize,Bid,0,stopLossPrice,takeProfitPrice,"Weak SELL",magicNumberStrong);
           }
        }
     }

I've already using a function that will run every new candle but it seems doesn't work. My code for IsNewCandle func is like this.

static datetime NewCandleTime=TimeCurrent();
bool IsNewCandle(){
   if(NewCandleTime==iTime(Symbol(),0,0)) return false;
   else{
      NewCandleTime=iTime(Symbol(),0,0);
      return true;
   }
}

I've tried many times to fix this issue and still doesn't know what cause it to happened like this. Hopefully you guys can help me to tell me where the error is.

Thank you

Files:
Capture.JPG  43 kb
 
Luandre Ezra: I've tried many times to fix this issue and still doesn't know what cause it to happened like this.

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          New candle - MQL4 programming forum #3 2014.04.04

I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum 2011.05.06

 
William RoederNew candle - MQL4 programming forum #3 2014.04.04

already did like what you suggest but the result is the same. Does mt4 cannot process more than one open position condition?

 
Show all of the relevant code.
 
lippmaje:
Show all of the relevant code.
if(IsNewCandle())
     {
      if(!CheckIfOpenOrdersByMagicNumber(magicNumberWeak)) //check if there's open position with specific magic number
        {
         if(FuncOpenPosition() == 3)
           {
            double stopLossPrice    = NormalizeDouble((Bid + spread) - (stoploss*Point()),Digits);
            double takeProfitPrice  = NormalizeDouble((Bid + spread) + takeProfitWeakPosition*Point(),Digits);
            double lotSize          = NormalizeDouble(OptimalLotSize(riskPerTrade,Ask,stopLossPrice)/lotType,2);
            orderId                 = OrderSend(Symbol(),OP_BUY,lotSize,Ask,0,stopLossPrice,takeProfitPrice,"Weak BUY",magicNumberStrong);
           }
         if(FuncOpenPosition() == 4)
           {
            double stopLossPrice    = NormalizeDouble((Bid + stoploss*Point()),Digits);
            double takeProfitPrice  = NormalizeDouble(Bid - takeProfitWeakPosition*Point(),Digits);
            double lotSize          = NormalizeDouble(OptimalLotSize(riskPerTrade,Bid,stopLossPrice)/lotType,2);
            orderId                 = OrderSend(Symbol(),OP_SELL,lotSize,Bid,0,stopLossPrice,takeProfitPrice,"Weak SELL",magicNumberStrong);
           }
        }
     }

this all the relevant code. This is the only code that repeating open position

 
Luandre Ezra:

this all the relevant code

No, obviously not. There's no point in repeating what's already been posted. Where's your code, OnTick etc?
 
Sorry guys I made a stupid mistake. The problem is that I select the previous EA version that doesn't have a condition to open only once per candle. I already select the right one and it works like I want.
 
ok
Reason: