Download MetaTrader 5

I have problem in close order

To add comments, please log in or register
ghobar
25
ghobar 2015.11.30 16:28 

Hi.

I have  problem  in close order 

This Ea is working and open position and close position at Profit but I want close order Which are not profit Provided that indicator 2 signal Is issued 

 



[QUOTE]//+------------------------------------------------------------------+

//|                                                                  |

//|      Copyright © 2014, Click Hooshmand Guilan LLC                |

//|               http://www.Book.com                            |

//|                                                                  |

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

#property copyright "Copyright © 2014, Click Hooshmand Guilan LLC"

#property link      "http://www.Book.com"

// local variables

double PipValue=1;    // this variable is here to support 5-digit brokers

bool Terminated = false;


extern int Magic1=1;


extern int Magic2=2;


extern bool Show_Alert = true;

extern int  Pointer_Offset = 9;

extern int  High_Offset = 10;

extern bool Display_ShootStar = true;

extern bool Show_ShootStar_Alert = true;

extern int  Offset_ShootStar = 12;

extern color Color_ShootStar = Aqua;

extern int Text_ShootStar = 8;

extern bool Display_Hammer = true;

extern bool Show_Hammer_Alert = true;

extern int  Offset_Hammer = 6;

extern color Color_Hammer = Aqua;

extern int Text_Hammer = 8;

extern double Candle_WickBody_Percent=0.90;

extern int CandleLength=12;




extern double  Risk = 3.0;


extern int slippage=6;




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

//| expert initialization function                                   |

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

int init()

  {

//----

   

//----

   return(0);

  }

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

//| expert deinitialization function                                 |

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

int deinit()

  {

//----

   

//----

   return(0);

  }

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

//| expert start function                                            |

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

int start()

  {

double b1=iCustom(Symbol(),0,"Candlestick - Hammer and Shooting Star Signal",true,9,10,true,true,12,Aqua,8,true,true,6,Aqua,8,0.90,12,0,1);


double b2=iCustom(Symbol(),0,"Candlestick - Hammer and Shooting Star Signal",true,9,10,true,true,12,Aqua,8,true,true,6,Aqua,8,0.90,12,1,1);


double b3=iCustom(Symbol(),0,"Candlestick - Hammer and Shooting Star Signal",true,9,10,true,true,12,Aqua,8,true,true,6,Aqua,8,0.90,12,0,2);


double b4=iCustom(Symbol(),0,"Candlestick - Hammer and Shooting Star Signal",true,9,10,true,true,12,Aqua,8,true,true,6,Aqua,8,0.90,12,1,2);


Comment(b1,"\n",b2,"\n",b3,"\n",b4);


{


if(Volume[0]<=1)

{

 if(b1!=EMPTY_VALUE)

 {                     

  close(Magic1);

  if(Orders()==9)

  Pendsell();

  }

  

 if(b4!=EMPTY_VALUE)

 {

  close(Magic2);

  if(Orders()==9)

  Pendbuy();

  }

 }

 }




   return(0);

  }

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

int Orders()

{

int num=9;


 for(int i=OrdersTotal()-1;i>=9;i--)

 {

 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

 

 if(OrderMagicNumber()==Magic1 || OrderMagicNumber()==Magic2)

  

  num++;

  

  }

return(num);

}

//---------------------------------------------------------------------

void Pendbuy()

{

OrderSend(Symbol(),OP_BUY,Get_Lots(Risk),Ask,slippage,0,0,"www.Book.com",Magic1,0,Blue);


}

//---------------------------------------------------------------------

void Pendsell()

{

OrderSend(Symbol(),OP_SELL,Get_Lots(Risk),Bid,slippage,0,0,"www.Book.com",Magic2,0,Red);

}

//--------------------------------------------------------------

double Get_Lots(double lRisk)

{

double

   Lots = AccountEquity() * lRisk/100/1000;

   if (MarketInfo(Symbol(),MODE_MINLOT) > Lots)Lots = MarketInfo(Symbol(),MODE_MINLOT);

   if (MarketInfo(Symbol(),MODE_MAXLOT) < Lots)Lots = MarketInfo(Symbol(),MODE_MAXLOT);

   return(Lots);

}

//--------------------------------------------------------------

void close(int number)

{


 for(int i=OrdersTotal()-1;i>=0;i--)

 {

 int OrderSelect = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

 

  if(OrderMagicNumber()==number)

  {

   if( OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber()==Magic1)

   if(Bid>OrderOpenPrice())

   if(OrderType()==OP_BUY)

   OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Green);

   

  

  if( OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber()==Magic2)

  if(Ask<OrderOpenPrice())

   if(OrderType()==OP_SELL)   

   OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Yellow);

   }   

  }

}[/QUOTE] 

 

 

Barnes & Noble
Barnes & Noble
  • Barnes & Noble
  • www.barnesandnoble.com
Lower Prices on Millions of Books, Movies and TV Show DVDs and Blu-ray, Music, Toys, and Games. Shop online for eBooks, NOOK, and textbooks. FREE Shipping on $25 orders!
Vasyl Nosal
18634
Vasyl Nosal 2015.11.30 16:55  

Volume[0]<=1

it is only for tester. 

ghobar
25
ghobar 2015.11.30 17:57  
i have problem just in close order .
Vasyl Nosal
18634
Vasyl Nosal 2015.11.30 18:22  

try to change this

int OrderSelect = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

 to this

if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
ghobar
25
ghobar 2015.11.30 19:18  

Dear Vasyl Nosal

 in this EA signal Hammer = buy and next signal Shooting Star = close buy and open sell  All of this is executed 

in this code

   if( OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber()==Magic1)

   if(Bid>OrderOpenPrice())

   if(OrderType()==OP_BUY)

   OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Green); 

 

Up to this point there is no problem

but next  i want  .  

EA = signal Hammer = 1 order buy  ( next 1 signal Shooting Star = Positions don't in profit ) =  ( next 2 signal Shooting Star = Positions don't in profit ) > close buy Positions  

i want close Positions  buy after 2  signal Shooting Star .

Please take a photo


 

Vasyl Nosal
18634
Vasyl Nosal 2015.11.30 20:30  

It is too mutch.

But in words.

Create counter of buy/sell signals

and when they=2 chek signal to close and set counter to 0. 

ghobar
25
ghobar 2015.11.30 20:46  
Vasyl Nosal:

It is too mutch.

But in words.

Create counter of buy/sell signals

and when they=2 chek signal to close and set counter to 0. 

dear Vasyl Nosal,

can you help me more?

I understand very little about programming 

Vasyl Nosal
18634
Vasyl Nosal 2015.11.30 23:29  
ghobar:

dear Vasyl Nosal,

can you help me more?

I understand very little about programming 

No.
ghobar
25
ghobar 2015.12.01 08:55  
Vasyl Nosal:
No.
No problem.
ghobar
25
ghobar 2015.12.01 18:01  
Would else can help me more ?
To add comments, please log in or register