[Help] Implementig a 3 EMA Cross + Time filter

 

Hello, guys!

I'm implementing an Expert that operates based on a 3 EMA cross, using a time filter (it makes trades only during a period of the day).

The main rule is basically:

  •      FastEMA > MediumEMA > SlowEMA = buy   (FastEMA < Medium EMA = stop loss)
  •      FastEMA < MediumEMA < SlowEMA = sell   (FastEMA > Medium EMA = stop loss)


However, there are two things that I'm not getting right.


1)I'm creating a new object "CSignalITF *pregao=new CSignalITF" every time that the Expert checks for an operation (Open/Close-Long/Short).

This is actually working, however it's not optimized. It would be great if the program created only 1 instance of the object to do this function (check if the period is OK for trading).

But I don't know how to do this! =(


2) I would like to modify the main rule, following this simple idea:

When the trade period that I configured starts, the Expert is opening a position (buy/sell) based on the 3 EMA at that moment.

I don't want that! I want that the Expert waits until the first FastEMA-MediumEMA cross, before operate for the 1st time on a day.

And I don't know how to do this either =(


All the files are attached.

- Main code;

- EMAs functions;

- Time filter;

- Picture as example;


I appreciate any help !!

Thanks !!!

 

Hi

Just create your ea using wizard adding SignalSimplerITF as another Signal.

It will work well.

or 

Remove from your signal any reference to StartTime and StopTime.

in EA

add 

#include <Expert\Signal\SignalSimplerITF.mqh>

remove 

input string StartTime = "00:00";
input string StopTime  = "23:59";

insert 

input string Signal_SITF_StartTime  ="10:00";  // Start Time
input string Signal_SITF_EndTime    ="16:00";  // End Time
input double Signal_SITF_Weight     =1.0;      // Weight [0...1.0]

remove

   signal.StartTime(StartTime);
   signal.StopTime(StopTime);

insert

//--- Creating filter CSignalSimplerITF
   CSignalSimplerITF *filter1=new CSignalSimplerITF;
   if(filter1==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter1");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
   signal.AddFilter(filter1);
//--- Set filter parameters
   filter1.StartTime(Signal_SITF_StartTime);
   filter1.EndTime(Signal_SITF_EndTime);
   filter1.Weight(Signal_SITF_Weight);
Reason: