Simple experts - page 19

 
mladen:

Adding this one (since it was talked about something like this here : https://www.mql5.com/en/forum/186180 ) :

ATTENTION: Video should be reuploaded
simple_hull_variation_ea.mq4

________________

Indicator used by the EA (must be in the indicators folder) :

ATTENTION: Video should be reuploaded
hull_variation_2.mq4

Dear @mladen,

Which method do you recommend for backtest this ea (simple_hull_variation_ea) ?

"Open prices" or "Every tick" ?

Thank you... 

 
oguz:

Dear @mladen,

Which method do you recommend for backtest this ea (simple_hull_variation_ea) ?

"Open prices" or "Every tick" ?

Thank you... 

If you are using closed candle for testing the conditions and you do not use stop losses or take profits, it is exactly the same (then the signal nor the stop loss and take profit do not depend on intra-bar changes since the conditions are tested on closed candle) - and then, since the "on open prices" is much faster, it seems like an obvious choice

If you are using opened candle for conditions or if you are using stop losses  and take profits, then use "on every tick" method or else you will get false results

 
mladen:

If you are using closed candle for testing the conditions and you do not use stop losses or take profits, it is exactly the same (then the signal nor the stop loss and take profit do not depend on intra-bar changes since the conditions are tested on closed candle) - and then, since the "on open prices" is much faster, it seems like an obvious choice

If you are using opened candle for conditions or if you are using stop losses  and take profits, then use "on every tick" method or else you will get false results

You're like a lighthouse :) Every time you show the right way.

Thanks million mladen :)  

 
mladen:

Upgraded "simple" expert for stepma of rsi adaptive ema (to use version 2.9 of the indicator, that was posted here : https://www.mql5.com/en/forum/179807/page417 )

Dearest MLADEN

  I tried to alter simply by copy/paste  (icustom call-changed indicator name) your EA "simple (stepma of rsi adaptive ema 2.9) EA" into "simple (stepma of rsi adaptive tema 1.1) EA" because i guess all features and parameters are same and equal sequence wise ... it is right to do so or if it needs some code modification inside EA code by you ?

the EA work but strange way,then i applied all 2 EAs (ema and tema) to different symbols/pairs with 5 slippage and test on every bar-test (1,2,3) they work very strange,some time working properly,some times inverse,some time did not take trade on signal change even so many bar passed to opposite trend .... can you plz look the code what happening cause and advise plz.

is there any chance repainting issue in all 2 indicators with color signaling though i don't believes,or if some issue with test-bar calculation or what so else.

regards


 
mntiwana:

Dearest MLADEN

  I tried to alter simply by copy/paste  (icustom call-changed indicator name) your EA "simple (stepma of rsi adaptive ema 2.9) EA" into "simple (stepma of rsi adaptive tema 1.1) EA" because i guess all features and parameters are same and equal sequence wise ... it is right to do so or if it needs some code modification inside EA code by you ?

the EA work but strange way,then i applied all 2 EAs (ema and tema) to different symbols/pairs with 5 slippage and test on every bar-test (1,2,3) they work very strange,some time working properly,some times inverse,some time did not take trade on signal change even so many bar passed to opposite trend .... can you plz look the code what happening cause and advise plz.

is there any chance repainting issue in all 2 indicators with color signaling though i don't believes,or if some issue with test-bar calculation or what so else.

regards


mntiwana

The enum for rsi types in stepma of rsi adaptive tema is different It should be like this :

enum enRsiTypes
{
   rsi_rsi,  // Regular RSI
   rsi_slo,  // Slow RSI
   rsi_rap,  // Rapid RSI
   rsi_har,  // Harris RSI
   rsi_rsx,  // RSX
   rsi_cut   // Cuttlers RSI
};
 
mladen:

mntiwana

The enum for rsi types in stepma of rsi adaptive tema is different It should be like this :

enum enRsiTypes
{
   rsi_rsi,  // Regular RSI
   rsi_slo,  // Slow RSI
   rsi_rap,  // Rapid RSI
   rsi_har,  // Harris RSI
   rsi_rsx,  // RSX
   rsi_cut   // Cuttlers RSI
};

Dearest MLADEN

Thanks for early response,do you think all that problems were in tema EA working behavior because of this reason ?

can you plz look in this changed code,as per your advice ,is it right for now ?

regards

//------------------------------------------------------------------
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"
#property strict
//------------------------------------------------------------------

enum enPrices
{
   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low
   pr_median,     // Median
   pr_typical,    // Typical
   pr_weighted,   // Weighted
   pr_average,    // Average (high+low+open+close)/4
   pr_medianb,    // Average median body (open+close)/2
   pr_tbiased,    // Trend biased price
   pr_tbiased2,   // Trend biased (extreme) price
   pr_haclose,    // Heiken ashi close
   pr_haopen ,    // Heiken ashi open
   pr_hahigh,     // Heiken ashi high
   pr_halow,      // Heiken ashi low
   pr_hamedian,   // Heiken ashi median
   pr_hatypical,  // Heiken ashi typical
   pr_haweighted, // Heiken ashi weighted
   pr_haaverage,  // Heiken ashi average
   pr_hamedianb,  // Heiken ashi median body
   pr_hatbiased,  // Heiken ashi trend biased price
   pr_hatbiased2  // Heiken ashi trend biased (extreme) price
};
enum enFilterWhat
{
   flt_prc,  // Filter the price
   flt_val,  // Filter the step ma
   flt_both  // Filter both
};
enum enRsiTypes
{
   rsi_rsi,  // Regular RSI
   rsi_slo,  // Slow RSI
   rsi_rap,  // Rapid RSI
   rsi_har,  // Harris RSI
   rsi_rsx,  // RSX
   rsi_cut   // Cuttlers RSI
};


extern int    MagicNumber = 123456;  // Magic number to use for the EA
extern bool   EcnBroker   = false;   // Is your broker ECN/STP type of broker?
extern double LotSize     = 0.1;     // Lot size to use for trading
extern int    Slippage    = 3;       // Slipage to use when opening new orders
extern double StopLoss    = 100;     // Initial stop loss (in pips)
extern double TakeProfit  = 100;     // Initial take profit (in pips)

extern string dummy1      = "";      // .
extern string dummy2      = "";      // Settings for indicators
extern int    BarToUse    = 1;       // Bar to test (0, for still opened, 1 for first closed, and so on)
extern enRsiTypes      RsiType            = rsi_rsi;       // RSI calculation method
extern int             RsiLength          = 14;            // Rsi length
extern enPrices        RsiPrice           = pr_close;      // Rsi price
extern double          Sensitivity        = 4;             // Sensivity Factor
extern double          StepSize           = 5;             // Atr step divisor
extern double          Filter             = 0;             // Filter (<=0, no filtering)
extern int             FilterPeriod       = 0;             // Filter period (0<= use rsi period)
extern enFilterWhat    FilterOn           = flt_val;       // Apply filter to :

extern string dummy3      = "";      // .
extern string dummy4      = "";      // General settings
extern bool   DisplayInfo = true;    // Dislay info

bool dummyResult;
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int init()   { return(0); }
int deinit() { return(0); }

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

#define _doNothing 0
#define _doBuy     1
#define _doSell    2
int start()
{
   int doWhat = _doNothing;
      double stepma_trend_current  = iCustom(NULL,0,"StepMA of rsi adaptive tema 1.1",PERIOD_CURRENT,RsiType,RsiLength,RsiPrice,Sensitivity,StepSize,Filter,FilterPeriod,FilterOn,10,BarToUse);
      double stepma_trend_previous = iCustom(NULL,0,"StepMA of rsi adaptive tema 1.1",PERIOD_CURRENT,RsiType,RsiLength,RsiPrice,Sensitivity,StepSize,Filter,FilterPeriod,FilterOn,10,BarToUse+1);
      if (stepma_trend_current!=stepma_trend_previous)
         if (stepma_trend_current==1)
               doWhat = _doBuy;
         else  doWhat = _doSell;
         if (doWhat==_doNothing && !DisplayInfo) return(0);
        
   //
   //
   //
   //
   //
  
   int    openedBuys    = 0;
   int    openedSells   = 0;
   double currentProfit = 0;
   for (int i = OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderSymbol()      != Symbol())            continue;
      if (OrderMagicNumber() != MagicNumber)         continue;

      //
      //
      //
      //
      //
      
      if (DisplayInfo) currentProfit += OrderProfit()+OrderCommission()+OrderSwap();
        
         //
         //
         //
         //
         //
        
         if (OrderType()==OP_BUY)
            if (doWhat==_doSell)
                  { RefreshRates(); if (!OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE)) openedBuys++; }
            else  openedBuys++;
         if (OrderType()==OP_SELL)
            if (doWhat==_doBuy)
                  { RefreshRates(); if (!OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE)) openedSells++; }
            else  openedSells++;            
   }
   if (DisplayInfo) Comment("Current profit : "+DoubleToStr(currentProfit,2)+" "+AccountCurrency()); if (doWhat==_doNothing) return(0);

   //
   //
   //
   //
   //

   if (doWhat==_doBuy && openedBuys==0)
      {
         RefreshRates();
         double stopLossBuy   = 0; if (StopLoss>0)   stopLossBuy   = Ask-StopLoss*Point*MathPow(10,Digits%2);
         double takeProfitBuy = 0; if (TakeProfit>0) takeProfitBuy = Ask+TakeProfit*Point*MathPow(10,Digits%2);
         if (EcnBroker)
         {
            int ticketb = OrderSend(Symbol(),OP_BUY,LotSize,Ask,Slippage,0,0,"",MagicNumber,0,CLR_NONE);
            if (ticketb>-1)
              dummyResult = OrderModify(ticketb,OrderOpenPrice(),stopLossBuy,takeProfitBuy,0,CLR_NONE);
         }
         else dummyResult = OrderSend(Symbol(),OP_BUY,LotSize,Ask,Slippage,stopLossBuy,takeProfitBuy,"",MagicNumber,0,CLR_NONE);
      }
   if (doWhat==_doSell && openedSells==0)
      {
         RefreshRates();
         double stopLossSell   = 0; if (StopLoss>0)   stopLossSell   = Bid+StopLoss*Point*MathPow(10,Digits%2);
         double takeProfitSell = 0; if (TakeProfit>0) takeProfitSell = Bid-TakeProfit*Point*MathPow(10,Digits%2);
         if (EcnBroker)
         {
            int tickets = OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage,0,0,"",MagicNumber,0,CLR_NONE);
            if (tickets>-1)
              dummyResult = OrderModify(tickets,OrderOpenPrice(),stopLossSell,takeProfitSell,0,CLR_NONE);
         }
         else dummyResult = OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage,stopLossSell,takeProfitSell,"",MagicNumber,0,CLR_NONE);
      }
   return(0);
}
 
mntiwana:

Dearest MLADEN

Thanks for early response,do you think all that problems were in tema EA working behavior because of this reason ?

can you plz look in this changed code,as per your advice ,is it right for now ?

regards

//------------------------------------------------------------------
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"
#property strict
//------------------------------------------------------------------

enum enPrices
{
   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low
   pr_median,     // Median
   pr_typical,    // Typical
   pr_weighted,   // Weighted
   pr_average,    // Average (high+low+open+close)/4
   pr_medianb,    // Average median body (open+close)/2
   pr_tbiased,    // Trend biased price
   pr_tbiased2,   // Trend biased (extreme) price
   pr_haclose,    // Heiken ashi close
   pr_haopen ,    // Heiken ashi open
   pr_hahigh,     // Heiken ashi high
   pr_halow,      // Heiken ashi low
   pr_hamedian,   // Heiken ashi median
   pr_hatypical,  // Heiken ashi typical
   pr_haweighted, // Heiken ashi weighted
   pr_haaverage,  // Heiken ashi average
   pr_hamedianb,  // Heiken ashi median body
   pr_hatbiased,  // Heiken ashi trend biased price
   pr_hatbiased2  // Heiken ashi trend biased (extreme) price
};
enum enFilterWhat
{
   flt_prc,  // Filter the price
   flt_val,  // Filter the step ma
   flt_both  // Filter both
};
enum enRsiTypes
{
   rsi_rsi,  // Regular RSI
   rsi_slo,  // Slow RSI
   rsi_rap,  // Rapid RSI
   rsi_har,  // Harris RSI
   rsi_rsx,  // RSX
   rsi_cut   // Cuttlers RSI
};


extern int    MagicNumber = 123456;  // Magic number to use for the EA
extern bool   EcnBroker   = false;   // Is your broker ECN/STP type of broker?
extern double LotSize     = 0.1;     // Lot size to use for trading
extern int    Slippage    = 3;       // Slipage to use when opening new orders
extern double StopLoss    = 100;     // Initial stop loss (in pips)
extern double TakeProfit  = 100;     // Initial take profit (in pips)

extern string dummy1      = "";      // .
extern string dummy2      = "";      // Settings for indicators
extern int    BarToUse    = 1;       // Bar to test (0, for still opened, 1 for first closed, and so on)
extern enRsiTypes      RsiType            = rsi_rsi;       // RSI calculation method
extern int             RsiLength          = 14;            // Rsi length
extern enPrices        RsiPrice           = pr_close;      // Rsi price
extern double          Sensitivity        = 4;             // Sensivity Factor
extern double          StepSize           = 5;             // Atr step divisor
extern double          Filter             = 0;             // Filter (<=0, no filtering)
extern int             FilterPeriod       = 0;             // Filter period (0<= use rsi period)
extern enFilterWhat    FilterOn           = flt_val;       // Apply filter to :

extern string dummy3      = "";      // .
extern string dummy4      = "";      // General settings
extern bool   DisplayInfo = true;    // Dislay info

bool dummyResult;
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int init()   { return(0); }
int deinit() { return(0); }

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

#define _doNothing 0
#define _doBuy     1
#define _doSell    2
int start()
{
   int doWhat = _doNothing;
      double stepma_trend_current  = iCustom(NULL,0,"StepMA of rsi adaptive tema 1.1",PERIOD_CURRENT,RsiType,RsiLength,RsiPrice,Sensitivity,StepSize,Filter,FilterPeriod,FilterOn,10,BarToUse);
      double stepma_trend_previous = iCustom(NULL,0,"StepMA of rsi adaptive tema 1.1",PERIOD_CURRENT,RsiType,RsiLength,RsiPrice,Sensitivity,StepSize,Filter,FilterPeriod,FilterOn,10,BarToUse+1);
      if (stepma_trend_current!=stepma_trend_previous)
         if (stepma_trend_current==1)
               doWhat = _doBuy;
         else  doWhat = _doSell;
         if (doWhat==_doNothing && !DisplayInfo) return(0);
        
   //
   //
   //
   //
   //
  
   int    openedBuys    = 0;
   int    openedSells   = 0;
   double currentProfit = 0;
   for (int i = OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderSymbol()      != Symbol())            continue;
      if (OrderMagicNumber() != MagicNumber)         continue;

      //
      //
      //
      //
      //
      
      if (DisplayInfo) currentProfit += OrderProfit()+OrderCommission()+OrderSwap();
        
         //
         //
         //
         //
         //
        
         if (OrderType()==OP_BUY)
            if (doWhat==_doSell)
                  { RefreshRates(); if (!OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE)) openedBuys++; }
            else  openedBuys++;
         if (OrderType()==OP_SELL)
            if (doWhat==_doBuy)
                  { RefreshRates(); if (!OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE)) openedSells++; }
            else  openedSells++;            
   }
   if (DisplayInfo) Comment("Current profit : "+DoubleToStr(currentProfit,2)+" "+AccountCurrency()); if (doWhat==_doNothing) return(0);

   //
   //
   //
   //
   //

   if (doWhat==_doBuy && openedBuys==0)
      {
         RefreshRates();
         double stopLossBuy   = 0; if (StopLoss>0)   stopLossBuy   = Ask-StopLoss*Point*MathPow(10,Digits%2);
         double takeProfitBuy = 0; if (TakeProfit>0) takeProfitBuy = Ask+TakeProfit*Point*MathPow(10,Digits%2);
         if (EcnBroker)
         {
            int ticketb = OrderSend(Symbol(),OP_BUY,LotSize,Ask,Slippage,0,0,"",MagicNumber,0,CLR_NONE);
            if (ticketb>-1)
              dummyResult = OrderModify(ticketb,OrderOpenPrice(),stopLossBuy,takeProfitBuy,0,CLR_NONE);
         }
         else dummyResult = OrderSend(Symbol(),OP_BUY,LotSize,Ask,Slippage,stopLossBuy,takeProfitBuy,"",MagicNumber,0,CLR_NONE);
      }
   if (doWhat==_doSell && openedSells==0)
      {
         RefreshRates();
         double stopLossSell   = 0; if (StopLoss>0)   stopLossSell   = Bid+StopLoss*Point*MathPow(10,Digits%2);
         double takeProfitSell = 0; if (TakeProfit>0) takeProfitSell = Bid-TakeProfit*Point*MathPow(10,Digits%2);
         if (EcnBroker)
         {
            int tickets = OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage,0,0,"",MagicNumber,0,CLR_NONE);
            if (tickets>-1)
              dummyResult = OrderModify(tickets,OrderOpenPrice(),stopLossSell,takeProfitSell,0,CLR_NONE);
         }
         else dummyResult = OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage,stopLossSell,takeProfitSell,"",MagicNumber,0,CLR_NONE);
      }
   return(0);
}
That could be the cause (because you were setting the indicator one way and it was working from the EA another way)
 

Hello guys,

 

I really need help, i'm building an expert with the waddah attar scalping indicator, the logic is working, all is ok.

Except one thing, as you see in the  backtest screenshot, at each green bar the expert opens a buy, same for the red bars. I want only 1 trade per color change.

What i want is :

INDICATOR TURNS GREEN ---> it opens a buy ---> the buy closes ---> INDICATOR TURNS RED ---> it opens a sell ---> the sell closes ---> repeat

I want only 1 trade per color change.

 

Can someone please come with a simple solution, i use a skeleton i find on the internet, watch the line 1265, the logic comes here.

 

Thanks a lot !

 Backtest waddah scalping

Waddah expert 

 

Dearest MLADEN

How to add an additional comments line at chart under current profit line to show magic number with trade Ticket for the current open trade.

(within this of your EA "simple (stepma of rsi adaptive tema 1.1) EA"

regards

    if (OrderType()==OP_BUY)
            if (doWhat==_doSell)
                  { RefreshRates(); if (!OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE)) openedBuys++; }
            else  openedBuys++;
         if (OrderType()==OP_SELL)
            if (doWhat==_doBuy)
                  { RefreshRates(); if (!OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE)) openedSells++; }
            else  openedSells++;            
   }
   if (DisplayInfo) Comment("Current profit : "+DoubleToStr(currentProfit,2)+" "+AccountCurrency());
   if (DisplayInfo) Comment("MagicNumber,123456");
--------------------------------------------------
   if (doWhat==_doNothing) return(0);

   //
 
mntiwana:

Dearest MLADEN

How to add an additional comments line at chart under current profit line to show magic number with trade Ticket for the current open trade.

(within this of your EA "simple (stepma of rsi adaptive tema 1.1) EA"

regards

    if (OrderType()==OP_BUY)
            if (doWhat==_doSell)
                  { RefreshRates(); if (!OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE)) openedBuys++; }
            else  openedBuys++;
         if (OrderType()==OP_SELL)
            if (doWhat==_doBuy)
                  { RefreshRates(); if (!OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE)) openedSells++; }
            else  openedSells++;            
   }
   if (DisplayInfo) Comment("Current profit : "+DoubleToStr(currentProfit,2)+" "+AccountCurrency());
   if (DisplayInfo) Comment("MagicNumber,123456");
--------------------------------------------------
   if (doWhat==_doNothing) return(0);

   //

Dearest MNTIWANA

like this:

if (DisplayInfo)
    Comment("Current profit : "+DoubleToStr(currentProfit,2)+" "+AccountCurrency()+"\nMagicNumber,123456");

regards

Reason: