简体   繁体   中英

predicting fractal before appearing on graph MQL5

I am trying to predict the fractal values before they appear on the chart so that I can apply other algorithms. I have tried the following but is of no use as it is giving the false positive to me.:

int fractalStore;
int OnInit()
{
   fractalStore = iFractals( _Symbol, _Period );
   ArraySetAsSeries( UpFrac,  false );
   ArraySetAsSeries( DownFrac,false );

   return( INIT_SUCCEEDED );
}

void OnTick()
{
     CopyBuffer( fractalStore, 0, 0, 5, UpFrac   );
     CopyBuffer( fractalStore, 1, 0, 5, DownFrac );

     if (  ( UpFrac[  0] != UpFrac[  1] )
        && ( DownFrac[0] == DownFrac[1] )
        && ( UpFrac[  0] == DownFrac[1] )
        && ( UpFrac[  0] == DownFrac[0] )
           )
     {
         trade.Buy( 0.1 );
         if ( !ArrowBuyCreate( 0, "Arrow Buy" + IntegerToString( count ) ) )
               Print( "Cannot sell" );              
     }

     if (  ( DownFrac[0] != DownFrac[1] )
        && ( UpFrac[  0] == UpFrac[  1] )
        && ( UpFrac[  1] == DownFrac[0] )
        && ( UpFrac[  0] == DownFrac[0] )
           )
     {
           trade.Sell( 0.1 );
           ArrowUpCreate();

           if (  !ArrowSellCreate( 0, "Arrow Sell" + IntegerToString( count ) ) )
                  Print( "Cannot sell" );

           Comment( "Sell" );
       }
}

bool ArrowSellCreate(const long            chart_ID=0,        // chart's ID 
                     const string          name="ArrowSell",  // sign name 
                     const int             sub_window=0,      // subwindow index 
                     datetime              time=0,            // anchor point time 
                     double                price=0,           // anchor point price 
                     const color           clr=C'225,68,29',  // sign color 
                     const ENUM_LINE_STYLE style=STYLE_SOLID, // line style (when highlighted) 
                     const int             width=1,           // line size (when highlighted) 
                     const bool            back=false,        // in the background 
                     const bool            selection=false,   // highlight to move 
                     const bool            hidden=true,       // hidden in the object list 
                     const long            z_order=0)         // priority for mouse click 
  { 
//--- set anchor point coordinates if they are not set 
   ChangeArrowEmptyPoint(time,price); 
//--- reset the error value 
   ResetLastError(); 
//--- create the sign 
   if(!ObjectCreate(chart_ID,name,OBJ_ARROW_SELL,sub_window,time,price)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create \"Sell\" sign! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set a sign color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- set a line style (when highlighted) 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
//--- set a line size (when highlighted) 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the sign by mouse 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Move the anchor point                                            | 
//+------------------------------------------------------------------+ 
bool ArrowSellMove(const long   chart_ID=0,       // chart's ID 
                   const string name="ArrowSell", // object name 
                   datetime     time=0,           // anchor point time coordinate 
                   double       price=0)          // anchor point price coordinate 
  { 
//--- if point position is not set, move it to the current bar having Bid price 
   if(!time) 
      time=TimeCurrent(); 
   if(!price) 
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID); 
//--- reset the error value 
   ResetLastError(); 
//--- move the anchor point 
   if(!ObjectMove(chart_ID,name,0,time,price)) 
     { 
      Print(__FUNCTION__, 
            ": failed to move the anchor point! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Delete Sell sign                                                 | 
//+------------------------------------------------------------------+ 
bool ArrowSellDelete(const long   chart_ID=0,       // chart's ID 
                     const string name="ArrowSell") // sign name 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- delete the sign 
   if(!ObjectDelete(chart_ID,name)) 
     { 
      Print(__FUNCTION__, 
            ": failed to delete \"Sell\" sign! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Check anchor point values and set default values                 | 
//| for empty ones                                                   | 
//+------------------------------------------------------------------+ 
void ChangeArrowEmptyPoint(datetime &time,double &price) 
  { 
//--- if the point's time is not set, it will be on the current bar 
   if(!time) 
      time=TimeCurrent(); 
//--- if the point's price is not set, it will have Bid value 
   if(!price) 
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID); 
  } 
bool ArrowBuyCreate(const long            chart_ID=0,        // chart's ID 
                    const string          name="ArrowBuy",   // sign name 
                    const int             sub_window=0,      // subwindow index 
                    datetime              time=0,            // anchor point time 
                    double                price=0,           // anchor point price 
                    const color           clr=C'3,95,172',   // sign color 
                    const ENUM_LINE_STYLE style=STYLE_SOLID, // line style (when highlighted) 
                    const int             width=1,           // line size (when highlighted) 
                    const bool            back=false,        // in the background 
                    const bool            selection=false,   // highlight to move 
                    const bool            hidden=true,       // hidden in the object list 
                    const long            z_order=0)         // priority for mouse click 
  { 
//--- set anchor point coordinates if they are not set 
   ChangeArrowEmptyPoint(time,price); 
//--- reset the error value 
   ResetLastError(); 
//--- create the sign 
   if(!ObjectCreate(chart_ID,name,OBJ_ARROW_BUY,sub_window,time,price)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create \"Buy\" sign! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set a sign color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- set a line style (when highlighted) 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
//--- set a line size (when highlighted) 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the sign by mouse 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Move the anchor point                                            | 
//+------------------------------------------------------------------+ 
bool ArrowBuyMove(const long   chart_ID=0,      // chart's ID 
                  const string name="ArrowBuy", // object name 
                  datetime     time=0,          // anchor point time coordinate 
                  double       price=0)         // anchor point price coordinate 
  { 
//--- if point position is not set, move it to the current bar having Bid price 
   if(!time) 
      time=TimeCurrent(); 
   if(!price) 
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID); 
//--- reset the error value 
   ResetLastError(); 
//--- move the anchor point 
   if(!ObjectMove(chart_ID,name,0,time,price)) 
     { 
      Print(__FUNCTION__, 
            ": failed to move the anchor point! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  }

I am trying to predict the values of Fractal arrows and display them. But getting very different values and placing the arrows else where.

Kindly, help me and let me know how I can predict the arrows of the fractal before actual indicator placing the arrow.

One who has read a definition of Fractal knows this will never fly

By design, there is at least a 3 Bar principal detection lag, before one can confirm a presence of Fractal-based signal.

As simple as this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM