Order execution problem

 

Hello, I am looking for the best way to execute a pyramiding strategy using pending orders as stops.  Should I use Mqltraderequest or the Trade.mqh classes?  Also, I have experimented with both and each have given me problems (even when using a set price as a Stop Loss, not a separate pending stop order) in particular this error message:

 

 2011.09.24 14:33:13 Core 2 2011.05.02 03:36:23   not enough money [instant buy 0.07 EURUSD at 1.48165 sl: 1.41449]

 

The following are the values for the variables for Lots, Ask,  BuyStopLoss etc.:

2011.09.24 14:33:13 Core 2 2011.05.02 03:36:23   BuyStopLoss 1.41449

 2011.09.24 14:33:13 Core 2 2011.05.02 03:36:23   Ask 1.48165

2011.09.24 14:33:13 Core 2 2011.05.02 03:36:23   Lots 0.07

This is my code:

 

 

  if (New_Orders==true)

   {

   MqlTick last_tick;

   SymbolInfoTick(_Symbol,last_tick);

   MqlTradeResult result;

   MqlTradeRequest request;


      

   request.symbol=_Symbol;

   request.magic=RRBuy;

   request.deviation=50;

   request.action=TRADE_ACTION_DEAL;

   request.type_filling=ORDER_FILLING_AON;

   if (price.Close(0)>highest)

   {

    if(AcceptLongOrders==true)

     {

    


   

     if (Point==0.00001)   

     StopLoss=(Ask-BuyStopLoss)*100000;     

     

Lots=NormalizeDouble((AccountInfoDouble(ACCOUNT_BALANCE)*(RiskPct/100)/StopLoss/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)), 2);



    double lot=Lots;

  

      request.volume=Lots;

      request.price=last_tick.ask;

      request.type=ORDER_TYPE_BUY;

      request.sl=BuyStopLoss;

      


      OrderSend(request,result);

      CopyTime(_Symbol,PERIOD_D1,0,1,Told);

   

 

Do you have any suggestions?  I have monkeyed around and tried everything.  Thanks   

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
 
andrew.potter77:    

Lots=NormalizeDouble((AccountInfoDouble(ACCOUNT_BALANCE)*(RiskPct/100)/StopLoss/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)), 2);

 

Do you have any suggestions?  I have monkeyed around and tried everything.  Thanks   

Probably its better to use ACCOUNT_FREEMARGIN or ACCOUNT_EQUITY.

And send it to OrderCheck() first to make sure all parameters are ok.

 
fireflies:

Probably its better to use ACCOUNT_FREEMARGIN or ACCOUNT_EQUITY.

And send it to OrderCheck() first to make sure all parameters are ok.

account_equity doesn't seem to have helped.  Here is the error output:

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   rtcode 23443

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   balance 100000

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   equity $g

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   profit 0

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   margin 164148

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   margin free -118495

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   margin level 27.8121

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   Error comment No money

 
andrew.potter77:

account_equity doesn't seem to have helped.  Here is the error output:


2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   margin free -118495

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   margin level 27.8121

2011.09.28 16:30:49 Core 2 2011.05.02 03:29:39   Error comment No money

If free margin is already below zero (margin level less than 100%) I don't think we can send pending orders.