分形的突破--图解

 

嘿,伙计们。


我想做一个分形 突破的EA,用一天中的时间和移动平均线进行过滤。


谁能给我指出正确的方向/查看代码中的任何缺陷?


1: 它只在我输入iFractal()后才买入。

2: 它没有输入分形的位置

//+------------------------------------------------------------------+
//|                                                    Simple EA.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//Literally copying Ferrus Format to a tee

extern string Label1="===General Trade Settings===";
extern int   TakeProfit=25;
extern int    StopLoss=10;
extern int    TrailingStop=0;
extern int    Slippage=2;
extern double  Lots=0.1;
//---------Time Filter--------//

//-----------Money Managerment---------//
extern bool Money.Management=true ;
extern double Risk=1;


//----------------------Moving Average-----//
extern string Label5="===Moving Average Settings===";
extern int    MA_Period=200;
extern int    MA_Shift=0;
extern int    MA_Type=1;
extern int    MA_Price=0;
//----------


//-------Initialize EA Orders Accounting-----//


int start()
{

int mypoint;

if (Digits==3||Digits==5){ mypoint=10;}
else {mypoint=1;}


//------------Orders Accounting---------//

 int total = OrdersTotal();
if(total<1)
{
//------------Money Management----------//

//Money Management sequence
 if (Money.Management)
   {
      if (Risk<1 || Risk>1000)
      {
         Comment("Invalid Risk Value.");
         return(0);
      }
      else
      {
         Lots=MathFloor((AccountFreeMargin()*AccountLeverage()*Risk*Point*mypoint*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_MINLOT);
      }
   }

//-------------EMA SETTINGS-----------------//
//
//------------------------------------------//
double EMA=iMA(NULL,0,MA_Period,MA_Shift,MA_Type,MA_Price,0);
double BarCloseB;
double BarCloseS;
BarCloseB=Bid;
BarCloseS=Ask;
//----Processing a buy---------//
//


double fractalU=iFractals(NULL,0,1,0);
double fractalD=iFractals(NULL,0,2,0);



//-----------------------------//
if((BarCloseB>EMA) && (BarCloseB>=fractalU))
{
double SLB=Bid-StopLoss*Point*mypoint;
double TPB=Bid+TakeProfit*Point*mypoint;
int buy= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0);
}

if(buy>0) 
{
OrderSelect(buy,SELECT_BY_TICKET,MODE_TRADES);
OrderModify(buy,OrderOpenPrice(),SLB,TPB,0,Green);
}
//---------Processing a sell---------//
//
//-----------------------------------//
if((BarCloseS<EMA)&&(BarCloseS<=fractalD))
{
double SLS=Ask+StopLoss*Point*mypoint;
double TPS=Ask-TakeProfit*Point*mypoint;

int sell= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0);
}

if (sell>0)
{
OrderSelect(sell,SELECT_BY_TICKET,MODE_TRADES);
OrderModify(sell,OrderOpenPrice(),SLS,TPB,0,Green);
}

Print(GetLastError());
return(0);
}
}
 
分形

突破?

double fractalU=iFractals(NULL,0,1,0);     //What if you had chosen for bar 1  ??
double fractalD=iFractals(NULL,0,2,0);             //then i think you will get sell trades also

计算你的交易后再开新的....

和更多的错误,但先试试这个


 
deVries:
分形

突围?

计算你的交易后再开新的....

和更多的错误,但先试试这个



嘿,deVries。


我很难理解这句话。我的两个收获是。


1)你想让我选择第一个酒吧?

2)重新做我的OrdersAccounting


再次感谢您的支持。

 
ZacharyRC:

嘿,deVries。


我很难理解这句话。我的两个收获是。


1)你想让我选择第一条?

2)重新做我的OrdersAccounting


再次感谢您的支持。


double fractalU=iFractals(NULL,0,1,0);

退货见我的下一篇文章.....

double fractalU=iFractals(NULL,0,1,1);

回报见我的下一篇文章......

你的订单计算方式是

 int total = OrdersTotal();
if(total<1)
{
 

如果你有另一个非本EA的交易未完成或待定,就会出现没有订单的情况。

回溯测试 中,你不会看到这种情况,但在一个账户上运行该EA,你会注意到。

 

在你的frctal代码上做了一个小测试

像这样

   double fractalU;
   for(int y=0;fractalU < Point;y++)
     {
      fractalU=iFractals(NULL,0,1,y);
      Alert("fractalUp  y =  "+y+ " "+fractalU);
     }

做同样的测试,你会看到你必须选择什么条形来获得正确的分形栏

 
deVries:

在你的frctal代码上做了一个小测试

像这样

做同样的测试,你会发现你必须选择什么条形来获得正确的分形条。


嗨,deVries!



你确实是个有帮助的人!

 
deVries:

在你的frctal代码上做了一个小测试

像这样

做同样的测试,你会看到你必须选择什么条形来获得正确的分形栏


嗯...


deVries,检查工作非常完美,对每个 "下跌 " 形和 "上涨 "分形发出了正确的价格警报。


我仍在调查代码中的错误,因为它在处理订单时 "忽略 "了分形。


你是对的,我需要修改OrdersAccounting部分,因为只要我把EA放在图表上,它就会进行交易。

 
deVries:

在你的frctal代码上做了一个小测试

像这样

做同样的测试,你会看到你必须选择什么条形来获得正确的分形条。


我真傻!


经过对代码的研究,我使用了=>而不是==,这导致了缓冲区的问题。


谢谢你deVries!!!!

 
ZacharyRC:

我真傻!


经过对代码的研究,我使用了=>而不是==,这导致了缓冲区的问题。


谢谢你deVries!!!!

你的意思是......
if((BarCloseB>EMA) && (BarCloseB>=fractalU))
改为
if((BarCloseB>EMA) && (BarCloseB==fractalU))

这样一来,????,也就不对了

.

像这样的东西

if((BarCloseB>EMA) && (BarCloseB>fractalU)&& fractalU>Point)

可能对你有用,可以让fractalU 达到你在测试中看到的效果......

 
deVries:
你的意思是......
改为

这样一来,????,这也将是不正确的。

.

像这样的事情

可能对你有用,并使fractalU达到你在测试中看到的效果......


我没有实施你的输入,因为它目前正在正常交易。我将在今晚晚些时候用你的输入进行尝试。



谢谢你deVries!

 

嘿,deVries。


我在最后的代码中遇到了问题,试图在这么多点之后把修改止损 放到收支平衡。


你看到任何明显的错误了吗?

extern int    StopLoss=10;

//-------------------------------------------------//
extern bool Move.BE=true;
extern int  MoveStopTo=1;



//----------------------------------------------//
//-----------------EXITING ORDERS---------------//
if(OrdersTotal()>1)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==(OP_BUY)&&(Move.BE))
{
if(Bid - OrderOpenPrice() >= Point * StopLoss)
 {
    if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo)
     {
     OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);
}
}
}
}

if(OrdersTotal()>1)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
{
 if(OrderType()==(OP_SELL)&&(Move.BE))
 {     
          
if(OrderOpenPrice() - Ask >= Point * StopLoss) 
 {
    if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo) 
     {
      OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
}
}
}
}
//--------CHECKING FOR ERRORS-------------------//
Print(GetLastError());
return(0);
}
}