Why won't my robot buy at the right time?

 
oid OnTick()

{
double parabolic = iSAR(_Symbol,_Period,0.02,0.2,0);
double KLine = iStochastic(NULL,0,5,3,3,MODE_SMA,MODE_MAIN,0,0);


 
  
if (OrdersTotal() == 0)
{  
if(KLine < 20 && Ask > parabolic)
{
OrderSend(_Symbol,OP_BUY,0.1,Ask,3,Ask-50*_Point,Ask+25*_Point,NULL,0,0,Green);
}
}


}

Guys help me. I am seriosu, this makes no sense.


It just doesn't buy when the right conditions is present.

 
EDIT : my bad you buy at Ask obviously, I don't see other errors though
 
Jean Francois Le Bas:
you have to buy at Bid not Ask

No you don't, you buy at Ask.

 
Keith Watford:

No you don't, you buy at Ask.

oh yeah... my bad


maybe the stoploss is too close to the open price

you should add a verification with STOP_LEVELS

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Calculations of technical indicators require price values and/or values of volumes, on which calculations will be performed. There are 7 predefined identifiers from the ENUM_APPLIED_PRICE enumeration, used to specify the desired price base for calculations. If a technical indicator uses for calculations price data, type of which is set by...
 
Mc Temple:

It just doesn't buy when the right conditions is present.

Check your parameters for iStochastic

double KLine = iStochastic(NULL,0,5,3,3,MODE_SMA,MODE_MAIN,0,0);

I think that you have price field and mode reversed.

 
Keith Watford:

Check your parameters for iStochastic

I think that you have price field and mode reversed.

yess, the text would be red if it was the right parameter

 
Mc Temple :

Guys help me. I am seriosu, this makes no sense.


It just doesn't buy when the right conditions is present.

oid OnTick ()

{
 double parabolic = iSAR ( _Symbol , _Period , 0.02 , 0.2 , 0 );
 double KLine = iStochastic ( _Symbol , 0 , 5 , 3 , 3 , MODE_SMA ,STO_LOWHIGH, 0 , 0 );


 
  
 if ( OrdersTotal () <= 0 )
{  
 if (KLine < 20 && Ask > parabolic)
{
 OrderSend ( _Symbol ,OP_BUY, 0.1 ,Ask, 3 ,Ask- 50 * _Point ,Ask+ 25 * _Point , NULL , 0 , 0 ,Green);
}
}


}

try this

if doesnt work check conditions

 OrdersTotal () shows you if there are any open orders in your account. It doesn't matter whether the symbol is a buy order or a sell order.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM
  • www.mql5.com
For equity securities, the Depth of Market window is available, where you can see the current Buy and Sell orders. Desired direction of a trade operation, required amount and requested price are specified for each order. To obtain information...
 
OrderSend(_Symbol,OP_BUY,0.1,Ask,3,Ask-50*_Point,Ask+25*_Point,NULL,0,0,Green);
  1. Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.

  2. You would know why had you bothered to check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

  3. You buy at the Ask and sell at the Bid.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice 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.)
      Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  4. You are trying to make your SL 50 points minus the spread (say 30 points) or 20 points. You can't put them closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

    On some ECN type brokers the value might be zero (broker doesn't know.) Use a minimum of two (2) PIPs.