why my order isnt send to the terminal

 

hello 

i wrote a program with OrderSend().But this order isnt send correctly ( ticket <0 )

Can u tell from where is the error in this program :

//+------------------------------------------------------------------+

//|                                                   openTrades.mq4 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property indicator_chart_window

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

//init variables

   double minStopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL);

   int magicNumber = 16384;

   int slippage = 3;

   datetime expiration=0;

   int ticket = 0;

   bool tradeBuy = FALSE, tradeSell=FALSE;

   double price,stoploss,takeprofit;



//strategie   

   if ( (High[0]>High[1]) && (Close[2]<Close[1]) ) tradeBuy = TRUE;

   if ( (Low[0]<Low[1]) && (Close[2]>Close[1]) ) tradeSell = TRUE;



//send open trade order   

   if (tradeBuy == TRUE) 

                 { price=Ask;

                   stoploss = NormalizeDouble(Bid-minStopLevel*Point,Digits);

                   takeprofit = NormalizeDouble(Bid+minStopLevel*Point,Digits);

                   ticket = OrderSend(Symbol(),OP_BUY,1,price,slippage,stoploss,takeprofit,"My Buy order",magicNumber,expiration,clrGreen);

                 }

                 

  if (tradeSell==TRUE) 

                 { price=Bid;

                   stoploss = NormalizeDouble(Bid+minStopLevel*Point,Digits);

                   takeprofit = NormalizeDouble(Bid-minStopLevel*Point,Digits);

                   ticket = OrderSend(Symbol(),OP_SELL,1,price,slippage,stoploss,takeprofit,"My Sell order",magicNumber,expiration,clrRed);

                 }

                  

//--- return value of prev_calculated for next call



 //}

 Comment("ticket= "+ticket+"  " + GetLastError() + " stoploss= "+stoploss+" takeprofit= "+takeprofit);

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. USD/JPY Analysis Well, the asset moves...
 
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Check your return codes for errors, report them and you would know why. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  3. int OnCalculate(...
       ticket = OrderSend(Symbol(),OP_SELL,1,price,slippage,stoploss,takeprofit,"My Sell order",magicNumber,expiration,clrRed);
    Indicators can not trade.
 

i put codes in <code>

GetLastError() gives  Runtime Error code 4055 which means custom indicator error (ERR_CUSTOM_INDICATOR_ERROR)

How to remove it?

tnx

 
paulselvan:

i put codes in <code>

GetLastError() gives  Runtime Error code 4055 which means custom indicator error (ERR_CUSTOM_INDICATOR_ERROR)

How to remove it?

tnx

As @whroeder1 said an indicator can not trade. If you want to trade you have to create an Expert (or a Script).

 

oh its more clear now

tnx

Reason: