Help adding indicator as filter and to modify EAs - page 2

 

ObjectCreate("1"+sName,2, 0,Time[p],price_p1,Time[0],price_01);

ObjectCreate("0"+sName,2, 0,Time[p],price_p0,Time[0],price_00);

ObjectCreate("2"+sName,2, 0,Time[p],price_p2,Time[0],price_02);

ok i think the "1" is the losest line, the "0" is the middle dotted line, and the "2" is the upper line. I decude that from the fact that when I put my mouse over the lines they each have an object number associated with them and that number is the same except for the first digit.

The three object trendlines are

#01151541601

#11151541601

#21151541601

according to the object list.

 

this indicator has no buffer!!! oy how do you use an indicator in an EA which has no buffer?

 
Aaragorn:
channeling mostly...

actually I have one indicator I think would work....I need help adding it...

https://www.mql5.com/en/forum/general

Aaragorn,

I don't know. I am not guru in coding.

I don't know how to add custom indicator which does not have buffer.

 

is there a good channeling indicator that DOES have a buffer?

 

ok lets see how to make this one work..

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

//| SHI_Channel.mq4 |

//| Copyright © 2004, Shurka & Kevin |

//| |

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

#property copyright "Copyright © 2004, Shurka & Kevin"

#property link ""

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 Red

double ExtMapBuffer1[];

//---- input parameters

extern int AllBars=240;

extern int BarsForFract=0;

int CurrentBar=0;

double Step=0;

int B1=-1,B2=-1;

int UpDown=0;

double P1=0,P2=0,PP=0;

int i=0,AB=300,BFF=0;

int ishift=0;

double iprice=0;

datetime T1,T2;

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_ARROW);

SetIndexArrow(0,164);

SetIndexBuffer(0,ExtMapBuffer1);

SetIndexEmptyValue(0,0.0);

//----

return(0);

}

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

//| Custor indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

void DelObj()

{

ObjectDelete("TL1");

ObjectDelete("TL2");

ObjectDelete("MIDL");

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

//----

if ((AllBars==0) || (Bars<AllBars)) AB=Bars; else AB=AllBars;

if (BarsForFract>0)

BFF=BarsForFract;

else

{

switch (Period())

{

case 1: BFF=12; break;

case 5: BFF=48; break;

case 15: BFF=24; break;

case 30: BFF=24; break;

case 60: BFF=12; break;

case 240: BFF=15; break;

case 1440: BFF=10; break;

case 10080: BFF=6; break;

default: DelObj(); return(-1); break;

}

}

CurrentBar=2;

B1=-1; B2=-1; UpDown=0;

while(((B1==-1) || (B2==-1)) && (CurrentBar<AB))

{

if((UpDown<1) && (CurrentBar==Lowest(Symbol(),Period(),MODE_LOW,BFF*2+1,CurrentBar-BFF)))

{

if(UpDown==0) { UpDown=-1; B1=CurrentBar; P1=Low; }

else { B2=CurrentBar; P2=Low;}

}

if((UpDown>-1) && (CurrentBar==Highest(Symbol(),Period(),MODE_HIGH,BFF*2+1,CurrentBar-BFF)))

{

if(UpDown==0) { UpDown=1; B1=CurrentBar; P1=High; }

else { B2=CurrentBar; P2=High; }

}

CurrentBar++;

}

if((B1==-1) || (B2==-1)) {DelObj(); return(-1);}

Step=(P2-P1)/(B2-B1);

P1=P1-B1*Step; B1=0;

ishift=0; iprice=0;

if(UpDown==1)

{

PP=Low[2]-2*Step;

for(i=3;i<=B2;i++)

{

if(Low<PP+Step*i) { PP=Low-i*Step; }

}

if(Low[0]<PP) {ishift=0; iprice=PP;}

if(Low[1]<PP+Step) {ishift=1; iprice=PP+Step;}

if(High[0]>P1) {ishift=0; iprice=P1;}

if(High[1]>P1+Step) {ishift=1; iprice=P1+Step;}

}

else

{

PP=High[2]-2*Step;

for(i=3;i<=B2;i++)

{

if(High>PP+Step*i) { PP=High-i*Step;}

}

if(Low[0]<P1) {ishift=0; iprice=P1;}

if(Low[1]<P1+Step) {ishift=1; iprice=P1+Step;}

if(High[0]>PP) {ishift=0; iprice=PP;}

if(High[1]>PP+Step) {ishift=1; iprice=PP+Step;}

}

P2=P1+AB*Step;

T1=Time; T2=Time[AB];

if(iprice!=0) ExtMapBuffer1=iprice;

DelObj();

ObjectCreate("TL1",OBJ_TREND,0,T2,PP+Step*AB,T1,PP);

ObjectSet("TL1",OBJPROP_COLOR,Violet);

ObjectSet("TL1",OBJPROP_WIDTH,2);

ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate("TL2",OBJ_TREND,0,T2,P2,T1,P1);

ObjectSet("TL2",OBJPROP_COLOR,Violet);

ObjectSet("TL2",OBJPROP_WIDTH,2);

ObjectSet("TL2",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate("MIDL",OBJ_TREND,0,T2,(P2+PP+Step*AB)/2,T1,(P1+PP)/2);

ObjectSet("MIDL",OBJPROP_COLOR,Violet);

ObjectSet("MIDL",OBJPROP_WIDTH,1);

ObjectSet("MIDL",OBJPROP_STYLE,STYLE_DOT);

Comment(" Channel size = ", DoubleToStr(MathAbs(PP - P1)/Point,0), " Slope = ", DoubleToStr(-Step/Point, 2));

//----

//----

return(0);

}

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

ok following the lesson http://www.metatrader.info/node/137

in his example t3 is holding the indicator calculation value according to his 'code explaination' #3. But once again my my question is that his example is only dealing with one line and this channel indicator is generating 3 lines. All three lines can't be held in one variable. So I can't just say that 'iprice' is holding the calculation value of the indicator. I have to get the calculation values for each line...

ObjectCreate("TL1",OBJ_TREND,0,T2,PP+Step*AB,T1,PP);

ObjectCreate("TL2",OBJ_TREND,0,T2,P2,T1,P1);

so there is a time1 and a price1, a time2 and a price2...are these the endpoints of the line TL1 and TL2?

if these are the endpoints of the lines then is the time2 and price2 values the calculation values which are in the current bar? so I would consider the price2 the calculation value for the lines? PP and P1?

 
Aaragorn:
is there a good channeling indicator that DOES have a buffer?

Many buffers. 7 or 8.

Too many.

But I think it is not that you need.

 

https://www.mql5.com/en/forum/general

I like the trend bands...but which variable do I use to embed it in the EA?

 

ok this one looks like it might fit the purpose from looking at it on the chart...

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

//| Trend Bands.mq4 |

//| Dwt5 and adoleh2000 |

//| Copyright © 2005, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

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

#property copyright "Copyright © 2005, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net"

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

//| Custom indicator initialization function |

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

#property indicator_chart_window

#property indicator_buffers 5

#property indicator_color1 Red

#property indicator_color2 Black

#property indicator_color3 Blue

#property indicator_color4 Red

#property indicator_color5 Blue

double upper[], middle1[], middle2, lower[];

double Xup[], Xdown[];

extern int period = 34;

int init()

{

SetIndexStyle(0,DRAW_LINE,EMPTY,2);

SetIndexShift(0,0);

SetIndexDrawBegin(0,0);

SetIndexBuffer(0,upper);

SetIndexStyle(1,DRAW_LINE,EMPTY,2);

SetIndexShift(1,0);

SetIndexDrawBegin(1,0);

SetIndexBuffer(1,middle1);

SetIndexStyle(2,DRAW_LINE,EMPTY,2);

SetIndexShift(2,0);

SetIndexDrawBegin(2,0);

SetIndexBuffer(2,lower);

SetIndexStyle(3,DRAW_ARROW,EMPTY,2);

SetIndexArrow(3, 162);

SetIndexShift(3,0);

SetIndexDrawBegin(3,0);

SetIndexBuffer(3,Xdown);

SetIndexStyle(4,DRAW_ARROW,EMPTY,2);

SetIndexArrow(4, 162);

SetIndexShift(4,0);

SetIndexDrawBegin(4,0);

SetIndexBuffer(4,Xup);

//---- indicators

//----

return(0);

}

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

//| Custor indicator deinitialization function |

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

int deinit()

{

//---- TODO: add your code here

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start() {

int limit;

int counted_bars=IndicatorCounted();

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

double avg;

for(int x=0; x<limit; x++) {

Xdown[x] = 0; Xup[x] = 0;

middle1[x] = iMA(NULL, 0, period, 0, MODE_EMA, PRICE_TYPICAL, x);// drawn line

middle2= iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

avg = findAvg(period, x);

upper[x] = middle2 + (3.5*avg);

lower[x] = middle2 - (3.5*avg);

if (MathAbs(upper[x] - High[x]) < 2*Point)

{

Xdown[x] = upper[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach upper edge");

}

if (MathAbs(lower[x] - Low[x]) < 2*Point)

{

Xup[x] = lower[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach lower edge");

}

}

return(0);

}

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

double findAvg(int period, int shift) {

double sum=0;

for (int x=shift;x<(shift+period);x++) {

sum += High[x]-Low[x];

}

sum = sum/period;

return (sum);

}

bool NewBar()

{

static datetime dt = 0;

if (dt != Time[0])

{

dt = Time[0];

return(true);

}

return(false);

}

which variables are the lines I see on the chart? upper [x] and lower [x]? what ones do I use to embed this in the EA? could I just use the alert lines to modify the EA rather than give alerts?

 

this is already so big..according to this... http://www.metatrader.info/node/137

I can copy the irreteration functions of the indicator below 'expert start'?

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

//| expert start function |

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

int start()

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

//| Custom indicator iteration function |

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

// Is this where I paste in the indicator??

int limit;

int counted_bars=IndicatorCounted();

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

double avg;

for(int x=0; x<limit; x++) {

Xdown[x] = 0; Xup[x] = 0;

middle1[x] = iMA(NULL, 0, period, 0, MODE_EMA, PRICE_TYPICAL, x);// drawn line

middle2= iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

avg = findAvg(period, x);

upper[x] = middle2 + (3.5*avg);

lower[x] = middle2 - (3.5*avg);

if (MathAbs(upper[x] - High[x]) < 2*Point)

{

Xdown[x] = upper[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach upper edge");

}

if (MathAbs(lower[x] - Low[x]) < 2*Point)

{

Xup[x] = lower[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach lower edge");

}

}

return(0);

}

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

//end of trend band indicator

{

if(Hour() >= StartHour && Hour() <= StopHour){ //Nothing will happen unless the time is within the trading time

int cnt, ticket, total;

double SEma, LEma, SEmaLAST, LEmaLAST;

string comment = "";

if(reversal==true) comment = "EMA_CROSS_Counter-Trend";

if(reversal==false) comment = "EMA_CROSS_Trend-Following";

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<1)

{

Print("TakeProfit less than 1");

return(0); // check TakeProfit

}

static int isCrossed = 0;

if(ConfirmedOnEntry)

{

if(CheckValueTime==iTime(NULL,TimeFrame,0)) return(0); else CheckValueTime = iTime(NULL,TimeFrame,0);

SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,1);

LEma = iMA(NULL,0,LongEma ,0,MODE_EMA,PRICE_CLOSE,1);

SEmaLAST = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,2);

LEmaLAST = iMA(NULL,0,LongEma ,0,MODE_EMA,PRICE_CLOSE,2);

if(SEmaLASTLEma) isCrossed = 1;

if(SEmaLAST>LEmaLAST && SEma<LEma) isCrossed = 2;

}

else

{

SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);

LEma = iMA(NULL,0,LongEma ,0,MODE_EMA,PRICE_CLOSE,0);

isCrossed = Crossed (LEma,SEma);

}

if(reversal==false)

{

if(isCrossed==1) isCrossed = 2;

else if(isCrossed==2) isCrossed = 1;

}

if(MM==true) Lots = LotSize(); //Adjust the lot size

total = OrdersTotal();

// TRAILING STOP

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())

{

if(OrderType()==OP_BUY) // long position is opened

{

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else // go to short position

{

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

// ENTRY

//Somewhere here I think is where I have to make the condition for filtering based //on the Trend Bands Indicator.

if(total < 2 || isNewSumbol(Symbol())) //I have modified the if condition too: it was total<1 (orBanAway aka cucurucu)

{

double HedgeLots = (HedgePercent/100)*Lots; //calculates the Lots for the hedged position

if(isCrossed == 1)

{

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);

else

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,comment,MAGICMA,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());

//###################################################################### the added code starts here

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);

else

ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,0,Bid-TakeProfit*Point,comment,MAGICMA,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());

//###################################################################### ends here

return(0);

}

if(isCrossed == 2)

{

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);

else

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,comment,MAGICMA,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());

//###################################################################### the added code starts here

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_BUY,HedgeLots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);

else

ticket=OrderSend(Symbol(),OP_BUY,HedgeLots,Ask,3,0,Ask+TakeProfit*Point,comment,MAGICMA,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());

//###################################################################### ends here

return(0);

}

return(0);

}

return(0);

}

return(0);

}

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

//| EMA_CROSS_2.mq4 |

//| Coders Guru |

//| https://www.forex-tsd.com |

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

// ultima versiune cu micro lots! H1 si D1

#property copyright "Coders Guru"

#property link "https://www.forex-tsd.com"

//---- Trades limits

extern double

TakeProfit = 10,

TrailingStop = 20,

StopLoss = 20;

extern bool

UseStopLoss = false;

//---- EMAs paris

extern int

ShortEma = 1,

LongEma = 5;

//---- Crossing options

extern bool

immediate_trade = true, //Open trades immediately or wait for cross.

reversal = false, //Use the originally reversal crossing method or not

ConfirmedOnEntry = false;

//---- Money Management

extern double

Lots = 1,

HedgePercent = 1; // Used to calcualte the what percent of the lots the user wants to be

// used in the hedged position

extern bool

MM = true, //Use Money Management or not

AccountIsMicro = true; //Use Micro-Account or not

extern int

StartHour = 0, //Indicates when the user wants the EA to start trading

StopHour = 23; //Indicates when the user wants the EA to stop trading

extern int

Risk = 10; //10%

extern int

MAGICMA = 20060301;

extern bool

Show_Settings = true;

//---- Global varaibles

static int

TimeFrame = 0;

datetime

CheckValueTime;

//---- Trend bands

double upper[], middle1[], middle2, lower[];

double Xup[], Xdown[];

extern int period = 34;

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

//| expert initialization function |

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

int init()

{

if(Show_Settings) Print_Details();

else Comment("");

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

TimeFrame=Period(); //Prevent counting the cross while the user changing the timeframe

return(0);

}

bool isNewSumbol(string current_symbol)

{

//loop through all the opened order and compare the symbols

int total = OrdersTotal();

for(int cnt = 0 ; cnt < total ; cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

string selected_symbol = OrderSymbol();

if (current_symbol == selected_symbol)

return (False);

}

return (True);

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 0;

if(TimeFrame!=Period())

{

TimeFrame=Period();

return (0);

}

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

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

if(immediate_trade==false)

{

if(last_direction == 0) //first use

{

last_direction = current_direction;

return(0);

}

}

if(current_direction != last_direction) //changed

{

last_direction = current_direction;

return (last_direction);

}

else

{

return (0); //not changed

}

}

//--- Bassed on Alex idea! More ideas are coming

double LotSize()

{

double lotMM = MathCeil(AccountFreeMargin() * Risk / 1000) / 100;

if(AccountIsMicro==false) //normal account

{

if (lotMM < 0.1) lotMM = Lots;

if ((lotMM > 0.5) && (lotMM < 1)) lotMM=0.5;

if (lotMM > 1.0) lotMM = MathCeil(lotMM);

if (lotMM > 100) lotMM = 100;

}

else //micro account

{

if (lotMM < 0.01) lotMM = Lots;

if (lotMM > 1.0) lotMM = MathCeil(lotMM);

if (lotMM > 100) lotMM = 100;

}

return (lotMM);

}

string BoolToStr ( bool value)

{

if(value) return ("True");

else return ("False");

}

void Print_Details()

{

string sComment = "";

string sp = "----------------------------------------\n";

string NL = "\n";

sComment = sp;

sComment = sComment + "TakeProfit=" + DoubleToStr(TakeProfit,0) + " | ";

sComment = sComment + "TrailingStop=" + DoubleToStr(TrailingStop,0) + " | ";

sComment = sComment + "StopLoss=" + DoubleToStr(StopLoss,0) + " | ";

sComment = sComment + "UseStopLoss=" + BoolToStr(UseStopLoss) + NL;

sComment = sComment + sp;

sComment = sComment + "immediate_trade=" + BoolToStr(immediate_trade) + " | ";

sComment = sComment + "reversal=" + BoolToStr(reversal) + NL;

sComment = sComment + sp;

sComment = sComment + "Lots=" + DoubleToStr(Lots,0) + " | ";

sComment = sComment + "MM=" + BoolToStr(MM) + " | ";

sComment = sComment + "Risk=" + DoubleToStr(Risk,0) + "%" + NL;

sComment = sComment + sp;

Comment(sComment);

}

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

//| expert start function |

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

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

//| Custom indicator iteration function |

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

int start() {

int limit;

int counted_bars=IndicatorCounted();

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

double avg;

for(int x=0; x<limit; x++) {

Xdown[x] = 0; Xup[x] = 0;

middle1[x] = iMA(NULL, 0, period, 0, MODE_EMA, PRICE_TYPICAL, x);// drawn line

middle2= iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

avg = findAvg(period, x);

upper[x] = middle2 + (3.5*avg);

lower[x] = middle2 - (3.5*avg);

if (MathAbs(upper[x] - High[x]) < 2*Point)

{

Xdown[x] = upper[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach upper edge");

}

if (MathAbs(lower[x] - Low[x]) < 2*Point)

{

Xup[x] = lower[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach lower edge");

}

}

return(0);

}

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

double findAvg(int period, int shift) {

double sum=0;

for (int x=shift;x<(shift+period);x++) {

sum += High[x]-Low[x];

}

sum = sum/period;

return (sum);

}

bool NewBar()

{

static datetime dt = 0;

if (dt != Time[0])

{

dt = Time[0];

return(true);

}

return(false);

//end of trend bands indicator

{

if(Hour() >= StartHour && Hour() <= StopHour){ //Nothing will happen unless the time is within the trading time

int cnt, ticket, total;

double SEma, LEma, SEmaLAST, LEmaLAST;

string comment = "";

if(reversal==true) comment = "EMA_CROSS_Counter-Trend";

if(reversal==false) comment = "EMA_CROSS_Trend-Following";

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<1)

{

Print("TakeProfit less than 1");

return(0); // check TakeProfit

}

static int isCrossed = 0;

if(ConfirmedOnEntry)

{

if(CheckValueTime==iTime(NULL,TimeFrame,0)) return(0); else CheckValueTime = iTime(NULL,TimeFrame,0);

SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,1);

LEma = iMA(NULL,0,LongEma ,0,MODE_EMA,PRICE_CLOSE,1);

SEmaLAST = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,2);

LEmaLAST = iMA(NULL,0,LongEma ,0,MODE_EMA,PRICE_CLOSE,2);

if(SEmaLASTLEma) isCrossed = 1;

if(SEmaLAST>LEmaLAST && SEma<LEma) isCrossed = 2;

}

else

{

SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);

LEma = iMA(NULL,0,LongEma ,0,MODE_EMA,PRICE_CLOSE,0);

isCrossed = Crossed (LEma,SEma);

}

if(reversal==false)

{

if(isCrossed==1) isCrossed = 2;

else if(isCrossed==2) isCrossed = 1;

}

if(MM==true) Lots = LotSize(); //Adjust the lot size

total = OrdersTotal();

// TRAILING STOP

no errors so far from the compiler..

Reason: