Requests & Ideas (MQL5 only!) - page 63

 
israelhernando :


Unfortunately, I cannot help you - I do not have access to the futures market.

 

Hi Mr. Vladimir.

The idea is the next:

With the Derivative indicator (code provided), An EA should be the next:

-  ATR must be higher than n x (bid-ask). Suggest n = 3.

- If Derivative changes its mark from - to +, then buy.

- If Derivative changes its mark from + to -, then sell.

- Close with opposite signal.

- Money with fixed risk.

this conditions can be applied with any time.


I wish you can read this and I'm sure you'll make a great job, as you've shown to everyone.


Best regards.


//+-----------------------------------+
//|                    derivative.mq5 |
//+-----------------------------------+
#property description "Derivative"
//+-----------------------------------+
//| Indicator settings                 |
//+-----------------------------------+
#property indicator_separate_window      //Creates another window
#property indicator_level1  0            //Importante reference level 
#property indicator_buffers 1            //Buffer number 1
#property indicator_plots   1            //Plot's window name
#property indicator_type1   DRAW_LINE    //Indicator drawn as a line
#property indicator_color1  clrCoral     //Indicator color
#property indicator_style1  STYLE_SOLID  //Line style
#property indicator_width1  1            //Line width
#property indicator_label1  "Derivative" //Indicator name

#define RESET 0 //Deletes previos data (?)
//+-----------------------------------+
//| Prices function selection         |
//+-----------------------------------+
enum ENUM_PRICE_TYPE{
   PRICE_CLOSE_ = 1,     //Close
   PRICE_OPEN_,          //Open
   PRICE_HIGH_,          //High
   PRICE_LOW_,           //Low
   PRICE_MEDIAN_,        //Median Price (HL/2)
   PRICE_TYPICAL_,       //Typical Price (HLC/3)
   PRICE_WEIGHTED_,      //Weighted Close (HLCC/4)
   PRICE_SIMPL_,         //Simpl Price (OC/2)
   PRICE_QUARTER_,       //Quarted Price (HLOC/4)
   PRICE_RK4_,           //RK4 Price(HLLOCC/6)
};

//+-----------------------------------+
//| Constants                         |
//+-----------------------------------+
uint  i_slowing = 16;                       // Auxiliar Data 
input uint  dev_order = 1;                  // Derivative order 
input ENUM_PRICE_TYPE i_p = PRICE_MEDIAN_;  // Applied price

double ExtBuffer[];   //Extbuffer array
int  min_rates_total;
uint dev_o;          //Auxiliar variables

//+------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------+
int OnInit(){
   //Initial check
   if(dev_order<1){
      dev_o=1;
      PrintFormat("Calculation will use %d intead of %d.",
                  dev_o,dev_order);
   }else if(dev_order>2){
      dev_o=2;
      PrintFormat("Calculation will use %d intead of %d.",
                  dev_o,dev_order);
   }else{dev_o=dev_order;}
   min_rates_total=int(i_slowing);                         // Auxiliar definition (Do not edit)
   SetIndexBuffer(0,ExtBuffer,INDICATOR_DATA);             // Indicator buffers mapping
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);          // Indicator acurracy
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); // Sets first bar from what index will be drawn
   IndicatorSetString(INDICATOR_SHORTNAME,"dP/dt");        // Name for DataWindow and indicator subwindow label
   ArraySetAsSeries(ExtBuffer,true);                       // Time series Buffer
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);     
   return(INIT_SUCCEEDED);
}

//+-----------------------------------+
//| Derivative indicator              |
//+-----------------------------------+
int OnCalculate(const int rates_total,    // Default variable
                const int prev_calculated,// Default variable
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]){
   if(rates_total<min_rates_total) return(RESET);
   int limit,bar; //Constants definition
   //Define candle prices as temporal series
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);

   if(prev_calculated>rates_total || prev_calculated<=0){
      limit=rates_total-min_rates_total-1; 
   }else limit=rates_total-prev_calculated; 
   //Main loop of calculations
   for(bar=limit; bar>=0 && !IsStopped(); bar--){
   if(dev_o==1){
   ExtBuffer[bar]=(Ptype(i_p,bar,open,low,high,close)-Ptype(i_p,bar+dev_o,open,low,high,close))/dev_o;
   }else{
   ExtBuffer[bar]=(3*Ptype(i_p,bar,open,low,high,close)-4*Ptype(i_p,bar+(dev_o/2),open,low,high,close)+Ptype(i_p,bar+dev_o,open,low,high,close))/dev_o;
   }
   }return(rates_total);
}                

//+-----------------------------------+
//| Price funtion desition            |
//+-----------------------------------+
double Ptype(uint applied_price,// Price option
             uint  i,           // Counter
             const double &Open[],
             const double &Low[],
             const double &High[],
             const double &Close[]){
   switch(applied_price){
      case  PRICE_CLOSE: return(Close[i]);
      case  PRICE_OPEN: return(Open [i]);
      case  PRICE_HIGH: return(High [i]);
      case  PRICE_LOW: return(Low[i]);
      case  PRICE_MEDIAN: return((High[i]+Low[i])/2.0);
      case  PRICE_TYPICAL: return((Close[i]+High[i]+Low[i])/3.0);
      case  PRICE_WEIGHTED: return((2*Close[i]+High[i]+Low[i])/4.0);
      //----                            
      case  8: return((Open[i]+Close[i])/2.0);
      case  9: return((Open[i]+Close[i]+High[i]+Low[i])/4.0);
      case 10: return((2*(Open[i]+Close[i])+High[i]+Low[i])/6.0);
      default: return(Close[i]);
     }
}


 

 
Dimcortesca :


If this is an indicator from CodeBase - give a link to CodeBase   ...

 
Vladimir Karputov:

If this is an indicator from CodeBase - give a link to CodeBase   ...

It's an own indicator, but I couldn't charge it in an post. I'm new in this platform.

Is based on this one, but it has some changes:  https://www.mql5.com/en/code/13902

Derivative
Derivative
  • www.mql5.com
The indicator performs the calculation of the derivative of the price.
 
Dimcortesca :

***  ATR must be higher than n x (bid-ask). Suggest n = 3. ***

What does it mean? Who is 'n x'?

 
Vladimir Karputov:

What does it mean? Who is 'n x'?

'x' means times, and n is a double type factor (just a number)
 
Dimcortesca :
'x' means times, and n is a double type factor (just a number)

Sorry, I do not understand you. Let's do this: you have one more attempt to clearly and intelligibly explain your idea.

 
Vladimir Karputov:

Sorry, I do not understand you. Let's do this: you have one more attempt to clearly and intelligibly explain your idea.

Ok, let's do it again


EA has 2 indicator: ATR and Derivative.

On the one hand, Derivative provides buy and sell trading signals. On the other hand, ATR works as a filter avoiding transactions when market has no trends.

There will be a Threshold defined as: Factor * (Bid - Ask). This Threshold will determinate if market has tendency or not.

I will use the subindex t to define actual bar.

Conditions for opening trades:

~ For BUY: derivative change mark from - to +.

~ For SELL: derivative change mark from + to -.

Conditions for closing trades:

- If ATR_t <= Threshold --> Do NOT close trades.

- If ATR_t > Threshold --> Can close trades as follow:

~ For BUY: derivative change mark from + to -.

~ For SELL: derivative change mark from - to +.

Other conditions

- Trading with fixed risk.

- Only 1 trade at a time.  

 
Dimcortesca :

***

There will be a Threshold defined as: Factor * (Bid - Ask) . This Threshold will determinate if market has tendency or not.

*** 

In other words, do you want to check the spread value for the current symbol?

 
Vladimir Karputov:

In other words, do you want to check the spread value for the current symbol?

Yes, but I want to amplify it, because some analisys that I've done.
Reason: