结合分形、ATR、斐波那契信号开发的EA Fractal Breakout Modified.mq4-MT4 EA-峰汇在线
诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4 EA > 正文

结合分形、ATR、斐波那契信号开发的EA Fractal Breakout Modified.mq4

Fractal Breakout Modified EA根据分形、ATR、斐波那契信号在进行交易。

源码:

//+------------------------------------------------------------------+
//|                                    Fractal Breakout Modified.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link      "http://www.125808047.com"

extern double TakeProfit = 150;
extern double Lots=1;
extern double TrailingStop = 150;
extern double InitialStop = 60;
extern double PSARStepArg = 0.07;
extern double PSARMaxArg = 0.2;
extern double RiskToleranceFactor = 2.15;
extern int    slip = 30;
extern double lp = 300;
extern double sp = 30;
bool          cg = false;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void OnTick()
{
  double b=0; 
   double balance=0;
   double Ilo=0;
   
   balance=AccountBalance();
   b=(5*Point+iATR(NULL,0,4,1)*5.5);
   double LastUpFractal,LastDownFractal,TimeOfLastDownFractal,TimeOfLastUpFractal;
   double yesterday_high=0;
   double yesterday_low=0;		
   
   for(int i=1;i<Bars;i++){
      if(iFractals(NULL, Period(), MODE_UPPER,i)!=0)
      {
         LastUpFractal=iFractals(NULL, Period(), MODE_UPPER,i);
         TimeOfLastUpFractal=Time[i];
         break;
         }
      }
   for(int j=1;j<Bars;j++){
      if(iFractals(NULL, Period(), MODE_LOWER,j)!=0){
         LastDownFractal=iFractals(NULL, Period(), MODE_LOWER,j);
         TimeOfLastDownFractal=Time[j];
         break;
         }
      }
      
   ObjectDelete("Fractal Fibo Retracement");
   ObjectCreate("Fractal Fibo Retracement",OBJ_FIBO,0,TimeOfLastUpFractal,LastUpFractal,TimeOfLastDownFractal,LastDownFractal);
   
   int FractalEnvelope=MathRound((LastUpFractal-LastDownFractal)/Point);
   int CurrentATR=MathRound(iATR(Symbol(), Period(),5,0)/Point);
   Comment("Fractal Envelope: "+FractalEnvelope+" pips\n",
           "ATR(5):              "+CurrentATR+" pips\n",
           "BuyStop:            "+LastUpFractal+"\n",
           "SellStop:             "+LastDownFractal+"\n"
            );

   bool BuyTriggered=false;
   bool SellTriggered=false;
   bool FracEnvIsSmallEnough=false;
   bool FractalIsInsideEnvelope=false;
      
   if(FractalEnvelope <= (RiskToleranceFactor * iATR(Symbol(), Period(),5,0)/Point) ){ 
      FracEnvIsSmallEnough=true;
      }
   if(Close[0]<=LastUpFractal && Close[0]>=LastDownFractal){
      FractalIsInsideEnvelope=true;
      }
      
   if(FracEnvIsSmallEnough){
      if(Open[1]<LastUpFractal || Open[1]>LastDownFractal)
      {
            if(Close[0]>LastUpFractal && Close[0]<LastUpFractal+(5*Point) )
            {
               BuyTriggered=true;
               Alert("Buy triggered for "+Symbol()+" on the "+Period()+" minute chart.");
               }//end if
            if(Close[0]<LastDownFractal && Close[0]>LastDownFractal-(5*Point) )
            {
               SellTriggered=true;
             Alert("Sell triggered for "+Symbol()+" on the "+Period()+" minute chart.");
               }
      }
   }

   int OrderForThisSymbol=0;
   for(int x=0;x<OrdersTotal();x++){
      cg = OrderSelect(x, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol()) OrderForThisSymbol++;
      }
   if(BuyTriggered && OrderForThisSymbol==0){
      int BuyOrderTicket=OrderSend(Symbol(),OP_BUY,Lots,Ask,slip,Ask-(InitialStop*Point),Ask+(TakeProfit*Point),"Buy Order placed at "+CurTime(),0,0,Green);
      }
   if(SellTriggered && OrderForThisSymbol==0){ 
      int SellOrderTicket=OrderSend(Symbol(),OP_SELL,Lots,Bid,slip,Bid+(InitialStop*Point),Bid-(TakeProfit*Point),"Sell Order placed at "+CurTime(),0,0,Red);
      }
if(TrailingStop>0)
{ 
     cg = OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
     if((OrderType() == OP_BUY || OrderType() == OP_BUYSTOP) && 
(OrderSymbol()==Symbol()))
         {
            if(TrailingStop>0) 
              {                
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     cg = OrderModify(OrderTicket(),OrderOpenPrice(),Bid- 
Point*TrailingStop,OrderTakeProfit(),0,Aqua);
                    }
                 }
              }
          }
     if((OrderType() == OP_SELL || OrderType() == OP_SELLSTOP) && 
(OrderSymbol()==Symbol()))
         {
            if(TrailingStop>0)  
              {                
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if(OrderStopLoss()==0.0 || 
                     OrderStopLoss()>(Ask+Point*TrailingStop))
                    {
                     cg = OrderModify(OrderTicket(),OrderOpenPrice
(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Aqua);
                    }
                 }
              }
          }
}   
} 
打赏
版权所有转载请注明标题及链接:峰汇在线 » 结合分形、ATR、斐波那契信号开发的EA Fractal Breakout Modified.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