Operation Syntax

 

Hi i have a problem opening pending orders:


extern int OperationType = 0; // 0 Mean Buy and Sell Limit
// 1 Mean Buy and Sell Stop



if(OperationType==0)
{
buy = OP_BUYLIMIT;
sell= OP_SELLLIMIT;
}
else if (OperationType==1)
{
buy = OP_BUYSTOP;
sell= OP_SELLSTOP;
}


etc etc


if ( TimeMinute(TimeCurrent())==OpenMinute && TimeHour(TimeCurrent())==OpenHour && MyTrades(MagicNumber)<2 )
{
Ticket = OrderSend(Symbol(),buy,Lots, Ask + Point*PipsVariation,slippage, Ask - Point*StopLoss, Ask + Point*TakeProfit,"", MagicNumber,Green);

if ( Ticket > 0 )
{
if ( OrderSelect( Ticket, SELECT_BY_TICKET, MODE_TRADES ) ) Print("BUY order opened .") ;
}
else Print("Error opening BUY order : ", ErrorDescription( GetLastError() ) ) ;
}



I get error opening orders with: "Invalid trade Parameters"



How i can solve this??

thanks.

 

Sorry, I can't guess.

Too many undefined variables in your command example.

 

Hi Phy here is my complete program, i have problem opening the orders but cant find whats the problem, I attached the EA too


#include <stdlib.mqh>

extern int OpenHour = 0; // hour goes from 0 to 23
extern int OpenMinute = 0; // minute goes from 0 tu 59
extern int PipsVariation= 30;
extern int TakeProfit = 40;
extern int StopLoss = 40;
extern int TrailingStop = 40 ; // 0 mean NO trailing Stop
extern int CloseMinute = 1; // minute goes from 0 tu 59
extern int CloseHour = 0; // hour goes from 0 to 23
extern int OperationType = 0; // 0 Mean Buy and Sell Limit
// 1 Mean Buy and Sell Stop
extern double Lots = 0.1; // Order Lots
extern int slippage = 3; //Orders slippage
extern int MagicNumber = 232323; // Oreder Macig Number

int i, cnt; // counter
int buy, sell;
int Ticket;


int start()
{

if(OperationType==0)
{
buy = OP_BUYLIMIT;
sell= OP_SELLLIMIT;
}
else if (OperationType==1)
{
buy = OP_BUYSTOP;
sell= OP_SELLSTOP;
}


if(IsTradeAllowed()) // Check to see if system is ready to trade
{

// Manage Opened Orders
if ( MyTrades(MagicNumber) > 0 )
{
for ( i=0 ; i < OrdersTotal() ; i++ )
{
OrderSelect( i, SELECT_BY_POS, MODE_TRADES );
if( OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() )
{
if( OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP )
{

//Traling Stop
if (Ask>OrderStopLoss()+TrailingStop*Point && TrailingStop!=0)
OrderModify(OrderTicket(),OrderOpenPrice(),Ask-TrailingStop*Point,OrderTakeProfit(),0,Yellow);

//Close BUY
if ( TimeMinute(TimeCurrent())==CloseMinute && TimeHour(TimeCurrent())==CloseHour )
OrderClose(OrderTicket(),OrderLots(),Close[0],slippage,Orange);


} // if BUY

if(OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP )
{

//Traling Stop
if (Bid<OrderStopLoss()-TrailingStop*Point && TrailingStop!=0)
OrderModify(OrderTicket(),OrderOpenPrice(),Bid+TrailingStop*Point,OrderTakeProfit(),0,Yellow);

//Close Sell
if (TimeMinute(TimeCurrent())==CloseMinute && TimeHour(TimeCurrent())==CloseHour)
OrderClose(OrderTicket(),OrderLots(),Close[0],slippage,Orange);

} // if SELL

} //Order MN and Symbol

} // for i

} // If MyTrades



// Open BUY order
if ( TimeMinute(TimeCurrent())==OpenMinute && TimeHour(TimeCurrent())==OpenHour && MyTrades(MagicNumber)<2 )
{
Ticket = OrderSend(Symbol(),buy,Lots, Ask + Point*PipsVariation,slippage, Ask - Point*StopLoss, Ask + Point*TakeProfit,"", MagicNumber,Green);

if ( Ticket > 0 )
{
if ( OrderSelect( Ticket, SELECT_BY_TICKET, MODE_TRADES ) ) Print("BUY order opened .") ;
}
else Print("Error opening BUY order : ", ErrorDescription( GetLastError() ) ) ;
}


// Open SELL order
if ( TimeMinute(TimeCurrent())==OpenMinute && TimeHour(TimeCurrent())==OpenHour && MyTrades(MagicNumber)<2 )
{
Ticket = OrderSend(Symbol(),sell,Lots, Bid - Point*PipsVariation,slippage, Bid + Point*StopLoss, Bid - Point*TakeProfit,"", MagicNumber,Red);
if ( Ticket > 0 )
{
if ( OrderSelect( Ticket, SELECT_BY_TICKET, MODE_TRADES ) ) Print("SELL order opened .") ;
}
else Print("Error opening SELL order : ", ErrorDescription( GetLastError() ) ) ;
}

} // if TradeAllowed





return(0);
}
//+------------------------------------------------------------------+





//
//
//+------------------------------------------------------------------+
//| My Functions |
//+------------------------------------------------------------------+
//
//


//Return number of active trades with the given Magic Number
int MyTrades(int Magic) {
cnt=0;
for(i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber()==Magic) cnt++;
}
return(cnt);
}//Function END

Files:
timekea.mq4  6 kb
 

the idea is to use it just in certain ocations so this is why its not so complicated.

I will really aprecciate your help.

Luis.

 

if OP_BUYLIMIT the price you set must be below current price.

if OP_SELLLIMIT the price you set must be above current price.

if OP_BUYSTOP the price you set must be above current price.

if OP_SELLSTOP the price you set must be below current price.

 
Thank you very much phy :)
 

Phy i modified this part of the EA like you told me but still not working:


if ( TimeMinute(TimeCurrent())==OpenMinute && TimeHour(TimeCurrent())==OpenHour && MyTrades(MagicNumber)<2 )
{
if (buy==OP_BUYLIMIT)
Ticket = OrderSend(Symbol(),buy,Lots, Ask - Point*PipsVariation,slippage, Ask - Point*StopLoss, Ask + Point*TakeProfit,"", MagicNumber,Green);
else if (buy==OP_BUYSTOP)
Ticket = OrderSend(Symbol(),buy,Lots, Ask + Point*PipsVariation,slippage, Ask - Point*StopLoss, Ask + Point*TakeProfit,"", MagicNumber,Green);

if ( Ticket > 0 )
{
if ( OrderSelect( Ticket, SELECT_BY_TICKET, MODE_TRADES ) ) Print("BUY order opened .") ;
}
else Print("Error opening BUY order : ", ErrorDescription( GetLastError() ) ) ;
}


// Open SELL order
if ( TimeMinute(TimeCurrent())==OpenMinute && TimeHour(TimeCurrent())==OpenHour && MyTrades(MagicNumber)<2 )
{
if (sell==OP_SELLLIMIT)
Ticket = OrderSend(Symbol(),sell,Lots, Bid + Point*PipsVariation,slippage, Bid + Point*StopLoss, Bid - Point*TakeProfit,"", MagicNumber,Red);
else if (sell==OP_SELLSTOP)
Ticket = OrderSend(Symbol(),sell,Lots, Bid - Point*PipsVariation,slippage, Bid + Point*StopLoss, Bid - Point*TakeProfit,"", MagicNumber,Red);

if ( Ticket > 0 )
{
if ( OrderSelect( Ticket, SELECT_BY_TICKET, MODE_TRADES ) ) Print("SELL order opened .") ;
}
else Print("Error opening SELL order : ", ErrorDescription( GetLastError() ) ) ;
}

 
Help please :)
Reason: