Download MetaTrader 5

the code don't execute the buy order

To add comments, please log in or register
Move from theory to practice. Code Base will help you!
saklas
22
saklas 2013.11.27 09:27 

Hi! I have a problem with the following code. First part of the if BuySignal == true && SellMarketCount(Symbol(),MagicNumber) == 0) runs great, but when i check ForceBuy to true the script don't place the order. Can anyone help me with that? Thx

         if((BuySignal == true && SellMarketCount(Symbol(),MagicNumber) == 0) || ForceBuy == true)
           {
            BuySignal = false;
            Current_TP = TakeProfit;
            Current_SL = StopLoss;
            if(DynamicLotSize == true)
              {
               double LotSizeMult =  AccountBalance()/10000;
               LotSize = LotSizeMult/MaxPair;
               LotSizeMethod="Dynamic";
              }
            if(DynamicLotSize2 == true)
               {
               LotSize = Profit/Pips/10;
               LotSizeMethod="Dynamic2";
               } 
            if(DynamicLotSize == false && DynamicLotSize2 == false)
               {LotSize=FixedLotSize;LotSizeMethod="Fixed";}  
            LotSize = VerifyLotSize(LotSize);
            if(Show_Alerts == true)
              {
               Alert("Attempting to buy ",LotSize," of ",Symbol());// Added by ck
               Print("Attempting to buy ",LotSize," of ",Symbol());// Added by ck
              } 
            BuyTicket = OpenBuyOrder(Symbol(),LotSize,UseSlippage,MagicNumber,"Renko2");
            if((BuyTicket > 0)  && ((Current_TP > 0) || (Current_SL > 0)))
              { 
               OrderSelect(BuyTicket,SELECT_BY_TICKET);
               double OpenPrice = OrderOpenPrice();
               double BuyStopLoss = CalcBuyStopLoss(Symbol(),Current_SL,OpenPrice);
               if(BuyStopLoss > 0)
                 {
                  BuyStopLoss = AdjustBelowStopLevel(Symbol(),BuyStopLoss,5);
                 }
               double BuyTakeProfit = CalcBuyTakeProfit(Symbol(),Current_TP,OpenPrice);
               if(BuyTakeProfit > 0)
                 { 
                  BuyTakeProfit = AdjustAboveStopLevel(Symbol(),BuyTakeProfit,5);
                 }
               AddStopProfit(BuyTicket,BuyStopLoss,BuyTakeProfit);
              }    
           }
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.11.27 09:32  
saklas:

Hi! I have a problem with the following code. First part of the if BuySignal == true && SellMarketCount(Symbol(),MagicNumber) == 0) runs great, but when i check ForceBuy to true the script don't place the order. Can anyone help me with that? Thx

Are you checking the return values from your Trading functions and reporting any errors when they fail ? what errors do you get ?

What are Function return values ? How do I use them ?

saklas
22
saklas 2013.11.27 09:38  
I don't get any error. The ea ignore the variable bool ForceBuy. The ea works great if BuySignal==true and SellMarketCount(Symbol(),MagicNumber) == 0
whroeder1
14519
whroeder1 2013.11.27 13:34  
saklas: I don't get any error.
How do you know that if you DON'T CHECK?
To add comments, please log in or register