omit trades during braiding of ma crossovers

 

Dear all,


I have an ea that uses ma crossovers to open and close trades, does anyone know of a way to omit trades during braiding of MA crossovers. Any advice is welcomed.

 

You have to revise the strategy! Then code it afterwards. After all the ma is designed to trade on braiding?

 
ydrol:

You have to revise the strategy! Then code it afterwards. After all the ma is designed to trade on braiding?



This thread is how to omit trades based on the strategy so not really a valid answer. :(

 

Although you dont think it, and it's your thread, I think it is the answer. I've been down this route before.

The EA is designed to trade when the MA's cross? Presumably 'braiding' is the MA's crossing more than you'd like.

So you can perhaps wait a certain amount of time after a cross, or ensure a certain distance occurs between the MA's, or perhaps use an indicator to check if consolidating/ranging (although this doesnt stop 'braiding' at an angle)., or lengthen the period of the MA.

Either way, its a change in strategy, to reduce and possibly delay entry signals.

You make no mention of the EA or the timeframe, pair traded so cant suggest anything else.

 
ydrol:

Although you dont think it, and it's your thread, I think it is the answer. I've been down this route before.

The EA is designed to trade when the MA's cross? Presumably 'braiding' is the MA's crossing more than you'd like.

So you can perhaps wait a certain amount of time after a cross, or ensure a certain distance occurs between the MA's, or perhaps use an indicator to check if consolidating/ranging (although this doesnt stop 'braiding' at an angle)., or lengthen the period of the MA.

Either way, its a change in strategy, to reduce and possibly delay entry signals.

You make no mention of the EA or the timeframe, pair traded so cant suggest anything else.



GBPUSD or EURGBP timeframe 1m, 5m.

thanks in advance

ea is below:

//+------------------------------------------------------------------+
//|                                                            X.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
double ma_period_slow = 800;
double ma_period_fast = 100;
double LotSize=0.1;
double StopLoss=50000;
double TakeProfit=50000;
int MagicNumber=1234;
double pips = 0.00001;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----

double fastmanow, slowmanow;

fastmanow = iMA(Symbol(),0,ma_period_fast,0,MODE_SMA,PRICE_CLOSE,1);
slowmanow = iMA(Symbol(),0,ma_period_slow,0,MODE_SMA,PRICE_CLOSE,1);
if ((fastmanow > slowmanow))
{
{OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green);} //send buy
}
if ((fastmanow < slowmanow))
{
{OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),NULL,MagicNumber,0,Red);}
}

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
 if(IsNewCandle())
{
//----
double fastmaprevious,slowmaprevious,fastmanow,slowmanow;
int order;
fastmanow = iMA(Symbol(),0,ma_period_fast,0,MODE_SMA,PRICE_CLOSE,1);
slowmanow = iMA(Symbol(),0,ma_period_slow,0,MODE_SMA,PRICE_CLOSE,1);
fastmaprevious = iMA(Symbol(),0,ma_period_fast,0,MODE_SMA,PRICE_CLOSE,2);
slowmaprevious = iMA(Symbol(),0,ma_period_slow,0,MODE_SMA,PRICE_CLOSE,2);



//check open orders
if(OrdersTotal()==1)
{
//////////////////////////////////////////////////////////////////////////////////////////////////////
//check for exit
if ((fastmanow > slowmanow) && (fastmaprevious < slowmaprevious))// CrossedUp
   {
if(OrderSelect(0, SELECT_BY_POS)==true)
      {
order=OrderTicket();
OrderClose(order,LotSize,OrderClosePrice(),3,Violet);
      }
   }
if ((fastmanow < slowmanow) && (fastmaprevious > slowmaprevious))
   {
if(OrderSelect(0, SELECT_BY_POS)==true)
      {
order=OrderTicket();
OrderClose(order,LotSize,OrderClosePrice(),3,Aqua);
      }
   }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
if(OrdersTotal()==0)
{
///////////////////////////////////////////////////////////////////////////////////////////////////////
//check for entry
if ((fastmanow > slowmanow) && (fastmaprevious < slowmaprevious))// CrossedUp
{
{OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green);} //send buy
}
if ((fastmanow < slowmanow) && (fastmaprevious > slowmaprevious))// CrossedDown
{
{OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),NULL,MagicNumber,0,Red);}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
}
//----
   return(0);
  }
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//insuring its a new candle function
//+------------------------------------------------------------------+
bool IsNewCandle()
{
   static int BarsOnChart=0;
        if (Bars == BarsOnChart)
        return (false);
        BarsOnChart = Bars;
        return(true);
}

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

First you have to define what conditions constitute braiding, then you will have to add code to your EA to not trade while such conditions exist.

