omit trades during braiding of ma crossovers - page 2

 
zmalick:

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

Nope . . .

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);}
}
 
zmalick:

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?


Best thing is to read all you can on MA Cross Strategies. I think your chosen timeframe is the main problem. (caveats as before!). Most examples I've seen are between H1 and D1
 

ydrol:

Best thing is to read all you can on MA Cross Strategies. I think your chosen timeframe is the main problem. (caveats as before!). Most examples I've seen are between H1 and D1

Yeah its a tuff one, Im not sure apart from the delay or identifying a ranging market what else is a useful strategy change either.

 
RaptorUK:

Nope . . .

thanks I missed the init routine..... its in there now.

//+------------------------------------------------------------------+
//|                                                            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))// CrossedUp
{
if(OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green)< 0)
{
Print("Buy (init) OrderFailed",GetLastError());
}
}
if ((fastmanow < slowmanow))// CrossedDown
{
if(OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),NULL,MagicNumber,0,Red) < 0)
{
Print("Sell (init) OrderFailed,",GetLastError());
}
}
//----
   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);
}

//+------------------------------------------------------------------+
 
zmalick:

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?


Here's something I'm trying that I hope will achieve something similar to what you're trying to do. I'm optimizing/backtesting a simple strategy that does okay on it's own, but it makes quite a few bad trades, many of which I could probably avoid if I made the decision taking into account other indicators. I probably wouldn't have made some of those bad trades myself, but I want something a little more independent.

Anyway, rather than guessing which other indicators to use or relying on my understanding of just a few other indicators, I'm actually testing to see which of the many available indicators would have significantly reduced my losses and/or maximized my gains, if any. After optimizing the simple base strategy purely for profit, I'm adding code that will write data about each trade (see https://book.mql4.com/functions/files). So, after I back test, I have a database full of rich data about the values of all kinds of indicators (and other market data) at crucial trading moments.

(Side note: I'm not sure yet whether the strategy tester allows data writing, so I'll have to double check. If not, I'll try writing a script that will read a file created from the backtest results and will then write based on that. Same result, but I'd like to do the writing from within the EA so that I later I can possibly use that for dynamic optimization during program running.)

My hope is that, upon interrogating the data, I will find significant relationships between some of the indicators and some of the bad trades. If I find other patterns that lend to maximizing the gains (e.g. dynamically creating/adjusting stops/limits, or choosing larger order sizes for "surer bets"), that's gravy.

In short, I suggest letting the data guide you.

To try what I'm trying, I suggest you look into basic database design and use, and basic statistics, in addition to checking out the link above about file operations.

 
zmalick: im still really interested in being able to predict the braiding

You can't predict the future.

Find the bar of the current cross. Find the bar of the previous cross. Don't trade the current cross if they're too close together.

 

can use both ideas to characterise the distance in time and price of good crosses and bad crosses but it wouldn't really predict the braiding just inform me of the most reliable delay range, but its definitely a start.

 
I have to add that the initial optimization of the basic strategy for pure profit is carried out with the same order size for every trade. The idea is that I am optimizing the accuracy of this strategy first, so given the limits of the optimizer data output, consistent trade volume makes total profit reflect net pips, thus it somewhat reflects the accuracy of the strategy. At this step, drawdown and profit factor and payoff are not as important. Hopefully, the other indicators will smooth that out.
 

KalebC:
I have to add that the initial optimization of the basic strategy for pure profit is carried out with the same order size for every trade. The idea is that I am optimizing the accuracy of this strategy first, so given the limits of the optimizer data output, consistent trade volume makes total profit reflect net pips, thus it somewhat reflects the accuracy of the strategy. At this step, drawdown and profit factor and payoff are not as important. Hopefully, the other indicators will smooth that out.

zmalick :Have you got any experience with the ATR indicator and the braiding KalebC.

 

i wonder if there is certain price behaviour prior to brading, ma's definitely seem to flatten during the clusters.

Reason: