![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi all, I have this particular error with my EA on Stocastic.
This is my criteria is like this:
When my stocEquator crosses up (Uptrend), only long will be triggered when my stocTrigger crosses up and when stocEquator crosses down (Downtrend), only short will be triggered when stocTrigger crosses down.
However, when I run the EA for testing, there are no trades triggered and was wondering what could be the problem here and would appreciate if someone can help me out here.
Thank you in advance for the help.
Regards
Terrance
int isCrossedTrigger= 0;
double shortStoc1Trigger= iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,1);
double longStoc1Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2Trigger= iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,2);
double longStoc2Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,2);
double diff1Trigger= shortStoc1Trigger-longStoc1Trigger;
double diff2Trigger= shortStoc2Trigger-longStoc2Trigger;
if ((diff1Trigger*diff2Trigger)<0)
{
if (shortStoc1Trigger>longStoc1Trigger)
isCrossedTrigger= 1;
else isCrossedTrigger= 2;
}
int isCrossedEquator = 0;
double shortStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN,1);
double longStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN,2);
double longStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,2);
double diff1Equator = shortStoc1Equator-longStoc1Equator;
double diff2Equator = shortStoc2Equator-longStoc2Equator;
if ((diff1Equator*diff2Equator)<0)
{
if (shortStoc1Equator>longStoc1Equator)
isCrossedEquator = 1;
else isCrossedEquator = 2;
}
if(total < 2)
{
if(isCrossedTrigger== 1 && isCrossedEquator == 1)
{
Buy
}
if(isCrossedTrigger== 2 && isCrossedEquator == 2)
{
Sell
}
return(0);
}
return(0);
Hi all, I have this particular error with my EA on Stocastic.
This is my criteria is like this:
When my stocEquator crosses up (Uptrend), only long will be triggered when my stocTrigger crosses up and when stocEquator crosses down (Downtrend), only short will be triggered when stocTrigger crosses down.
However, when I run the EA for testing, there are no trades triggered and was wondering what could be the problem here and would appreciate if someone can help me out here.
Thank you in advance for the help.
Regards
Terrance
int isCrossedTrigger= 0;
double shortStoc1Trigger= iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,1);
double longStoc1Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2Trigger= iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,2);
double longStoc2Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,2);
double diff1Trigger= shortStoc1Trigger-longStoc1Trigger;
double diff2Trigger= shortStoc2Trigger-longStoc2Trigger;
if ((diff1Trigger*diff2Trigger)<0)
{
if (shortStoc1Trigger>longStoc1Trigger)
isCrossedTrigger= 1;
else isCrossedTrigger= 2;
}
int isCrossedEquator = 0;
double shortStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN,1);
double longStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN,2);
double longStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,2);
double diff1Equator = shortStoc1Equator-longStoc1Equator;
double diff2Equator = shortStoc2Equator-longStoc2Equator;
if ((diff1Equator*diff2Equator)<0)
{
if (shortStoc1Equator>longStoc1Equator)
isCrossedEquator = 1;
else isCrossedEquator = 2;
}
if(total < 2)
{
if(isCrossedTrigger== 1 && isCrossedEquator == 1)
{
Buy
}
if(isCrossedTrigger== 2 && isCrossedEquator == 2)
{
Sell
}
return(0);
}
return(0);Terrance
The only thing I could no check is the "total" variable
The code should work if the total variable is set properly. Here is a test indicator I used with your conditions and it is raising valid buy and sell signals (run the indicator in visual mode and you will see when it alerts) so the error is somewhere else
#property indicator_buffers 0
//------------------------------------------------------------------
//
//------------------------------------------------------------------
int init()
{
return(0);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
int start()
{
int total = 0;
int isCrossedTrigger= 0;
double shortStoc1Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,1);
double longStoc1Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,1) ;
double shortStoc2Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,2);
double longStoc2Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,2) ;
double diff1Trigger = shortStoc1Trigger-longStoc1Trigger;
double diff2Trigger = shortStoc2Trigger-longStoc2Trigger;
if ((diff1Trigger*diff2Trigger)<0)
{
if (shortStoc1Trigger>longStoc1Trigger)
isCrossedTrigger= 1;
else isCrossedTrigger= 2;
}
int isCrossedEquator = 0;
double shortStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN, 1);
double longStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN, 2);
double longStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,2);
double diff1Equator = shortStoc1Equator-longStoc1Equator;
double diff2Equator = shortStoc2Equator-longStoc2Equator;
if ((diff1Equator*diff2Equator)<0)
{
if (shortStoc1Equator>longStoc1Equator)
isCrossedEquator = 1;
else isCrossedEquator = 2;
}
//
//
//
//
//
if(total < 2)
{
if(isCrossedTrigger== 1 && isCrossedEquator == 1)
{
Alert("Buy at : "+TimeToStr(Time[0],TIME_DATE|TIME_SECONDS));
}
if(isCrossedTrigger== 2 && isCrossedEquator == 2)
{
Alert("Sell at : "+TimeToStr(Time[0],TIME_DATE|TIME_SECONDS));
}
}
return(0);
}Hi mladen, thanks for the highlight. I went back and have a look at my codes and could not figure out what you meant by "total" variable. What could be the caused of my error?
Regards
Terrance
//+------------------------------------------------------------------+
//| My_First_EA.mq4 |
//| TK|
//| MetaTrader 4 Trading Platform / MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "TK"
#property link "http://www.metaquotes.net"
//--- input parameters
extern double TakeProfit=500.0;
extern double Lots=0.1;
extern double StopLoss=500.0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
datetime newbar;
int start()
{
if(newbar==Time[0])return(0);
else newbar=Time[0];
int ticket, total;
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0);
}
//+------------------------------------------------------------------+
//| expert start function | Stochastic Trigger
//+------------------------------------------------------------------+
// shortStoc = iStochastic(NULL,0,7,15,17,MODE_LWMA,0,MODE_MAIN,0); //orignial Stoc movement
// longStoc = iStochastic(NULL,0,7,15,17,MODE_LWMA,0,MODE_SIGNAL,0); //orignial Stoc movement
//+--------------------------------------------------------------------------------------+
//| expert start function | Set trigger trade only when line crossed and candle closed |//
//+--------------------------------------------------------------------------------------+
int isCrossed = 0;
double shortStoc1 = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,1);
double longStoc1 = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2 = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,2);
double longStoc2 = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,2);
double diff1 = shortStoc1-longStoc1;
double diff2 = shortStoc2-longStoc2;
if ((diff1*diff2)<0)
{
if (shortStoc1>longStoc1)
isCrossed = 1;
else isCrossed = 2;
}
// Equator Stoc Start -------------------------------------
int isCrossedEquator = 0;
double shortStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN,1);
double longStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN,2);
double longStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,2);
double diff1Equator = shortStoc1Equator-longStoc1Equator;
double diff2Equator = shortStoc2Equator-longStoc2Equator;
if ((diff1Equator*diff2Equator)<0)
{
if (shortStoc1Equator>longStoc1Equator)
isCrossedEquator = 1;
else isCrossedEquator = 2;
}
// Equator Stoc End -------------------------------------
//+------------------------------------------------------------------------------------+
//| expert end function | Set trigger trade only when line crossed and candle closed |//
//+------------------------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| expert end function | Stochastic Trigger
//+------------------------------------------------------------------+
//| expert start function | Trigger order
//+------------------------------------------------------------------------------------------------------------+
total = OrdersTotal();
if(total < 2) //restrict the number of trades opened
{
if(isCrossed == 1 && isCrossedEquator == 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,Ask-StopLoss*Point,Ask+TakeProfit*Point,
"My EA",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(isCrossed == 2 && isCrossedEquator == 2)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,Bid+StopLoss*Point,Bid-TakeProfit*Point,
"My EA",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
return(0);
}
//+------------------------------------------------------------------+
//| expert end function |
//+------------------------------------------------------------------+
Terrance
The only thing I could no check is the "total" variable
The code should work if the total variable is set properly. Here is a test indicator I used with your conditions and it is raising valid buy and sell signals (run the indicator in visual mode and you will see when it alerts) so the error is somewhere else
#property indicator_buffers 0
//------------------------------------------------------------------
//
//------------------------------------------------------------------
int init()
{
return(0);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
int start()
{
int total = 0;
int isCrossedTrigger= 0;
double shortStoc1Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,1);
double longStoc1Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,1) ;
double shortStoc2Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,2);
double longStoc2Trigger = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,2) ;
double diff1Trigger = shortStoc1Trigger-longStoc1Trigger;
double diff2Trigger = shortStoc2Trigger-longStoc2Trigger;
if ((diff1Trigger*diff2Trigger)<0)
{
if (shortStoc1Trigger>longStoc1Trigger)
isCrossedTrigger= 1;
else isCrossedTrigger= 2;
}
int isCrossedEquator = 0;
double shortStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN, 1);
double longStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN, 2);
double longStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,2);
double diff1Equator = shortStoc1Equator-longStoc1Equator;
double diff2Equator = shortStoc2Equator-longStoc2Equator;
if ((diff1Equator*diff2Equator)<0)
{
if (shortStoc1Equator>longStoc1Equator)
isCrossedEquator = 1;
else isCrossedEquator = 2;
}
//
//
//
//
//
if(total < 2)
{
if(isCrossedTrigger== 1 && isCrossedEquator == 1)
{
Alert("Buy at : "+TimeToStr(Time[0],TIME_DATE|TIME_SECONDS));
}
if(isCrossedTrigger== 2 && isCrossedEquator == 2)
{
Alert("Sell at : "+TimeToStr(Time[0],TIME_DATE|TIME_SECONDS));
}
}
return(0);
}Hi mladen, thanks for the highlight. I went back and have a look at my codes and could not figure out what you meant by "total" variable. What could be the caused of my error?
Regards
Terrance
//+------------------------------------------------------------------+
//| My_First_EA.mq4 |
//| TK|
//| MetaTrader 4 Trading Platform / MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "TK"
#property link "http://www.metaquotes.net"
//--- input parameters
extern double TakeProfit=500.0;
extern double Lots=0.1;
extern double StopLoss=500.0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
datetime newbar;
int start()
{
if(newbar==Time[0])return(0);
else newbar=Time[0];
int ticket, total;
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0);
}
//+------------------------------------------------------------------+
//| expert start function | Stochastic Trigger
//+------------------------------------------------------------------+
// shortStoc = iStochastic(NULL,0,7,15,17,MODE_LWMA,0,MODE_MAIN,0); //orignial Stoc movement
// longStoc = iStochastic(NULL,0,7,15,17,MODE_LWMA,0,MODE_SIGNAL,0); //orignial Stoc movement
//+--------------------------------------------------------------------------------------+
//| expert start function | Set trigger trade only when line crossed and candle closed |//
//+--------------------------------------------------------------------------------------+
int isCrossed = 0;
double shortStoc1 = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,1);
double longStoc1 = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2 = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_MAIN,2);
double longStoc2 = iStochastic(NULL,0,3,5,7,MODE_SMA,0,MODE_SIGNAL,2);
double diff1 = shortStoc1-longStoc1;
double diff2 = shortStoc2-longStoc2;
if ((diff1*diff2)<0)
{
if (shortStoc1>longStoc1)
isCrossed = 1;
else isCrossed = 2;
}
// Equator Stoc Start -------------------------------------
int isCrossedEquator = 0;
double shortStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN,1);
double longStoc1Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_MAIN,2);
double longStoc2Equator = iStochastic(NULL,0,10,100,20,MODE_SMA,0,MODE_SIGNAL,2);
double diff1Equator = shortStoc1Equator-longStoc1Equator;
double diff2Equator = shortStoc2Equator-longStoc2Equator;
if ((diff1Equator*diff2Equator)<0)
{
if (shortStoc1Equator>longStoc1Equator)
isCrossedEquator = 1;
else isCrossedEquator = 2;
}
// Equator Stoc End -------------------------------------
//+------------------------------------------------------------------------------------+
//| expert end function | Set trigger trade only when line crossed and candle closed |//
//+------------------------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| expert end function | Stochastic Trigger
//+------------------------------------------------------------------+
//| expert start function | Trigger order
//+------------------------------------------------------------------------------------------------------------+
total = OrdersTotal();
if(total < 2) //restrict the number of trades opened
{
if(isCrossed == 1 && isCrossedEquator == 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,Ask-StopLoss*Point,Ask+TakeProfit*Point,
"My EA",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(isCrossed == 2 && isCrossedEquator == 2)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,Bid+StopLoss*Point,Bid-TakeProfit*Point,
"My EA",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
return(0);
}
//+------------------------------------------------------------------+
//| expert end function |
//+------------------------------------------------------------------+Terrance
In my tests that EA works
Here is the test result plus the back test report. Tested on 1 minute time frame
Hi all, pls can someone just help me with this code below,,,,it continuing giving me sound alert at every tick instead of only when the trading required conditions are triggered! I ndont want the alert to be sound at every tick or when new candlestick are forming.
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters
extern int ADXbars=14;
extern int CountBars=350;
//---- buffers
double val1[];
double val2[];
double b4plusdi,nowplusdi,b4minusdi,nowminusdi;
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int init()
{
//-- indicator short name
IndicatorShortName("PipsdatorPro1("+Symbol()+")");
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexBuffer(0,val1);
SetIndexBuffer(1,val2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| AltrTrend_Signal_v2_2 |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>=Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars);
SetIndexDrawBegin(1,Bars-CountBars);
int i,shift,counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=CountBars;i++) val1[CountBars-i]=0.0;
for(i=1;i<=CountBars;i++) val2[CountBars-i]=0.0;
}
for (shift = CountBars; shift>=0; shift--)
{
b4plusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,shift-1);
nowplusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,shift);
b4minusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,shift-1);
nowminusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,shift);
if (b4plusdi>b4minusdi && nowplusdi<nowminusdi && i!=1)
{
val1[shift]=Low[shift]-5*Point;
// Alert("Buy Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());
i++;
}
if (b4plusdinowminusdi && i!=1)
{
val2[shift]=High[shift]+5*Point;
// Alert("Sell Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());
i++;
}
}
return(0);
}
//+---------------------------------------------------------------+
Hi all, pls can someone just help me with this code below,,,,it continuing giving me sound alert at every tick instead of only when the trading required conditions are triggered! I ndont want the alert to be sound at every tick or when new candlestick are forming.
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters
extern int ADXbars=14;
extern int CountBars=350;
//---- buffers
double val1[];
double val2[];
double b4plusdi,nowplusdi,b4minusdi,nowminusdi;
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int init()
{
//-- indicator short name
IndicatorShortName("PipsdatorPro1("+Symbol()+")");
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexBuffer(0,val1);
SetIndexBuffer(1,val2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| AltrTrend_Signal_v2_2 |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>=Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars);
SetIndexDrawBegin(1,Bars-CountBars);
int i,shift,counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=CountBars;i++) val1[CountBars-i]=0.0;
for(i=1;i<=CountBars;i++) val2[CountBars-i]=0.0;
}
for (shift = CountBars; shift>=0; shift--)
{
b4plusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,shift-1);
nowplusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,shift);
b4minusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,shift-1);
nowminusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,shift);
if (b4plusdi>b4minusdi && nowplusdi<nowminusdi && i!=1)
{
val1[shift]=Low[shift]-5*Point;
// Alert("Buy Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());
i++;
}
if (b4plusdinowminusdi && i!=1)
{
val2[shift]=High[shift]+5*Point;
// Alert("Sell Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());
i++;
}
}
return(0);
}
//+---------------------------------------------------------------+Mastercash, there is a version of that indicator here https://www.mql5.com/en/forum/173574/page320 maybe it will help.
Terrance
In my tests that EA works
Here is the test result plus the back test report. Tested on 1 minute time frameHi mladen, I have re-reviewed the code according to your comments and I noticed that the trade will only triggered when both of my stocastic lines triggered upwards or downwards at the same candle.
However, what I am trying to accomplish is that if the equator indicator is crossing up indicating uptrend, the EA will trigger only long when the fast indicator triggered upwards and vice versa instead of having both the equator and fast indicator triggered in the same direction at the same candle.
I had tried to tune the EA to suit that criteria but was not able to get the desired results. Is there something I am doing wrong? Please help. Thanks again.
Regards
Terrance
Hi mladen, I have re-reviewed the code according to your comments and I noticed that the trade will only triggered when both of my stocastic lines triggered upwards or downwards at the same candle.
However, what I am trying to accomplish is that if the equator indicator is crossing up indicating uptrend, the EA will trigger only long when the fast indicator triggered upwards and vice versa instead of having both the equator and fast indicator triggered in the same direction at the same candle.
I had tried to tune the EA to suit that criteria but was not able to get the desired results. Is there something I am doing wrong? Please help. Thanks again.
Regards
TerranceTerrance
You will probably have to write a custom indicatyor to accomplish that (some things in EAs you simply can not do the same way you do it indicators)
Terrance You will probably have to write a custom indicatyor to accomplish that (some things in EAs you simply can not do the same way you do it indicators)
Hi mladen, 1 thing I do not understand is that why I am able to do this with MA and not iMA despite it being the same kind of criteria? Could it be some form of indicator settings?
Regards
Terrance
Hi mladen, 1 thing I do not understand is that why I am able to do this with MA and not iMA despite it being the same kind of criteria? Could it be some form of indicator settings?
Regards
Terrancebecause with custom indicator you can save states (trends) between the two ticks, and when you use iMA you can not (just one example)