Hello, sorry for my bad English,
If anyone can help me to complete the code below (extract from sample MACD code).
I will wish to add the following logic.
I open a Buy or Sell Trade with a MACD but, if the trend is bad, I want open a other trade with a gap of 20 pips.
This action can be made 4 times.
For exemple :
I buy GBPUSD at 1,5000 with a MACD validation.
Take Profit is plan with the variable but 5 buy limit are ready (1,4080, 1,4060, 1,4040, 1,4020)
Of course, I keep the same Profit when I sell all trades.
Thanks for your help
extern double TakeProfit = 50;
extern double Lots = 0.1;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
int cnt;
int ticket;
int total;
if(Bars<100)
{
Print("Nombre de barres inférieurs à 100");
return(0);
}
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
total=OrdersTotal();
if(total<1)
{
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// Vérification pour une position Longue (BUY)
if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
// check for short position (SELL) possibility
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"macd sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
}