The problem is that when a cross has occurred 3 times in quick succession, it is very easy to see. It is not so easy to predict that this is likely to happen when you can only see the first cross though.

Ydrol's suggestion to ensure a certain distance occurs between the MA's may be a good idea. Maybe you could check on average cross distances for failures?

 
Another thing to consider is the angle of the cross. (angle between the lines, and also relative to the horizontal).

Although my personal experience (bearing in mind that I'm new to forex/trading) is that MA's on their own seem too laggy to be used as signals, and after the cross almost anything can happen.

If this is your EA then my understanding is that MA Cross'es work better when adjusted for higher timeframes. I could be wrong.

Also see What are Function return values ? How do I use them ?

 
ydrol:
Another thing to consider is the angle of the cross. (angle between the lines, and also relative to the horizontal).

Although my personal experience (bearing in mind that I'm new to forex/trading) is that MA's on their own seem too laggy to be used as signals, and after the cross almost anything can happen.

If this is your EA then my understanding is that MA Cross'es work better when adjusted for higher timeframes. I could be wrong.

Also see What are Function return values ? How do I use them ?


is there a way to predict the braiding based on other indicators/parameters? also why do i need the function return stuff?
 
zmalick:

is there a way to predict the braiding based on other indicators/parameters? also why do i need the function return stuff?

Because your are using function (OrderSend) and don't check the returned value. OrderSend can failed, don't you want to manage this case ?

OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green);} //send buy
 

Thanks for the advice on the function returns for the ordersend, I included them see below:

//+------------------------------------------------------------------+
//|                                                            X.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
double ma_period_slow = 800;
double ma_period_fast = 100;
double LotSize=0.1;
double StopLoss=50000;
double TakeProfit=50000;
int MagicNumber=1234;
double pips = 0.00001;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----

double fastmanow, slowmanow;

fastmanow = iMA(Symbol(),0,ma_period_fast,0,MODE_SMA,PRICE_CLOSE,1);
slowmanow = iMA(Symbol(),0,ma_period_slow,0,MODE_SMA,PRICE_CLOSE,1);
if ((fastmanow > slowmanow))
{
{OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green);} //send buy
}
if ((fastmanow < slowmanow))
{
{OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),NULL,MagicNumber,0,Red);}
}

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
 if(IsNewCandle())
{
//----
double fastmaprevious,slowmaprevious,fastmanow,slowmanow;
int order;
fastmanow = iMA(Symbol(),0,ma_period_fast,0,MODE_SMA,PRICE_CLOSE,1);
slowmanow = iMA(Symbol(),0,ma_period_slow,0,MODE_SMA,PRICE_CLOSE,1);
fastmaprevious = iMA(Symbol(),0,ma_period_fast,0,MODE_SMA,PRICE_CLOSE,2);
slowmaprevious = iMA(Symbol(),0,ma_period_slow,0,MODE_SMA,PRICE_CLOSE,2);



//check open orders
if(OrdersTotal()==1)
{
//////////////////////////////////////////////////////////////////////////////////////////////////////
//check for exit
if ((fastmanow > slowmanow) && (fastmaprevious < slowmaprevious))// CrossedUp
   {
if(OrderSelect(0, SELECT_BY_POS)==true)
      {
order=OrderTicket();
OrderClose(order,LotSize,OrderClosePrice(),3,Violet);
      }
   
   
   }
   
if ((fastmanow < slowmanow) && (fastmaprevious > slowmaprevious))
   {
if(OrderSelect(0, SELECT_BY_POS)==true)
      {
order=OrderTicket();
OrderClose(order,LotSize,OrderClosePrice(),3,Aqua);
      }
   }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
if(OrdersTotal()==0)
{
///////////////////////////////////////////////////////////////////////////////////////////////////////
//check for entry
if ((fastmanow > slowmanow) && (fastmaprevious < slowmaprevious))// CrossedUp
{
if(OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green)< 0)
{
Print("Buy OrderFailed",GetLastError());
}
}
if ((fastmanow < slowmanow) && (fastmaprevious > slowmaprevious))// CrossedDown
{
if(OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),NULL,MagicNumber,0,Red) < 0)
{
Print("Sell OrderFailed,",GetLastError());
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
}
//----
   return(0);
  }
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//insuring its a new candle function
//+------------------------------------------------------------------+
bool IsNewCandle()
{
   static int BarsOnChart=0;
        if (Bars == BarsOnChart)
        return (false);
        BarsOnChart = Bars;
        return(true);
}

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

im still really interested in being able to predict the braiding maybe using other indicators or parameters. Without the braiding clusters this code would work much better. any other "strategy" is also interesting for me can anyone help?

Reason: