Help wanted

 


Hello,
I am new to MQL5. In DealBook 360 could be programmed in ctl quite "easy".

Example:

/*

//MACD

  line := ema(price, first_period) - ema(price, second_period);

  line_signal := ema(line, signal_period);

  line_histogram := line - line_signal;

  

if positionvolume() = 0 and (line[i]-0.000008) > line[i-1] then begin 

  buy(lots);

end;

if positionvolume() = 0 and (line[i]+0.000008) < line[i-1] then begin 

  sell(lots);

end;

*/ 


Now I have created with "New" in MetaEditor 5 a EA is working well but too sensitive. I want to "reassure" the MACD signal and my new parameter "Diff = 0.000008" as installed in ctl. I tried everything possible and find no way.

Can anyone help? 

//+------------------------------------------------------------------+
//|                                                       Test11.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Include                                                          |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
//--- available signals
#include <Expert\Signal\SignalMACD.mqh>
//--- available trailing
#include <Expert\Trailing\TrailingFixedPips.mqh>
//--- available money management
#include <Expert\Money\MoneyFixedLot.mqh>
//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
//--- inputs for expert
input string             Expert_Title                  ="Test11";    // Document name
ulong                    Expert_MagicNumber            =4701;        // 
bool                     Expert_EveryTick              =false;       // 
//--- inputs for main signal
input int                Signal_ThresholdOpen          =0;          // Signal threshold value to open [0...100]
input int                Signal_ThresholdClose         =0;          // Signal threshold value to close [0...100]
input double             Signal_PriceLevel             =0.0;         // Price level to execute a deal
input double             Signal_StopLevel              =5.0;        // Stop Loss level (in points)
input double             Signal_TakeLevel              =25.0;        // Take Profit level (in points)
input int                Signal_Expiration             =0;           // Expiration of pending orders (in bars)
input int                Signal_MACD_PeriodFast        =12;          // MACD(12,24,9,PRICE_CLOSE) Period of fast EMA
input int                Signal_MACD_PeriodSlow        =24;          // MACD(12,24,9,PRICE_CLOSE) Period of slow EMA
input int                Signal_MACD_PeriodSignal      =9;           // MACD(12,24,9,PRICE_CLOSE) Period of averaging of difference
input double             Diff                          =0.000008;    // Diffenrenz zum umschalten long - short
input ENUM_APPLIED_PRICE Signal_MACD_Applied           =PRICE_OPEN; // MACD(12,24,9,PRICE_CLOSE) Prices series
input double             Signal_MACD_Weight            =0.0;         // MACD(12,24,9,PRICE_CLOSE) Weight [0...1.0]
//--- inputs for trailing
input int                Trailing_FixedPips_StopLevel  =3;          // Stop Loss trailing level (in points)
input int                Trailing_FixedPips_ProfitLevel=25;          // Take Profit trailing level (in points)
//--- inputs for money
input double             Money_FixLot_Percent          =0.5;        // Percent
input double             Money_FixLot_Lots             =0.1;         // Fixed volume
//+------------------------------------------------------------------+
//| Global expert object                                             |
//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
   if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing expert");
      ExtExpert.Deinit();
      return(-1);
     }
//--- Creating signal
   CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(-2);
     }
//---
   ExtExpert.InitSignal(signal);
   signal.ThresholdOpen(Signal_ThresholdOpen);
   signal.ThresholdClose(Signal_ThresholdClose);
   signal.PriceLevel(Signal_PriceLevel);
   signal.StopLevel(Signal_StopLevel);
   signal.TakeLevel(Signal_TakeLevel);
   signal.Expiration(Signal_Expiration);
//--- Creating filter CSignalMACD    
   CSignalMACD *filter0=new CSignalMACD;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(-3);
     }
   signal.AddFilter(filter0);
//--- Set filter parameters
   filter0.PeriodFast(Signal_MACD_PeriodFast);
   filter0.PeriodSlow(Signal_MACD_PeriodSlow);
   filter0.PeriodSignal(Signal_MACD_PeriodSignal);
   filter0.Applied(Signal_MACD_Applied);
   filter0.Weight(Signal_MACD_Weight);
//--- Creation of trailing object
   CTrailingFixedPips *trailing=new CTrailingFixedPips;
   if(trailing==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating trailing");
      ExtExpert.Deinit();
      return(-4);
     }
//--- Add trailing to expert (will be deleted automatically))
   if(!ExtExpert.InitTrailing(trailing))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing trailing");
      ExtExpert.Deinit();
      return(-5);
     }
//--- Set trailing parameters
   trailing.StopLevel(Trailing_FixedPips_StopLevel);
   trailing.ProfitLevel(Trailing_FixedPips_ProfitLevel);
//--- Creation of money object
   CMoneyFixedLot *money=new CMoneyFixedLot;
   if(money==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating money");
      ExtExpert.Deinit();
      return(-6);
     }
//--- Add money to expert (will be deleted automatically))
   if(!ExtExpert.InitMoney(money))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing money");
      ExtExpert.Deinit();
      return(-7);
     }
//--- Set money parameters
   money.Percent(Money_FixLot_Percent);
   money.Lots(Money_FixLot_Lots);
//--- Check all trading objects parameters
   if(!ExtExpert.ValidationSettings())
     {
      //--- failed
      ExtExpert.Deinit();
      return(-8);
     }
//--- Tuning of all necessary indicators
   if(!ExtExpert.InitIndicators())
     {
      //--- failed
      printf(__FUNCTION__+": error initializing indicators");
      ExtExpert.Deinit();
      return(-9);
     }
//--- ok
   return(0);
  }
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
   ExtExpert.OnTick();
  }
//+------------------------------------------------------------------+
//| "Trade" event handler function                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
   ExtExpert.OnTrade();
  }
//+------------------------------------------------------------------+
//| "Timer" event handler function                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   ExtExpert.OnTimer();
  }
//+------------------------------------------------------------------+


 


 

 
gehtdoch:

Now I have created with "New" in MetaEditor 5 a EA is working well but too sensitive. I want to "reassure" the MACD signal and my new parameter "Diff = 0.000008" as installed in ctl. I tried everything possible and find no way.

What does that mean ?

Now I have created with "New" in MetaEditor 5 a EA is working well but too sensitive. I want to "reassure" the MACD signal and my new parameter "Diff = 0.000008" as installed in ctl. I tried everything possible and find no way.

Find a way to do what ? What have you tried ?

 
angevoyageur:

What does that mean ?

Find a way to do what ? What have you tried ?

Since I have a slight manipulation of the MACD signal in the vicinity of the ordering decisions (now long or short) influence I have searched this unique place in the embedded subroutines and not found or not recognized.
I tried using diff in the main program to work. The result, many error messages.

Chart 

  
For a better understanding.?
I have shown in a chart times the problem. The EA responded immediately with a new candle when MACD-signal red then short when MACD-signal green then long.
The "Diff" I want to switch the instant, from long to short to delay the + diff.

I want to manipulate the current MACD signal with Diff. 

Example:
previous signal = 1 and the current signal > (1 + Diff) then long

previous signal = 1 and the current signal < (1 - Diff) then short

Please where I can manipulate with "+ Diff" and "- Diff"? 

 

 
gehtdoch:
Since I have a slight manipulation of the MACD signal in the vicinity of the ordering decisions (now long or short) influence I have searched this unique place in the embedded subroutines and not found or not recognized.
I tried using diff in the main program to work. The result, many error messages.

 

  
For a better understanding.?
I have shown in a chart times the problem. The EA responded immediately with a new candle when MACD-signal red then short when MACD-signal green then long.
The "Diff" I want to switch the instant, from long to short to delay the + diff.

I want to manipulate the current MACD signal with Diff. 

Example:
previous signal = 1 and the current signal > (1 + Diff) then long

previous signal = 1 and the current signal < (1 - Diff) then short

Please where I can manipulate with "+ Diff" and "- Diff"? 

I think you have to create you own class derived from CSignalMACD and then overload the LongCondition(void) and ShortCondition(void).

Something like :

#include <Expert\Signal\SignalMACD.mqh>

class CMySignalMACD : public CSignalMACD
  {
protected:
   double            m_diff;           // Diff

public:
   //--- methods of setting adjustable parameters
   void              SetDiff(double value)             { m_diff=value;           }
}

int CSignalMACD::LongCondition(void)
  {

// In this function replace 0.0 with m_diff where appropriate

   int result=0;
   int idx   =StartIndex();
//--- check direction of the main line
   if(DiffMain(idx)>0.0)
     {
      //--- the main line is directed upwards, and it confirms the possibility of price growth
      if(IS_PATTERN_USAGE(0))
         result=m_pattern_0;      // "confirming" signal number 0
      //--- if the model 1 is used, look for a reverse of the main line
      if(IS_PATTERN_USAGE(1) && DiffMain(idx+1)<0.0)
         result=m_pattern_1;      // signal number 1
      //--- if the model 2 is used, look for an intersection of the main and signal line
      if(IS_PATTERN_USAGE(2) && State(idx)>0.0 && State(idx+1)<0.0)
         result=m_pattern_2;      // signal number 2
      //--- if the model 3 is used, look for an intersection of the main line and the zero level
      if(IS_PATTERN_USAGE(3) && Main(idx)>0.0 && Main(idx+1)<0.0)
         result=m_pattern_3;      // signal number 3
      //--- if the models 4 or 5 are used and the main line turned upwards below the zero level, look for divergences
      if((IS_PATTERN_USAGE(4) || IS_PATTERN_USAGE(5)) && Main(idx)<0.0)
        {
         //--- perform the extended analysis of the oscillator state
         ExtState(idx);
         //--- if the model 4 is used, look for the "divergence" signal
         if(IS_PATTERN_USAGE(4) && CompareMaps(1,1)) // 0000 0001b
            result=m_pattern_4;   // signal number 4
         //--- if the model 5 is used, look for the "double divergence" signal
         if(IS_PATTERN_USAGE(5) && CompareMaps(0x11,2)) // 0001 0001b
            return(m_pattern_5);  // signal number 5
        }
     }
//--- return the result
   return(result);
  }
int CMySignalMACD::LongCondition(void)
  {
   // See SignalMACD.mqh
   ...
   return(result);
  } 
and replace CSignalMACD with CMySignalMACD within your EA.
 
angevoyageur:

I think you have to create you own class derived from CSignalMACD and then overload the LongCondition(void) and ShortCondition(void).

Something like :

and replace CSignalMACD with CMySignalMACD within your EA.
The proposed solution seemed conclusive. I have only one, then all replaced 0.0 with "m_diff". No error messages.
After each change I have made a trial run in the Strategy Tester. It changed nothing.
Then I once locked the whole section of LongCondition + ShortCondition  in SignalMACD.mqh. Even this did not change.
Buying and selling are not dependent on this part of the program.
In each part, the program goes to other subprograms, but the point where a signal for "OrderSend" is, I still have not found.
 
gehtdoch:
The proposed solution seemed conclusive. I have only one, then all replaced 0.0 with "m_diff". No error messages.
After each change I have made a trial run in the Strategy Tester. It changed nothing.
Then I once locked the whole section of LongCondition + ShortCondition  in SignalMACD.mqh. Even this did not change.
Buying and selling are not dependent on this part of the program.
In each part, the program goes to other subprograms, but the point where a signal for "OrderSend" is, I still have not found.
Ah ? I will try but don't expect nothing before tomorrow.
 
angevoyageur:
Ah ? I will try but don't expect nothing before tomorrow.
OK. Above is the complete code ...
 
gehtdoch:
OK. Above is the complete code ...
PS: has occurred to me, after having compiled a script is displayed immediately in the new chart! Hopefully this is in the tester, too.
 
gehtdoch:
PS: has occurred to me, after having compiled a script is displayed immediately in the new chart! Hopefully this is in the tester, too.
What are you talking about ?
 
angevoyageur:
What are you talking about ?
perhaps it is now understandable.
If I have a script on the chart, it automatically when I changed it AND recompiled appear changed.
When EA remain the input values ​​in the tester, even after a change and new compilation as before. I can not see whether it is the modified version of EA. If not, my tests were in vain.
 
gehtdoch:
The proposed solution seemed conclusive. I have only one, then all replaced 0.0 with "m_diff". No error messages.
After each change I have made a trial run in the Strategy Tester. It changed nothing.
Then I once locked the whole section of LongCondition + ShortCondition  in SignalMACD.mqh. Even this did not change.
Buying and selling are not dependent on this part of the program.
In each part, the program goes to other subprograms, but the point where a signal for "OrderSend" is, I still have not found.
Effectively that doesn't work with your code. Never goes to CSignalMACD::LongPosition, I don't know what you have modified.

BUT

If I create a new EA with MQL5 Wizard using MACD as signal, that works, it goes to CSignalMACD::LongPosition. So you have to create a new one and apply modifications I suggested above. That would work.
MQL5 Wizard: Creating Expert Advisors without Programming
MQL5 Wizard: Creating Expert Advisors without Programming
  • 2011.01.11
  • MetaQuotes Software Corp.
  • www.mql5.com
Do you want to try out a trading strategy while wasting no time for programming? In MQL5 Wizard you can simply select the type of trading signals, add modules of trailing positions and money management - and your work is done! Create your own implementations of modules or order them via the Jobs service - and combine your new modules with existing ones.
Reason: