Sell and Buy Limit orders are giving 'Invalid Price' error

 

Hi this is the code I have for opening a SellLimit order

         double sl_distance = NormalizeDouble(m_latest_atr * atr_multiplier_sl, _Digits);
         double lot_size = determine_lot_size(sl_distance);
         
         double price = NormalizeDouble(latest_candle.low-150*_Point, _Digits);
         double sl_value = price + sl_distance;
         double tp_value = price - NormalizeDouble(m_latest_atr * atr_multiplier_tp, _Digits);
         
         Print("LATEST CANDLE LOW PRICE IS:    $", price,  "\n",
               "SL VALUE SET TO:               $", sl_value, "\n");
         
         // Check if we even have any money left to trade with...
         if(m_account.FreeMarginCheck(_Symbol, ORDER_TYPE_SELL_LIMIT, lot_size, price) < 0.0) {
            printf("We have no money. Free Margin = %f",m_account.FreeMargin());
         }
         else {
            if (m_trade.SellLimit(lot_size, price, _Symbol, sl_value, tp_value, ORDER_TIME_GTC, 0, NULL)) {
               printf("Position by %s to be opened", _Symbol);
            }
            else {
               printf("Error opening SELL position by %s: '%s'", _Symbol, m_trade.ResultComment());
               printf("Open parameters: price=%f, SL=%f", price, sl_value);
            }
         }


But this is what I get in the Journal

2020.03.13 13:41:18.997    Core 01    2015.01.01 22:05:00   failed sell limit 0.01 AUDCAD at 0.94420 sl: 0.95483 tp: 0.91940 [Invalid price]
2020.03.13 13:41:18.997    Core 01    2015.01.01 22:05:00   CTrade::OrderSend: sell limit 0.01 AUDCAD at 0.94420 sl: 0.95483 tp: 0.91940 [invalid price]
2020.03.13 13:41:18.997    Core 01    2015.01.01 22:05:00   Error opening SELL position by AUDCAD: 'Invalid price'
2020.03.13 13:41:18.997    Core 01    2015.01.01 22:05:00   Open parameters: price=0.944200, SL=0.954830

I've made sure that the price is actually below the current price but for the life of me I can't figure out why this error is coming up.

The only thing I can see is that if you look at the last line "Open parameters: price=0.944200, SL=0.954830" it seems like it's adding an additional zero to the price. If that's the reason, why is it adding an extra zero and how do I get this to work?

Thanks in advance.

 
haseeb_90 :


If it’s a mistake, print at least three parameters: Ask price, Bid price, and freeze level.

 
Vladimir Karputov:

If it’s a mistake, print at least three parameters: Ask price, Bid price, and freeze level.

Thank you fo taking the time to reply,

I'm not sure what you mean, can you please explain?


Thanks.

 
Vladimir Karputov:

If it’s a mistake, print at least three parameters: Ask price, Bid price, and freeze level.

Okay, so I modified the error to print out the FREEZE_LEVEL also.  This is the Journal output that I get

2020.03.13 14:56:27.696    Core 01    2015.01.01 22:05:00   failed sell limit 0.01 AUDCAD at 0.94420 sl: 0.95483 tp: 0.91940 [Invalid price]
2020.03.13 14:56:27.696    Core 01    2015.01.01 22:05:00   CTrade::OrderSend: sell limit 0.01 AUDCAD at 0.94420 sl: 0.95483 tp: 0.91940 [invalid price]
2020.03.13 14:56:27.696    Core 01    2015.01.01 22:05:00   Error opening SELL position by AUDCAD: 'Invalid price'
2020.03.13 14:56:27.696    Core 01    2015.01.01 22:05:00   Open parameters: price=0.944200, SL=0.954830, TP=0.919400, ASK=0.949690, BID=0.949300, FREEZE=0.000000


Here's the code change that I made.

if (m_trade.SellLimit(lot_size, price, _Symbol, sl_value, tp_value, ORDER_TIME_SPECIFIED_DAY, 5, NULL)) {
  printf("Position by %s to be opened", _Symbol);
}
else {
  printf("Error opening SELL position by %s: '%s'", _Symbol, m_trade.ResultComment());
  printf("Open parameters: price=%f, SL=%f, TP=%f, ASK=%f, BID=%f, FREEZE=%f", price, sl_value, tp_value, SymbolInfoDouble(_Symbol, SYMBOL_ASK), SymbolInfoDouble(_Symbol, SYMBOL_BID), SymbolInfoInteger(_Symbol, SYMBOL_TRADE_FREEZE_LEVEL));
}
 
haseeb_90 :

Okay, so I modified the error to print out the FREEZE_LEVEL also.  This is the Journal output that I get

2020.03.13 14:56:27.696    Core 01    2015.01.01 22:05:00   failed sell limit 0.01 AUDCAD at 0.94420 sl: 0.95483 tp: 0.91940 [Invalid price]
2020.03.13 14:56:27.696    Core 01    2015.01.01 22:05:00   Open parameters: price=0.944200 , SL=0.954830, TP=0.919400, ASK=0.949690 , BID=0.949300, FREEZE=0.000000

Are you trying to place a Sell limit BELOW the Ask price!

What is Sell limit:

Sell limit

 
Vladimir Karputov:

Are you trying to place a Sell limit BELOW the Ask price!

What is Sell limit:



Aaaah, I see. Thanks for pointing that out. I'm still new to all this.

What I'm trying to do is expecting the price to drop lower and when it does, open a position.  How would I go about doing this?

 
haseeb_90:

Aaaah, I see. Thanks for pointing that out. I'm still new to all this.

What I'm trying to do is expecting the price to drop lower and when it does, open a position.  How would I go about doing this?

Found out that I need to open a Stop order. Either a SellStop or BuyStop.  Trying to figure out how to set the expiration dates.
 
Vladimir Karputov:

Are you trying to place a Sell limit BELOW the Ask price!

What is Sell limit:


Okay, this is what I got now.
m_trade.SellStop(lot_size, price, _Symbol, sl_value, tp_value, ORDER_TIME_SPECIFIED_DAY, TimeCurrent()+96*60*60, NULL)
Thanks a lot for pointing me in the right direction.
Reason: