Please fix this indicator or EA - page 41

 

...

tkuan77

You are assuming that the 2 crosses (the 10,20 SMA cross and 20,50 SMA cross) will happen on exactly the same bar (and not just the same bar, since the way you have the crosses function check written, they must happen on exactly the same tick), which is a very, very rare occasion (you can check that on the chart too, and you will see that it almost never happens even for bars let alone ticks). You have to change the condition testing and condition combination (try it out with just one condition and you will see what do I mean)

tkuan77:
Hi I did some editing and decided to focus on short trade first just to make things simpler. However, the situation still remains the same. After executing 1 trade, it stop opening new trades. my criteria are there should only be 1 trade open at any point of time and trade will only open when LWMA fast crossed over LWMA slow and SMA fast crossed over SMA slow, both crossed downwards.

My TP is 100pips and SL is 150pips

Please help.

//+------------------------------------------------------------------+

#property copyright "zzz"

//--- input parameters

extern double TakeProfit=1000.0;

extern double Lots=0.01;

extern double StopLoss=1500.0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

int mainCrossed (double mainline1 , double mainline2)

{

static int mainlast_direction = 0;

static int maincurrent_dirction = 0;

if(mainline1>mainline2)maincurrent_dirction = 1; //main up

if(mainline1<mainline2)maincurrent_dirction = 2; //main down

if(maincurrent_dirction != mainlast_direction) //main changed

{

mainlast_direction = maincurrent_dirction;

return (mainlast_direction);

}

else

{

return (0);

}

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_dirction = 0;

if(line1>line2)current_dirction = 1; //up

if(line1<line2)current_dirction = 2; //down

if(current_dirction != last_direction) //changed

{

last_direction = current_dirction;

return (last_direction);

}

else

{

return (0);

}

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

int cnt, ticket, total;

double shortEma, longEma, mainshortEma, mainlongEma;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

shortEma = iMA(NULL,0,10,0,MODE_LWMA,PRICE_CLOSE,0);

longEma = iMA(NULL,0,20,0,MODE_LWMA,PRICE_CLOSE,0);

mainshortEma = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);

mainlongEma = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,0);

int mainisCrossed = mainCrossed (mainshortEma,mainlongEma);

int isCrossed = Crossed (shortEma,longEma);

total = OrdersTotal();

if(total < 1)

{

if(mainisCrossed == 2 && isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,

Bid-TakeProfit*Point,"My EA",12345,0,Red);

return(0);

}

return(0);

}

return(0);

}

//+------------------------------------------------------------------+

Thanks and regards

Terrance
 
mladen:
tkuan77 You are assuming that the 2 crosses (the 10,20 SMA cross and 20,50 SMA cross) will happen on exactly the same bar (and not just the same bar, since the way you have the crosses function check written, they must happen on exactly the same tick), which is a very, very rare occasion (you can check that on the chart too, and you will see that it almost never happens even for bars let alone ticks). You have to change the condition testing and condition combination (try it out with just one condition and you will see what do I mean)

Hi Mladen, I get what you mean. I have tried it out with only one condition and it works, however how do i merge the 2 conditions together? Do i have to group them together or something? Thanks.

 

...

tkuan77

You already did that (this part : if(mainisCrossed == 2 && isCrossed == 2)) and you ran into a problem that the two condition do not happen at the same time. In that condition either mainisCrossed or isCrossed will receive a value of 2, but they will almost never have the value of 2 at the same time, and that is preventing orders opening

You have to "rethink" the entry rules (conditions) and find a combination that is probable (since this condition you are trying to work with is almost not probable)

tkuan77:
Hi Mladen, I get what you mean. I have tried it out with only one condition and it works, however how do i merge the 2 conditions together? Do i have to group them together or something? Thanks.
 
mladen:
tkuan77

You already did that (this part : if(mainisCrossed == 2 && isCrossed == 2)) and you ran into a problem that the two condition do not happen at the same time. In that condition either mainisCrossed or isCrossed will receive a value of 2, but they will almost never have the value of 2 at the same time, and that is preventing orders opening

You have to "rethink" the entry rules (conditions) and find a combination that is probable (since this condition you are trying to work with is almost not probable)

Hi Mladen,

I notice that earlier today and redo this portion. I have created a counter for both the up and down trend portion. E.g. when SMA20 crosses SMA50 upwards the upcounter will increase in value ie ++ and the isCrossed buy condition will only occur when upcounter is higher then 1 and isCrossed = 2. However I am still getting the same error here. Am I still doing the same wrong thing is another manner or is this another new error? Thanks.

//--- input parameters

extern double TakeProfit=1000.0;

extern double Lots=0.01;

extern double StopLoss=1500.0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

int mainCrossed (double mainline1 , double mainline2)

{

static int mainlast_direction = 0;

static int maincurrent_dirction = 0;

if(mainline1>mainline2)maincurrent_dirction = 1; //main up

if(mainline1<mainline2)maincurrent_dirction = 2; //main down

if(maincurrent_dirction != mainlast_direction) //main changed

{

mainlast_direction = maincurrent_dirction;

return (mainlast_direction);

}

else

{

return (0);

}

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_dirction = 0;

if(line1>line2)current_dirction = 1; //up

if(line1<line2)current_dirction = 2; //down

if(current_dirction != last_direction) //changed

{

last_direction = current_dirction;

return (last_direction);

}

else

{

return (0);

}

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

int cnt, ticket, total, downcounter, upcounter;

double shortEma, longEma, mainshortEma, mainlongEma;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

shortEma = iMA(NULL,0,10,0,MODE_LWMA,PRICE_CLOSE,0);

longEma = iMA(NULL,0,20,0,MODE_LWMA,PRICE_CLOSE,0);

mainshortEma = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);

mainlongEma = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,0);

int mainisCrossed = mainCrossed (mainshortEma,mainlongEma);

int isCrossed = Crossed (shortEma,longEma);

total = OrdersTotal();

downcounter = 1;

upcounter = 1;

if(mainisCrossed == 2)

{

downcounter++;

if(total 1)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,

Bid-TakeProfit*Point,"My EA",12345,0,Red);

}

return(0);

}

return(0);

if(mainisCrossed == 1)

{

upcounter++;

if(total 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,

Ask+TakeProfit*Point,"My EA",12345,0,Green);

}

return(0);

}

return(0);

}

//+------------------------------------------------------------------+

 

Please help me with alert

Hi Everyone

Can someone please assist me in creating an alert (popup with sound as well as email alert) for the indicator below.

I would really appreciate your assistance.

Happy trading

pdt330

"/*------------------------------------------------------------------------------------

Name: xSuperTrend MTF.mq4

Copyright ©2011, Xaphod, http://wwww.xaphod.com

Supertrend formula Copyright © Unknown. Someone on the Internets:

UpperLevel=(High+Low)/2+Multiplier*Atr(Period);

LowerLevel=(High+Low)/2-Multiplier*Atr(Period);

Description: MTF SuperTrend Indicator.

Change log:

2011-12-18. Xaphod, v1.01

- Removed dependancy on external indicator for iCustom calls

2011-12-04. Xaphod, v1.00

- First Release

-------------------------------------------------------------------------------------*/

// Indicator properties

#property copyright "Copyright © 2011, Xaphod"

#property link "http://wwww.xaphod.com"

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 DimGray

#property indicator_color2 OrangeRed

#property indicator_color3 MediumSeaGreen

#property indicator_width1 1

#property indicator_width2 2

#property indicator_width3 2

#property indicator_style1 STYLE_DOT

#property indicator_maximum 1

#property indicator_minimum 0

// Constant definitions

#define INDICATOR_NAME "xSuperTrend MTF"

#define INDICATOR_VERSION "v1.01, www.xaphod.com"

// Indicator parameters

extern string Version.Info=INDICATOR_VERSION;

extern string SuperTrend.Settings="——————————————————————————————";

extern int SuperTrend.Period=10; // SuperTrend ATR Period

extern double SuperTrend.Multiplier=1.7; // SuperTrend Multiplier

extern int SuperTrend.TimeFrame=0; // SuperTrend Timeframe

extern bool SuperTrend.AutoTF=True; // Select next higher TF. If TF=M15 then H1 is selected

// Global module varables

double gadUpBuf[];

double gadDnBuf[];

double gadSuperTrend[];

int giTimeFrame;

int giRepaintBars;

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

// function: init()

// Description: Custom indicator initialization function.

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

int init() {

// Set buffers

SetIndexStyle(0, DRAW_LINE);

SetIndexBuffer(0, gadSuperTrend);

SetIndexLabel(0, "SuperTrend");

SetIndexStyle(1, DRAW_LINE);

SetIndexBuffer(1, gadDnBuf);

SetIndexLabel(1, "SuperTrend Down");

SetIndexStyle(2, DRAW_LINE);

SetIndexBuffer(2, gadUpBuf);

SetIndexLabel(2, "SuperTrend Up");

// Set Timeframe

if (SuperTrend.TimeFrame==0)

SuperTrend.TimeFrame=Period();

if (SuperTrend.AutoTF==True)

SuperTrend.TimeFrame=NextHigherTF(Period());

// Calculation call via iCustom

if (SuperTrend.AutoTF==False && SuperTrend.Settings=="") {

giRepaintBars=0;

}

// Higher Time-frame

else if (SuperTrend.TimeFrame!=Period()) {

IndicatorShortName(INDICATOR_NAME+" "+TF2Str(SuperTrend.TimeFrame) +"["+SuperTrend.Period+";"+DoubleToStr(SuperTrend.Multiplier,1)+"]");

giRepaintBars=SuperTrend.TimeFrame/Period()*2+1;

}

// Current Time-frame

else {

IndicatorShortName(INDICATOR_NAME+" "+TF2Str(SuperTrend.TimeFrame) +"["+SuperTrend.Period+";"+DoubleToStr(SuperTrend.Multiplier,1)+"]");

giRepaintBars=0;

}

return(0);

}

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

// function: deinit()

// Description: Custom indicator deinitialization function.

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

int deinit() {

return (0);

}

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

// function: start()

// Description: Custom indicator iteration function.

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

int start() {

int iNewBars, iCountedBars, i;

double dAtr,dUpperLevel, dLowerLevel;

// Get unprocessed ticks

iCountedBars=IndicatorCounted();

if(iCountedBars < 0) return (-1);

if(iCountedBars>0) iCountedBars--;

iNewBars=MathMax(giRepaintBars,Bars-iCountedBars);

for(i=iNewBars; i>=0; i--) {

// Calc SuperTrend Locally

if (SuperTrend.TimeFrame==Period()) {

dAtr = iATR(NULL, 0, SuperTrend.Period, i);

dUpperLevel=(High+Low)/2+SuperTrend.Multiplier*dAtr;

dLowerLevel=(High+Low)/2-SuperTrend.Multiplier*dAtr;

// Set supertrend levels

if (Close>gadSuperTrend && Close<=gadSuperTrend) {

gadSuperTrend=dLowerLevel;

}

else if (Close=gadSuperTrend) {

gadSuperTrend=dUpperLevel;

}

else if (gadSuperTrend<dLowerLevel)

gadSuperTrend=dLowerLevel;

else if (gadSuperTrend>dUpperLevel)

gadSuperTrend=dUpperLevel;

else

gadSuperTrend=gadSuperTrend;

// Draw Histo

gadUpBuf=EMPTY_VALUE;

gadDnBuf=EMPTY_VALUE;

if (Close>gadSuperTrend || (Close==gadSuperTrend && Close>gadSuperTrend))

gadUpBuf=gadSuperTrend;

else if (Close<gadSuperTrend || (Close==gadSuperTrend && Close<gadSuperTrend))

gadDnBuf=gadSuperTrend;

}

// Calc higher TF SuperTrend via iCustom

else {

gadUpBuf=EMPTY_VALUE;

gadDnBuf=EMPTY_VALUE;

gadSuperTrend=iCustom(Symbol(),SuperTrend.TimeFrame,WindowExpertName(),"","",SuperTrend.Period,

SuperTrend.Multiplier,SuperTrend.TimeFrame,False,0,iBarShift(Symbol(), SuperTrend.TimeFrame, Time));

gadDnBuf=iCustom(Symbol(),SuperTrend.TimeFrame,WindowExpertName(),"","",SuperTrend.Period,

SuperTrend.Multiplier,SuperTrend.TimeFrame,False,1,iBarShift(Symbol(), SuperTrend.TimeFrame, Time));

gadUpBuf=iCustom(Symbol(),SuperTrend.TimeFrame,WindowExpertName(),"","",SuperTrend.Period,

SuperTrend.Multiplier,SuperTrend.TimeFrame,False,2,iBarShift(Symbol(), SuperTrend.TimeFrame, Time));

//gadSuperTrend=iCustom(NULL,SuperTrend.TimeFrame,"xSuperTrend","","",SuperTrend.Period,SuperTrend.Multiplier,0,iBarShift(Symbol(), SuperTrend.TimeFrame, Time));

}

}

return(0);

}

//+------------------------------------------------------------------+

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

// function: TF2Str()

// Description: Convert time-frame to a string

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

string TF2Str(int iPeriod) {

switch(iPeriod) {

case PERIOD_M1: return("M1");

case PERIOD_M5: return("M5");

case PERIOD_M15: return("M15");

case PERIOD_M30: return("M30");

case PERIOD_H1: return("H1");

case PERIOD_H4: return("H4");

case PERIOD_D1: return("D1");

case PERIOD_W1: return("W1");

case PERIOD_MN1: return("MN1");

default: return("M"+iPeriod);

}

}

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

// function: NextHigherTF()

// Description: Select the next higher time-frame.

// Note: M15 and M30 both select H1 as next higher TF.

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

int NextHigherTF(int iPeriod) {

if (iPeriod==0) iPeriod=Period();

switch(iPeriod) {

case PERIOD_M1: return(PERIOD_M5);

case PERIOD_M5: return(PERIOD_M15);

case PERIOD_M15: return(PERIOD_H1);

case PERIOD_M30: return(PERIOD_H1);

case PERIOD_H1: return(PERIOD_H4);

case PERIOD_H4: return(PERIOD_D1);

case PERIOD_D1: return(PERIOD_W1);

case PERIOD_W1: return(PERIOD_MN1);

case PERIOD_MN1: return(PERIOD_MN1);

default: return(Period());

}

}"

Files:
 

...

tkuan77

As I already explained : your function that checks the crosses is checking it for every tick. It does not matter how you place the 2 conditions (you just wrote the same conditions in a bit different way, does not matter the counter addition) those 2 conditions (cross of LWMA 10,20 and cross of SMA 20,50) will not happen at the same time so you can not test if both conditions are fulfilled since they are never going to happen at the same tick. You can not try to combine signals that will happen only now and then and expect that they will happen at the same time, since they are not going to.

Change the logic.

For example, try something like :
if (LWMA10 crosses lwma20 up) and (SMA20 greater than SMA50) then buy

if (LWMA10 crosses lwma20 down) and (SMA20 less than SMA50) then sell

But then it is a completely different logic and I can not evaluate it any more since it deviates from your idea. Bit, I will repeat, that your idea to enter when both crosses happen at the same time will not work since they will not happen at the same time

tkuan77:
Hi Mladen,

I notice that earlier today and redo this portion. I have created a counter for both the up and down trend portion. E.g. when SMA20 crosses SMA50 upwards the upcounter will increase in value ie ++ and the isCrossed buy condition will only occur when upcounter is higher then 1 and isCrossed = 2. However I am still getting the same error here. Am I still doing the same wrong thing is another manner or is this another new error? Thanks.

//--- input parameters

extern double TakeProfit=1000.0;

extern double Lots=0.01;

extern double StopLoss=1500.0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

int mainCrossed (double mainline1 , double mainline2)

{

static int mainlast_direction = 0;

static int maincurrent_dirction = 0;

if(mainline1>mainline2)maincurrent_dirction = 1; //main up

if(mainline1<mainline2)maincurrent_dirction = 2; //main down

if(maincurrent_dirction != mainlast_direction) //main changed

{

mainlast_direction = maincurrent_dirction;

return (mainlast_direction);

}

else

{

return (0);

}

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_dirction = 0;

if(line1>line2)current_dirction = 1; //up

if(line1<line2)current_dirction = 2; //down

if(current_dirction != last_direction) //changed

{

last_direction = current_dirction;

return (last_direction);

}

else

{

return (0);

}

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

int cnt, ticket, total, downcounter, upcounter;

double shortEma, longEma, mainshortEma, mainlongEma;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

shortEma = iMA(NULL,0,10,0,MODE_LWMA,PRICE_CLOSE,0);

longEma = iMA(NULL,0,20,0,MODE_LWMA,PRICE_CLOSE,0);

mainshortEma = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);

mainlongEma = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,0);

int mainisCrossed = mainCrossed (mainshortEma,mainlongEma);

int isCrossed = Crossed (shortEma,longEma);

total = OrdersTotal();

downcounter = 1;

upcounter = 1;

if(mainisCrossed == 2)

{

downcounter++;

if(total 1)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,

Bid-TakeProfit*Point,"My EA",12345,0,Red);

}

return(0);

}

return(0);

if(mainisCrossed == 1)

{

upcounter++;

if(total 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,

Ask+TakeProfit*Point,"My EA",12345,0,Green);

}

return(0);

}

return(0);

}

//+------------------------------------------------------------------+
 

...

Posted it here : https://www.mql5.com/en/forum/180648/page255

pdt330:
Hi Everyone

Can someone please assist me in creating an alert (popup with sound as well as email alert) for the indicator below.

I would really appreciate your assistance.

Happy trading

pdt330

"/*------------------------------------------------------------------------------------

Name: xSuperTrend MTF.mq4

Copyright ©2011, Xaphod, http://wwww.xaphod.com

Supertrend formula Copyright © Unknown. Someone on the Internets:

UpperLevel=(High+Low)/2+Multiplier*Atr(Period);

LowerLevel=(High+Low)/2-Multiplier*Atr(Period);

Description: MTF SuperTrend Indicator.

Change log:

2011-12-18. Xaphod, v1.01

- Removed dependancy on external indicator for iCustom calls

2011-12-04. Xaphod, v1.00

- First Release

-------------------------------------------------------------------------------------*/

// Indicator properties

#property copyright "Copyright © 2011, Xaphod"

#property link "http://wwww.xaphod.com"

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 DimGray

#property indicator_color2 OrangeRed

#property indicator_color3 MediumSeaGreen

#property indicator_width1 1

#property indicator_width2 2

#property indicator_width3 2

#property indicator_style1 STYLE_DOT

#property indicator_maximum 1

#property indicator_minimum 0

// Constant definitions

#define INDICATOR_NAME "xSuperTrend MTF"

#define INDICATOR_VERSION "v1.01, www.xaphod.com"

// Indicator parameters

extern string Version.Info=INDICATOR_VERSION;

extern string SuperTrend.Settings="——————————————————————————————";

extern int SuperTrend.Period=10; // SuperTrend ATR Period

extern double SuperTrend.Multiplier=1.7; // SuperTrend Multiplier

extern int SuperTrend.TimeFrame=0; // SuperTrend Timeframe

extern bool SuperTrend.AutoTF=True; // Select next higher TF. If TF=M15 then H1 is selected

// Global module varables

double gadUpBuf[];

double gadDnBuf[];

double gadSuperTrend[];

int giTimeFrame;

int giRepaintBars;

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

// function: init()

// Description: Custom indicator initialization function.

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

int init() {

// Set buffers

SetIndexStyle(0, DRAW_LINE);

SetIndexBuffer(0, gadSuperTrend);

SetIndexLabel(0, "SuperTrend");

SetIndexStyle(1, DRAW_LINE);

SetIndexBuffer(1, gadDnBuf);

SetIndexLabel(1, "SuperTrend Down");

SetIndexStyle(2, DRAW_LINE);

SetIndexBuffer(2, gadUpBuf);

SetIndexLabel(2, "SuperTrend Up");

// Set Timeframe

if (SuperTrend.TimeFrame==0)

SuperTrend.TimeFrame=Period();

if (SuperTrend.AutoTF==True)

SuperTrend.TimeFrame=NextHigherTF(Period());

// Calculation call via iCustom

if (SuperTrend.AutoTF==False && SuperTrend.Settings=="") {

giRepaintBars=0;

}

// Higher Time-frame

else if (SuperTrend.TimeFrame!=Period()) {

IndicatorShortName(INDICATOR_NAME+" "+TF2Str(SuperTrend.TimeFrame) +"["+SuperTrend.Period+";"+DoubleToStr(SuperTrend.Multiplier,1)+"]");

giRepaintBars=SuperTrend.TimeFrame/Period()*2+1;

}

// Current Time-frame

else {

IndicatorShortName(INDICATOR_NAME+" "+TF2Str(SuperTrend.TimeFrame) +"["+SuperTrend.Period+";"+DoubleToStr(SuperTrend.Multiplier,1)+"]");

giRepaintBars=0;

}

return(0);

}

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

// function: deinit()

// Description: Custom indicator deinitialization function.

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

int deinit() {

return (0);

}

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

// function: start()

// Description: Custom indicator iteration function.

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

int start() {

int iNewBars, iCountedBars, i;

double dAtr,dUpperLevel, dLowerLevel;

// Get unprocessed ticks

iCountedBars=IndicatorCounted();

if(iCountedBars < 0) return (-1);

if(iCountedBars>0) iCountedBars--;

iNewBars=MathMax(giRepaintBars,Bars-iCountedBars);

for(i=iNewBars; i>=0; i--) {

// Calc SuperTrend Locally

if (SuperTrend.TimeFrame==Period()) {

dAtr = iATR(NULL, 0, SuperTrend.Period, i);

dUpperLevel=(High+Low)/2+SuperTrend.Multiplier*dAtr;

dLowerLevel=(High+Low)/2-SuperTrend.Multiplier*dAtr;

// Set supertrend levels

if (Close>gadSuperTrend && Close<=gadSuperTrend) {

gadSuperTrend=dLowerLevel;

}

else if (Close=gadSuperTrend) {

gadSuperTrend=dUpperLevel;

}

else if (gadSuperTrend<dLowerLevel)

gadSuperTrend=dLowerLevel;

else if (gadSuperTrend>dUpperLevel)

gadSuperTrend=dUpperLevel;

else

gadSuperTrend=gadSuperTrend;

// Draw Histo

gadUpBuf=EMPTY_VALUE;

gadDnBuf=EMPTY_VALUE;

if (Close>gadSuperTrend || (Close==gadSuperTrend && Close>gadSuperTrend))

gadUpBuf=gadSuperTrend;

else if (Close<gadSuperTrend || (Close==gadSuperTrend && Close<gadSuperTrend))

gadDnBuf=gadSuperTrend;

}

// Calc higher TF SuperTrend via iCustom

else {

gadUpBuf=EMPTY_VALUE;

gadDnBuf=EMPTY_VALUE;

gadSuperTrend=iCustom(Symbol(),SuperTrend.TimeFrame,WindowExpertName(),"","",SuperTrend.Period,

SuperTrend.Multiplier,SuperTrend.TimeFrame,False,0,iBarShift(Symbol(), SuperTrend.TimeFrame, Time));

gadDnBuf=iCustom(Symbol(),SuperTrend.TimeFrame,WindowExpertName(),"","",SuperTrend.Period,

SuperTrend.Multiplier,SuperTrend.TimeFrame,False,1,iBarShift(Symbol(), SuperTrend.TimeFrame, Time));

gadUpBuf=iCustom(Symbol(),SuperTrend.TimeFrame,WindowExpertName(),"","",SuperTrend.Period,

SuperTrend.Multiplier,SuperTrend.TimeFrame,False,2,iBarShift(Symbol(), SuperTrend.TimeFrame, Time));

//gadSuperTrend=iCustom(NULL,SuperTrend.TimeFrame,"xSuperTrend","","",SuperTrend.Period,SuperTrend.Multiplier,0,iBarShift(Symbol(), SuperTrend.TimeFrame, Time));

}

}

return(0);

}

//+------------------------------------------------------------------+

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

// function: TF2Str()

// Description: Convert time-frame to a string

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

string TF2Str(int iPeriod) {

switch(iPeriod) {

case PERIOD_M1: return("M1");

case PERIOD_M5: return("M5");

case PERIOD_M15: return("M15");

case PERIOD_M30: return("M30");

case PERIOD_H1: return("H1");

case PERIOD_H4: return("H4");

case PERIOD_D1: return("D1");

case PERIOD_W1: return("W1");

case PERIOD_MN1: return("MN1");

default: return("M"+iPeriod);

}

}

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

// function: NextHigherTF()

// Description: Select the next higher time-frame.

// Note: M15 and M30 both select H1 as next higher TF.

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

int NextHigherTF(int iPeriod) {

if (iPeriod==0) iPeriod=Period();

switch(iPeriod) {

case PERIOD_M1: return(PERIOD_M5);

case PERIOD_M5: return(PERIOD_M15);

case PERIOD_M15: return(PERIOD_H1);

case PERIOD_M30: return(PERIOD_H1);

case PERIOD_H1: return(PERIOD_H4);

case PERIOD_H4: return(PERIOD_D1);

case PERIOD_D1: return(PERIOD_W1);

case PERIOD_W1: return(PERIOD_MN1);

case PERIOD_MN1: return(PERIOD_MN1);

default: return(Period());

}

}"
 
mladen:
tkuan77

As I already explained : your function that checks the crosses is checking it for every tick. It does not matter how you place the 2 conditions (you just wrote the same conditions in a bit different way, does not matter the counter addition) those 2 conditions (cross of LWMA 10,20 and cross of SMA 20,50) will not happen at the same time so you can not test if both conditions are fulfilled since they are never going to happen at the same tick. You can not try to combine signals that will happen only now and then and expect that they will happen at the same time, since they are not going to.

Change the logic.

For example, try something like :
if (LWMA10 crosses lwma20 up) and (SMA20 greater than SMA50) then buy

if (LWMA10 crosses lwma20 down) and (SMA20 less than SMA50) then sell

But then it is a completely different logic and I can not evaluate it any more since it deviates from your idea. Bit, I will repeat, that your idea to enter when both crosses happen at the same time will not work since they will not happen at the same time

Hi Mladen, I changed my logic like you said and it works~! Thanks for the guidance!

 

Hi, Can someone please enter the arrow when the lines are crossing

Thank you and Best regards !

ICostum JRSX

Files:
 

EA Problem

Hi everyone, I recently downloaded rangeLagma_V2 EA which I found in the thread "Money Making Manual Trading System" - by Darkonix. I'm getting an invalid stoploss error ticket=-1 in my journal and the EA is not opening any orders what so ever. I am using Oanda Broker (ECN, 5 Digit), so maybe it is not sending orders properly because it is not coded for ECN? I'm not sure, hopefully one of you smart gentlemen can help me out, I don't know anything much about coding .

Here is the file: rangelagma_v2.mq4

Thanks in advance!

Files: