Simple experts - page 12

 
Pava:
I have a simple way estimating system...if I take a look @ it and feel even slightly nervous...I forgetaboutit...your picture makes me nervous

Let us make it more comfortable for your ease.

now you can better understand how these filtering out each other,when all two showing any same direction,dont change your mode when any single produce some false/short signal.


 
mladen:

I am not sure that it can be done without over-complicating the whole thing

More or less that would be an EA already, not an indicator, but will see what can be done

Dearest MLADEN

A bit explaining my request/idea.

system 1 = true/false .......         // at one time only one system should be true.

system 2 = true/false

system 1 = check only ma 1

system 2 = check ma 1 + ma 2

when ma one (1) "averages - mtf - alerts 8.4" in orange color (sell/down trend)

condition=check for ma two (2)

if ma two (2) "StepMA of rsi adaptive ema 2.8" in orange color (sell/down trend)

open a sell order/trade.

same in opposite (for buy trade)

hope i explain well my request as an initial start.

regards

 

Hi mladen,

I tried to do an simple EA using simple trend (extended), and I tried to work from the simple EA using StepMA of rsi adaptive ema 2.8.

The EA gets no errors when I compile, but it don't open any trades. I don't know what I did wrong?

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

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 int    ConversionPeriod   = 5;    // Conversion Period
extern int    CalculationPeriod   = 26;    // Calculation Period

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 hull_trend_current  = iCustom(NULL,0,"simple trend (extended)",PERIOD_CURRENT,ConversionPeriod,CalculationPeriod,10,BarToUse);
      double hull_trend_previous = iCustom(NULL,0,"simple trend (extended)",PERIOD_CURRENT,ConversionPeriod,CalculationPeriod,10,BarToUse+1);
      if (hull_trend_current!=hull_trend_previous)
         if (hull_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);
}
 

Hi mladen,
I also tried to make an simple EA from averages - mtf - alerts 8.4.ex4. And I think I understand a bit more now, all parameters from the indicator seem to work in the EA (or the opposite if you like). And now the EA opens order, but something is wrong with how it opens orders. It only opens sell orders, and not when it should.

//------------------------------------------------------------------
#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_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
};



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 int             CustomTF          = 0;            // Custom time frame to use
extern int             AveragePeriod          = 14;            // Average period
extern enPrices        PriceToUse           = pr_close;      // Price to use
extern int             AverageMethod         = 20;            // Average Method
extern bool            DoubleSmoothedAverage = false;    // Double Smoothed Average
extern bool            AdaptiveAverage = false;    // Adaptive Average
extern double          Filter             = 0;             // Filter (<=0, no filtering)
extern int             Filterapplied         = 0;            // Filter should be applied 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 hull_trend_current  = iCustom(NULL,0,"averages - mtf - alerts 8.4",PERIOD_CURRENT,CustomTF,AveragePeriod,PriceToUse,AverageMethod,DoubleSmoothedAverage,AdaptiveAverage,Filter,Filterapplied,10,BarToUse);
      double hull_trend_previous = iCustom(NULL,0,"averages - mtf - alerts 8.4",PERIOD_CURRENT,CustomTF,AveragePeriod,PriceToUse,AverageMethod,DoubleSmoothedAverage,AdaptiveAverage,Filter,Filterapplied,10,BarToUse+1);
      if (hull_trend_current!=hull_trend_previous)
         if (hull_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);
}
 

Hi again :) (sorry for many questions)

What does the number 10 mean in :"double hull_trend_current  = iCustom(NULL,0,"averages - mtf - alerts 8.4",PERIOD_CURRENT,CustomTF,AveragePeriod,PriceToUse,AverageMethod,DoubleSmoothedAverage,AdaptiveAverage,Filter,Filterapplied,10,BarToUse);"

before "BarToUse"? If I change it to 9 in simple EA from averages - mtf - alerts 8.4.ex4 it seems to work?

 
simon_json:

Hi again :) (sorry for many questions)

What does the number 10 mean in :"double hull_trend_current  = iCustom(NULL,0,"averages - mtf - alerts 8.4",PERIOD_CURRENT,CustomTF,AveragePeriod,PriceToUse,AverageMethod,DoubleSmoothedAverage,AdaptiveAverage,Filter,Filterapplied,10,BarToUse);"

before "BarToUse"? If I change it to 9 in simple EA from averages - mtf - alerts 8.4.ex4 it seems to work?

That is the buffer number
 
mladen:
That is the buffer number
Thanks! Is it correct to use number 9 in this example? How do I find the right buffer number?
 
simon_json:
Thanks! Is it correct to use number 9 in this example? How do I find the right buffer number?

Try using the buffers explorer (the attached) - that way you can see how many buffers are there, what are the values in the buffers and what are their numbers of any indicator using default parameters (just enter the name of the indicator you wish to explore and then chose the buffer numbers)


Files:
 
mladen:

Try using the buffers explorer (the attached) - that way you can see how many buffers are there, what are the values in the buffers and what are their numbers of any indicator using default parameters (just enter the name of the indicator you wish to explore and then chose the buffer numbers)


Thanks!
 
mladen:

Try using the buffers explorer (the attached) - that way you can see how many buffers are there, what are the values in the buffers and what are their numbers of any indicator using default parameters (just enter the name of the indicator you wish to explore and then chose the buffer numbers)


Hi mladen,

1. I try to use different timeframes in simple EA and have changed PERIOD_CURRENT to TimeFrame and wrote for TimeFrame;
extern int TimeFrame = 0 //TimeFrame
And it works, if I write 60 in EA it becomes 1H in indicator. But can I do it in some other way, perhaps with enums?
I have looked here:
https://docs.mql4.com/constants/chartconstants/enum_timeframes
and tried a few combinations, but can't get it right. 

2. If I would like to combine two settings or two indicators. For example if both are in downtrend then buy, and if one changes then sell. Is it hard? Can I use two hull_trend in some way?
Is it enough to change something here in the code:

#define _doNothing 0
#define _doBuy     1
#define _doSell    2
int start()
{
   int doWhat = _doNothing;
      double hull_trend_current  = iCustom(NULL,0,"StepMA of rsi adaptive ema 2.8",PERIOD_CURRENT,RsiType,RsiLength,RsiPrice,Sensitivity,StepSize,Filter,FilterPeriod,FilterOn,10,BarToUse);
      double hull_trend_previous = iCustom(NULL,0,"StepMA of rsi adaptive ema 2.8",PERIOD_CURRENT,RsiType,RsiLength,RsiPrice,Sensitivity,StepSize,Filter,FilterPeriod,FilterOn,10,BarToUse+1);
      if (hull_trend_current!=hull_trend_previous)
         if (hull_trend_current==1)
               doWhat = _doBuy;
         else  doWhat = _doSell;
         if (doWhat==_doNothing && !DisplayInfo) return(0);
Reason: