Ctrade not executing sells, only buys.

 

Hello,


I found it weird that if I test Ctrade with trade.buy it executes correctly, but when I try to sell with trade.Sell, it doesn't open the position as it does with buy, and I get no errors, I do get "Sell executed" printed, so I don't know where the problem lies. (I just tried it on a demo account with a lot of openings and got like 3 sells for every 100 buys). 

Any ideas on what I'm doing wrong?


#include<Trade\Trade.mqh>
CTrade trade;

double last_ts = 0;

void OnTick()
  {       
        double current_ts = iTime(NULL,0,0);          
        Alert(current_ts); 

        if(current_ts > last_ts)                                    
           last_ts = current_ts;
           double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);                            
           trade.Sell(0.01, NULL, Ask,(Ask+30 * _Point),(Ask-100 * _Point), NULL);        
           Alert("Sell executed");      
   
 }  
 
Skester96:

Hello,


I found it weird that if I test Ctrade with trade.buy it executes correctly, but when I try to sell with trade.Sell, it doesn't open the position as it does with buy, and I get no errors, I do get "Sell executed" printed, so I don't know where the problem lies. (I just tried it on a demo account with a lot of openings and got like 3 sells for every 100 buys). 

Any ideas on what I'm doing wrong?


Why don't you try checking result of the last trade request to get the info that you need?  

 
  1.            double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
               trade.Sell(0.01, NULL, Ask,(Ask+30 * _Point),(Ask-100 * _Point), NULL);
    You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP would be longer. Don't you want the same/specified amount for either direction?
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

  2.         if(current_ts > last_ts)           
    
    Use not equal There was a post around 2002, where a server clock mis-set and then corrected — stopped the EA for days!
 

Did you check the filling mode?

is this written in your symbol? Otherwise you habe to set it