I have been trying to create a function that will close a long position when a short signal is fired and vice versa.
could some kind soul please help me out..
I am using the 10p3 as the base but I have taken all the indicators our and set up a bar set up.
if (Open[pos+0]>=Low[pos+1] && Low[pos+2]>=Low[pos+3]){myOrderType=2;} Long set up
if (Open[pos+0]<=High[pos+1] && High[pos+2]<=High[pos+3]){myOrderType=1;} Short set up
Any help would be fantastic.
I find it easier to branch out for open and close order functions. When your conditions are met call the close order function. I program by piecing together bits and pieces of code I find. That is why I use modular programming. Contact me. We can exchange ideas. Mike bamcoti@yahoo.com
//+------------------------------------------------------------------+
//| Close orders |
//+------------------------------------------------------------------+
void CloseOrders(int CloseType)
{
double ClosePrice;
if(CloseType==1){ClosePrice=Ask;}else{ClosePrice=Bid;}
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
if(OrderType()==CloseType && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
OrderClose(OrderTicket(),OrderLots(),ClosePrice,MaxSlippage,White);}
}
//----
return(0);
}
I have been trying to create a function that will close a long position when a short signal is fired and vice versa.
could some kind soul please help me out..
I am using the 10p3 as the base but I have taken all the indicators our and set up a bar set up.
if (Open[pos+0]>=Low[pos+1] && Low[pos+2]>=Low[pos+3]){myOrderType=2;} Long set up
if (Open[pos+0]<=High[pos+1] && High[pos+2]<=High[pos+3]){myOrderType=1;} Short set up
Any help would be fantastic.
I find it easier to branch out for open and close order functions. When your conditions are met call the close order function. I program by piecing together bits and pieces of code I find. That is why I use modular programming. Contact me. We can exchange ideas. Mike bamcoti@yahoo.com
//+------------------------------------------------------------------+
//| Close orders |
//+------------------------------------------------------------------+
void CloseOrders(int CloseType)
{
double ClosePrice;
if(CloseType==1){ClosePrice=Ask;}else{ClosePrice=Bid;}
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
if(OrderType()==CloseType && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
OrderClose(OrderTicket(),OrderLots(),ClosePrice,MaxSlippage,White);}
}
//----
return(0);
}
Thanks for the reply but where would it go in the exiting code
I have been trying to create a function that will close a long position when a short signal is fired and vice versa.
could some kind soul please help me out..
I am using the 10p3 as the base but I have taken all the indicators our and set up a bar set up.
if (Open[pos+0]>=Low[pos+1] && Low[pos+2]>=Low[pos+3]){myOrderType=2;} Long set up
if (Open[pos+0]<=High[pos+1] && High[pos+2]<=High[pos+3]){myOrderType=1;} Short set up
Any help would be fantastic.
I find it easier to branch out for open and close order functions. When your conditions are met call the close order function. I program by piecing together bits and pieces of code I find. That is why I use modular programming. Contact me. We can exchange ideas. Mike bamcoti@yahoo.com
//+------------------------------------------------------------------+
//| Close orders |
//+------------------------------------------------------------------+
void CloseOrders(int CloseType)
{
double ClosePrice;
if(CloseType==1){ClosePrice=Ask;}else{ClosePrice=Bid;}
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
if(OrderType()==CloseType && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
OrderClose(OrderTicket(),OrderLots(),ClosePrice,MaxSlippage,White);}
}
//----
return(0);
}
Thanks for the reply but where would it go in the exiting code
In the program I took this from it is just befor the open order call in my check signals module. If you are not modular put the CloseOrders(0); immediatly before your open order line:
{
CloseOrders(0);
Distance=(High[1]-Low[3])/Point;
OpenOrder(1,Distance);
}
//----
return(0);
I would like help to design a martingale system to work as a braking system ( not as winning tactic) and should be very conservative strategy to mitigate the impact of a big reversal wave. Any ideas would be appreciated.
mcgene2010@yahoo.com
McGene4xPro... to mitigate problems I use this....but this is just a life saver...if I do proper management of my orders, balance and open lots...this code would never be used.
I use this to close one order at a time (the oldest)....until the bad condition is cleared.....
// THIS CLOSES ORDERS BECAUSE OF LOW MARGIN
if (OrdersTotal()>1)
if ((AccountFreeMargin()*MarginTroubleMult) < AccountMargin())
//Or if you prefer an actual currency amount use this instead
//if ((AccountBalance()-Maxloss)>AccountEquity())
{
OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
Sleep(69);
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
Sleep(6000);
}

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have been trying to create a function that will close a long position when a short signal is fired and vice versa.
could some kind soul please help me out..
I am using the 10p3 as the base but I have taken all the indicators our and set up a bar set up.
if (Open[pos+0]>=Low[pos+1] && Low[pos+2]>=Low[pos+3]){myOrderType=2;} Long set up
if (Open[pos+0]<=High[pos+1] && High[pos+2]<=High[pos+3]){myOrderType=1;} Short set up
Any help would be fantastic.