Code für eine Art Ausbruchstrading nach Faktor Pips und Zeit - Seite 2

 

Ich habe das Rad neu erfinden müssen, da es sowas nur im Ansatz gibt.

Sehr einfach gehalten und mit Indexfehler durch Bufferüberlauf: https://www.mql5.com/de/code/89 ein sehr frühes Werk.

Die Sache mit dem Plotshift hat einiges Kopfzerbrechen bereitet.

Resultat: Ein Tickchart im Subwindow der für einen EA leicht auszulesen ist.

//+------------------------------------------------------------------+
//|                                                   Tick_Chart.mqh |
//|                                Copyright © 2018 Ing. Otto Pauser |
//|                       https://www.mql5.com/de/users/kronenchakra | 
//| simple code as idea was found on https://www.mql5.com/de/code/89 |
//+------------------------------------------------------------------+
#property copyright     "Copyright © 2018, Ing. Otto Pauser"
#property link          "https://www.mql5.com/de/users/kronenchakra"
#property version       "1.0"
#property description   "Tickchart in subwindow"
#property indicator_separate_window

#define LSTYLE ENUM_LINE_STYLE
#define PDTYPE ENUM_DRAW_TYPE
#define PLOTS  5

#property indicator_buffers PLOTS
#property indicator_plots   PLOTS

//+------------------------------------------------------------------+
//| input values                                                     |
//+------------------------------------------------------------------+
input int   inp_MaxTicks    =          500;   // Maxticks to load
input int   inp_LineWidth   =            1;   // Linewidth Ask/Mid/Bid
input color inp_ColorAsk    =       clrRed;   // Color Ask
input color inp_ColorMid    =    clrSilver;   // Color Mid
input color inp_ColorBid    = clrSteelBlue;   // Color Bid
input bool  inp_ShowLines   =         true;   // Show Ask/Bid Lines
input int   inp_Period      =           10;   // Period (< MaxTicks)
input int   inp_LineWidHL   =            2;   // LineWidth high/low
input color inp_ColorHig    =       clrRed;   // Color high
input color inp_ColorLow    = clrSteelBlue;   // Color low
input bool  inp_ShowHighLow =         true;   // Show high/low of period

//+------------------------------------------------------------------+
//| globals definitions                                              |
//+------------------------------------------------------------------+
double Ask[], Mid[], Bid[], HiLine[], LoLine[];

//+------------------------------------------------------------------+
//| Indicator initialization                                         |
//+------------------------------------------------------------------+
int OnInit()
{
   Indi.InitLine(Ask,DRAW_LINE,STYLE_SOLID,inp_LineWidth,inp_ColorAsk,"ASK");
   Indi.InitLine(Mid,DRAW_LINE,STYLE_DOT  ,inp_LineWidth,inp_ColorMid,"MID");
   Indi.InitLine(Bid,DRAW_LINE,STYLE_SOLID,inp_LineWidth,inp_ColorBid,"BID");
   PDTYPE DRAW_TYPE=inp_ShowHighLow?DRAW_LINE:DRAW_NONE;
   Indi.InitLine(HiLine,DRAW_TYPE,STYLE_SOLID,inp_LineWidHL,inp_ColorHig,"High("+IntegerToString(inp_Period)+")");
   Indi.InitLine(LoLine,DRAW_TYPE,STYLE_SOLID,inp_LineWidHL,inp_ColorLow, "Low("+IntegerToString(inp_Period)+")");
   IndicatorSetString (INDICATOR_SHORTNAME,"Tick_Chart");
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Indicator mainloop                                               |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double& price[])
{
   static   int  count=0;                             // number of ticks (tickindex)
            int  shift;                               // shift  of chart

   MqlTick  last_tick;                                // one tick
   double   hh,ll;                                    // highest high, lowest low
   int      idxStart, idxLimit;                       // indizes to find max min

   if(count==0)                                       // first call of OnCalculate() or reset buffers
      {                                  
         ZeroMemory(Ask);                             // clear the buffers
         ZeroMemory(Mid);
         ZeroMemory(Bid);
         ZeroMemory(HiLine);
         ZeroMemory(LoLine);
         count=LoadTicks(inp_MaxTicks,Ask,Mid,Bid);   // try to load ticks from cache
      }

   if(SymbolInfoTick(Symbol(),last_tick))             // get last tick
      {
         Ask[count]= last_tick.ask;                   // copy tickvalues to plotbuffers
         Mid[count]=(last_tick.ask+last_tick.bid)*0.5;
         Bid[count]= last_tick.bid;

         if(inp_ShowLines)                            // show ask/bid line selected
            {
               HLine("Ask",Ask[count],inp_ColorAsk,inp_LineWidth,STYLE_DASHDOT);
               HLine("Bid",Bid[count],inp_ColorBid,inp_LineWidth,STYLE_DASHDOT);
            }

         if(inp_ShowHighLow)                          // show max/min line selected
            {
               idxStart=count-inp_Period;             // start index for max/min
               idxLimit=count;                        // end index for max/min

               hh = Ask[ArrayMaximum(Ask,idxStart,inp_Period)];   // find the highest high
               ll = Bid[ArrayMinimum(Bid,idxStart,inp_Period)];   // find the lowest  low

               DrawLine(HiLine,idxStart,idxLimit,hh);             // draw the Maxline
               DrawLine(LoLine,idxStart,idxLimit,ll);             // draw the Minline
            }

         shift=rates_total-count-1;                         // calculate shift of display
         for(int i=0; i<PLOTS; i++)                         // shift all plotbuffers
            PlotIndexSetInteger(i,PLOT_SHIFT, shift);
      
         count++;                                          // increment ticknumber

         if(shift==0)                                       // avoid the array overflow
           (count=0);                                      // will load the cache again and start from begin 
      }

   return(rates_total);
}

//+------------------------------------------------------------------+
//| load max available ticks from cache to all 3 buffers             |
//+------------------------------------------------------------------+
int LoadTicks(int aMaxTicks, double &askBuf[], double &midBuf[], double &bidBuf[])
{
   MqlTick TickArray[];
   int loaded=CopyTicks(_Symbol,TickArray,COPY_TICKS_INFO,0,aMaxTicks);

   if(loaded<0)
      return(0);

   for(int i=0; i<loaded; i++)
      {
       askBuf[i]= TickArray[i].ask;
       bidBuf[i]= TickArray[i].bid;
       midBuf[i]= (askBuf[i]+bidBuf[i])*0.5;
      }

   return(loaded);
}

//+------------------------------------------------------------------+
//| comfortable function to initialize indicatorbuffers              |
//+------------------------------------------------------------------+
class CIndi
{
   private:
      int   BufIdx;                                         // current bufferindex
   public:
      bool InitLine (double  &aBuffer[],                    // the buffer
                     PDTYPE   aDrawType =DRAW_LINE,         // DRAW_NONE .. DRAW_COLOR_CANDLES
                     LSTYLE   aLineStyle=STYLE_SOLID,       // STYLE_SOLID .. STYLE_DASHDOTDOT
                     int      aLineWidth=1,                 // PLOT_LINE_WIDTH
                     int      aLineColor=clrRed,            // PLOT_LINE_COLOR
                     string   aPlotLabel="")                // PLOT_LABEL - "Any String"
                     {
                        SetIndexBuffer     (BufIdx,aBuffer,         INDICATOR_DATA);
                        PlotIndexSetInteger(BufIdx,PLOT_DRAW_TYPE,  DRAW_LINE );
                        PlotIndexSetInteger(BufIdx,PLOT_LINE_STYLE, aLineStyle);
                        PlotIndexSetInteger(BufIdx,PLOT_LINE_WIDTH, aLineWidth);
                        PlotIndexSetInteger(BufIdx,PLOT_LINE_COLOR, aLineColor);
                        PlotIndexSetString (BufIdx,PLOT_LABEL,      aPlotLabel);
                        PlotIndexSetDouble (BufIdx,PLOT_EMPTY_VALUE,NULL);
                        ArraySetAsSeries   (aBuffer,false);
                        BufIdx++;                           // increment bufferindex for next call
                        return(true);
                     }
};

CIndi Indi;

//+------------------------------------------------------------------+
//| comfortable and fast handling of a OBJ_HLINE                     |
//+------------------------------------------------------------------+
void HLine(string aName, double aPrice, color aColor, int aWidth, LSTYLE aStyle)
{
   if(ObjectFind(0,aName)==WRONG_VALUE)                     // if the chartobject does not exist
      {
         ObjectCreate    (0,aName,OBJ_HLINE,ChartWindowFind(),NULL,aPrice);   // create OBJ_HLINE
         ObjectSetInteger(0,aName,OBJPROP_SELECTABLE,false);                  // set the properties
         ObjectSetInteger(0,aName,OBJPROP_COLOR,aColor);
         ObjectSetInteger(0,aName,OBJPROP_WIDTH,aWidth);
         ObjectSetInteger(0,aName,OBJPROP_STYLE,aStyle);
      }
   else
      ObjectSetDouble(0,aName,OBJPROP_PRICE,aPrice);        // update the price
}

//+------------------------------------------------------------------+
//| draw a line in plotbuffer                                        |
//+------------------------------------------------------------------+
void DrawLine(double &aBuffer[], int iStart, int iLimit, double value)
{
   for(int i=iStart; i<=iLimit; i++)    // set line value
      aBuffer[i]=value;

   aBuffer[iStart-1]=NULL;              // clear last segment of line
}

Eine Steigerung ist noch möglich, SMA und EMA in diesem TickChart.

Diese Variante könnt ihr per PN erhalten.

Ticks
Ticks
  • www.mql5.com
Ansichten: 896 Rating: Veröffentlicht: 2016.04.21 15:56 Aktualisiert: 2016.11.22 07:34 Es ist ein einfaches Beispiel des Indikators das Ticks im separaten Unterfenster anzeigt. Er verwendet die buffers des Standard-Indikators, nach jedem Tick mit der Funktion PlotIndexSetInteger() verschoben...
Dateien:
Tick_Chart.mq5  19 kb