MQL4 Learning - page 56

 

How can I change an Indicator from Close to Open cours

Hallo,

Im a newbie, an hope somebody can help me here to solve

my Problem in Metatrader 4.

I have an Indicator which I use as a filter. But I would like

to change it from close to open to get only open-signals.

I can't find parameters in the code to change it.

So please help me !

Thanks for your effort.

 
 

here is the indicator, many thanks

#property indicator_separate_window

#property indicator_buffers 5

#property indicator_color1 Yellow

#property indicator_color2 LimeGreen

#property indicator_color3 Red

#property indicator_color4 Yellow

#property indicator_color5 Cyan

#property indicator_width1 2

#property indicator_width2 2

#property indicator_width3 2

extern bool Crash = false;

extern int TimeFrame = 0;

extern int Length = 5;

extern int Method = 2;

extern int Smoothing = 6;

extern int Filter = 5;

extern bool RealTime = true;

extern bool Steady = false;

extern bool Color = true;

extern bool Alerts = true;

extern bool EmailON = false;

extern bool SignalPrice = true;

extern color SignalPriceBUY = Yellow;

extern color SignalPriceSELL = Aqua;

extern int CountBars = 1485;

double fxlive[];

double fxlive_MTF[];

double DIR[];

double UpBuffer[];

double DnBuffer[];

double UpArrow[];

double DnArrow[];

bool TurnedUp = false;

bool TurnedDn = false;

datetime timeprev1=0;

datetime timeprev2=0;

int p=0;

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

int init()

{

IndicatorBuffers(8);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);

SetIndexBuffer(0,fxlive);

SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);

SetIndexBuffer(1,UpBuffer);

SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);

SetIndexBuffer(2,DnBuffer);

SetIndexStyle(3,DRAW_ARROW);

SetIndexArrow(3,233);

SetIndexBuffer(3,UpArrow);

SetIndexStyle(4,DRAW_ARROW);

SetIndexArrow(4,234);

SetIndexBuffer(4,DnArrow);

SetIndexBuffer(5,fxlive);

SetIndexBuffer(6,DIR);

SetIndexBuffer(7,fxlive_MTF);

if (Length < 2) Length = 2;

if (Method < 0) Method = 0;

if (Method > 3) Method = 3;

if (Smoothing < 0) Smoothing = 0;

if (Filter < 0) Filter = 0;

if ((TimeFrame < Period()) && (TimeFrame != 0)) TimeFrame = Period();

switch(TimeFrame)

{

case 1: string TimeFrameStr = "M1"; break;

case 5: TimeFrameStr = "M5"; break;

case 15: TimeFrameStr = "M15"; break;

case 30: TimeFrameStr = "M30"; break;

case 60: TimeFrameStr = "H1"; break;

case 240: TimeFrameStr = "H4"; break;

case 1440: TimeFrameStr = "D1"; break;

case 10080: TimeFrameStr = "W1"; break;

case 43200: TimeFrameStr = "MN1"; break;

default: TimeFrameStr = "";

}

string short_name = "fxlive" + TimeFrameStr + " | " + Length + " , " + Method + " , " + Smoothing + " , " + Filter + " | ";

IndicatorShortName(short_name);

return(0);

}

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

int start()

{

if (Bars < 100) {IndicatorShortName("Bars less than 100"); return(0);}

if(timeprev1<iTime(NULL,TimeFrame,0)) {TurnedDn = false; TurnedUp = false; timeprev1=iTime(NULL,TimeFrame,0);}

//Print("Current bar for USDCHF H1: ",TimeMinute(iTime(NULL,TimeFrame,0)));

//Print("Current bar for USDCHF H1: ",TimeMinute(iTime(NULL,TimeFrame,1)));

if (!RealTime)

{

if(timeprev2==iTime(NULL,TimeFrame,0)) return(0);

timeprev2=iTime(NULL,TimeFrame,0);

p=TimeFrame/Period()+1; if (p==0) p=1;

}

double TR = 0, MH = 0, ML = 0, MO = 0, MC = 0, MC1 = 0;

if (CountBars>iBars(NULL,TimeFrame) || CountBars>Bars-Length-1) CountBars=MathMin(Bars-Length-1,iBars(NULL,TimeFrame)-Length-1);

if (Crash && CountBars>0){CountBars=CountBars-10; IndicatorShortName("Crash: "+CountBars+" ");}

if (Crash && CountBars<0) IndicatorShortName("Crash");

int i = CountBars;

fxlive = Close;

fxlive_MTF = Close;

while (i >= 0)

{

MH = iMA(NULL,TimeFrame,Length,0,Method,PRICE_HIGH,i);

ML = iMA(NULL,TimeFrame,Length,0,Method,PRICE_LOW,i);

MO = iMA(NULL,TimeFrame,Length,0,Method,PRICE_OPEN,i);

MC = iMA(NULL,TimeFrame,Length,0,Method,PRICE_CLOSE,i);

MC1 = iMA(NULL,TimeFrame,Length,0,Method,PRICE_CLOSE,i + Smoothing);

if (Steady==true) {MC=iMA(NULL,TimeFrame,Length,0,Method,PRICE_MEDIAN,i); MC1=iMA(NULL,TimeFrame,Length,0,Method,PRICE_MEDIAN,i+Smoothing);}

fxlive = MathAbs(((MC - MC1) / MathMax(MH - ML,MathMax(MH - MC1,MC1 - ML)) + (MC - MO) / (MH - ML)) * 0.5) * ((MC - MC1 + (MC - MO)) * 0.5);

fxlive = fxlive + fxlive;

if (Filter > 0) if (MathAbs(fxlive - fxlive) < Filter * Point) fxlive = fxlive;

if (TimeFrame > Period()) fxlive_MTF = fxlive;

i--;

}

if (TimeFrame>Period())

{

datetime TimeArray1[];

ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TimeFrame);

int limit=CountBars+TimeFrame/Period();

for(i=0, int y=0;i<limit;i++) {if (Time<TimeArray1[y]) y++; fxlive=fxlive_MTF[y];}

}

for (i = CountBars; i >= 0; i--)

{

DIR = DIR;

if (fxlive - fxlive > 0) DIR = 1;

if (fxlive - fxlive > 0) DIR = -1;

if (Color == true)

{

if (DIR > 0)

{

UpBuffer = fxlive;

if (DIR < 0) UpBuffer = fxlive;

DnBuffer = EMPTY_VALUE;

}

else

{

if (DIR < 0)

{

DnBuffer = fxlive;

if (DIR > 0) DnBuffer = fxlive;

UpBuffer = EMPTY_VALUE;

}

}

}

if (Alerts == true)

{

UpArrow = EMPTY_VALUE; DnArrow = EMPTY_VALUE;

if ((DIR == 1) && (DIR == -1)) UpArrow = fxlive - (Ask - Bid);

if ((DIR == -1) && (DIR == 1)) DnArrow = fxlive + (Ask - Bid);

}

}

if (Alerts == true)

{

string AlertTXT;

if (UpArrow[0+p]!=EMPTY_VALUE && TurnedUp==false)

{

AlertTXT="fxlive BUY: "+Symbol()+" - "+Period()+" at "+ DoubleToStr(Close[0],Digits)+ " - "+ TimeToStr(CurTime(),TIME_SECONDS);

Alert(AlertTXT); if (EmailON) SendMail(AlertTXT,AlertTXT);

if (SignalPrice == true)

{

ObjectCreate("BUY SIGNAL: " + DoubleToStr(Time[0],0),OBJ_ARROW,0,Time[0],Close[0]);

ObjectSet("BUY SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_ARROWCODE,5);

ObjectSet("BUY SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_COLOR,SignalPriceBUY);

}

TurnedDn = false; TurnedUp = true;

}

if (DnArrow[0+p]!=EMPTY_VALUE && TurnedDn==false)

{

AlertTXT="fxlive SELL: "+Symbol()+" - "+Period()+" at "+ DoubleToStr(Close[0],Digits)+ " - "+ TimeToStr(CurTime(),TIME_SECONDS);

Alert(AlertTXT); if (EmailON) SendMail(AlertTXT,AlertTXT);

if (SignalPrice == true)

{

ObjectCreate("SELL SIGNAL: " + DoubleToStr(Time[0],0),OBJ_ARROW,0,Time[0],Close[0]);

ObjectSet("SELL SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_ARROWCODE,5);

ObjectSet("SELL SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_COLOR,SignalPriceSELL);

}

TurnedUp = false; TurnedDn = true;

}

}

return(0);

}

 

Try this variant:

extern double Lots=0.1;

//parameters used by fx-live

extern bool Crash = false;

extern int TimeFrame = 0;

extern int Length = 5;

extern int Method = 2;

extern int Smoothing = 6;

extern int Filter = 5;

extern bool RealTime = true;

extern bool Steady = false;

extern bool Color = true;

extern bool Alerts = true;

extern bool EmailON = false;

extern bool SignalPrice = true;

extern color SignalPriceBUY = Yellow;

extern color SignalPriceSELL = Aqua;

extern int CountBars = 1485;

//parameters used by RSIOMA

extern int RSIOMA = 21;

extern int RSIOMA_MODE = 1;

extern int RSIOMA_PRICE = 0;

extern int Ma_RSIOMA = 38;

extern int Ma_RSIOMA_MODE = 1;

extern double BuyTrigger = 20.00;

extern double SellTrigger = 80.00;

extern color BuyTriggerColor = Magenta;

extern color SellTriggerColor = DodgerBlue;

extern double MainTrendLong = 70.00;

extern double MainTrendShort = 30.00;

extern color MainTrendLongColor = Green;

extern color MainTrendShortColor = Red;

extern double MajorTrend = 50;

extern int BarsToCount = 500;

bool TurnedUp = false;

bool TurnedDn = false;

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

//| expert initialization function |

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

int init()

{

//----

start();

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

int Almost_Cross (double line1 , double line2)

{

Print("line1 - ",line1," line2 - ",line2," delta - ",MathAbs(line1 - line2));

if (line1 < 30.0 && line2 <30.0 && MathAbs(line1 - line2)<5.0)

{

return (1);

}

else

{

if (line1 < 30.0 && line2 < 30)

{

Print("filtered buy order: "," ",line1," ",line2," ",MathAbs(line1-line2));

return (0);

}

}

if (line1 > 70.0 && line2 >70.0 && MathAbs(line2 - line1)<5.0)

{

return (2);

}

else

{

if (line1 > 70.0 && line2 >70.0)

{

Print("filtered sell order: "," ",line2," ",line1," ",MathAbs(line2-line1));

return (0);

}

}

}

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

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

//if(current_direction != last_direction) //changed

//{

//last_direction = current_direction;

//return (last_direction);

//}

//else

//{

//return (0);

//}

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

//| expert start function |

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

int start()

{

//----

int cnt, ticket, total;

double fxb;

double fxs;

double rsioma;

double marsioma;

fxb = iCustom(NULL, 0, "fx-live", Crash, TimeFrame, Length, Method, Smoothing, Filter, RealTime, Steady, Color, Alerts, EmailON, SignalPrice, SignalPriceBUY, SignalPriceSELL, CountBars, 3, 0);

fxs = iCustom(NULL, 0, "fx-live", Crash, TimeFrame, Length, Method, Smoothing, Filter, RealTime, Steady, Color, Alerts, EmailON, SignalPrice, SignalPriceBUY, SignalPriceSELL, CountBars, 4, 0);

rsioma = iCustom(NULL, 0, "RSIOMA_V3", RSIOMA, RSIOMA_MODE, RSIOMA_PRICE, Ma_RSIOMA, Ma_RSIOMA_MODE, BuyTrigger, SellTrigger, BuyTriggerColor, SellTriggerColor, MainTrendLong, MainTrendShort, MainTrendLongColor, MainTrendShortColor, MajorTrend, BarsToCount, 0, 0);

marsioma = iCustom(NULL, 0, "RSIOMA_V3", RSIOMA, RSIOMA_MODE, RSIOMA_PRICE, Ma_RSIOMA, Ma_RSIOMA_MODE, BuyTrigger, SellTrigger,BuyTriggerColor,SellTriggerColor,MainTrendLong, MainTrendShort, MainTrendLongColor, MainTrendShortColor, MajorTrend, BarsToCount, 5, 0);

int is_almost_crossed = Almost_Cross(rsioma,marsioma);

Print("is_almost_crossed - ",is_almost_crossed);

total = OrdersTotal();

if(total < 1)

{

if(fxb != EMPTY_VALUE && is_almost_crossed==0 && !TurnedUp)

{

Print("BUY order filtered : ",rsioma," ",marsioma," ",MathAbs(rsioma-marsioma));

}

if(fxs != EMPTY_VALUE && is_almost_crossed == 0 && !TurnedDn)

{

Print("SELL order filtered : ",rsioma," ",marsioma," ",MathAbs(rsioma-marsioma));

}

if(fxb != EMPTY_VALUE && is_almost_crossed ==1 && !TurnedUp)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,99,0,0," fx-live buy",12345,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))

Print("BUY order opened : ",OrderOpenPrice());

TurnedDn = false; TurnedUp = true;

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if(fxs != EMPTY_VALUE && is_almost_crossed == 2 && !TurnedDn)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,99,0,0, "fx-live sell",12345,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))

Print("SELL order opened : ",OrderOpenPrice());

TurnedUp = false; TurnedDn = true;

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

return(0);

}

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

{

// should it be closed?

if(fxs != EMPTY_VALUE)

{

OrderClose(OrderTicket(),OrderLots(),Bid,99,Violet );

// close position

return(0); // exit

}

}

else // go to short position

{

// should it be closed?

if(fxb != EMPTY_VALUE)

{

OrderClose(OrderTicket(),OrderLots(),Ask,99,Violet );

// close position

return(0); // exit

}

// check for trailing stop

}

}

}

//----

return(0);

}
 

Calculate the right lot size MQL4/MT4

Hi,

i want to write an ea for the lot calculation i try this.

lot=NormalizeDouble(AccountBalance( )*MaximumRisk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),2);

StopLoss is SMA 200.

the problem is now that i don't know how to calculate the diff. betwenn Moving Averange and Open of the Pos. Can someone help me?

double lot=Lots;

double StopLoss=ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);

//---- select lot size

lot=NormalizeDouble(AccountBalance( )*MaximumRisk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),2);

How can I say it is Buy or Sell Stopp?

doesn't work. HELP.

 
Howardcool:
Hi,

i want to write an ea for the lot calculation i try this.

lot=NormalizeDouble(AccountBalance( )*MaximumRisk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),2);

StopLoss is SMA 200.

the problem is now that i don't know how to calculate the diff. betwenn Moving Averange and Open of the Pos. Can someone help me?

double lot=Lots;

double StopLoss=ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);

//---- select lot size

lot=NormalizeDouble(AccountBalance( )*MaximumRisk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),2);

How can I say it is Buy or Sell Stopp?

doesn't work. HELP.

diff = (your_price - sma200_price) / Point

int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order",16384,0,Green);

for buy stop

ticket=OrderSend(Symbol(),OP_BUYSTOP,1,your_price,3,your_price_SL,your_price_TP,"My order",16384,0,Green);

OP_BUY 0 Buying position.

OP_SELL 1 Selling position.

OP_BUYLIMIT 2 Buy limit pending position.

OP_SELLLIMIT 3 Sell limit pending position.

OP_BUYSTOP 4 Buy stop pending position.

OP_SELLSTOP 5 Sell stop pending position.

 

it works thank you

 

need HELP

hi i'm a new EA programmer

i want to make an EA

can someone help me to create it?????

rules:

1. average price = high + low previous day / 2

2. resistance = average price + 20

3. support = average price - 20

4. if price between support and resistance, order buystop on resistance and sellstop on support with TP 30pips and SL on average price, with stop expired on next day

5. if one of the stop is done, cancel the other

thankkkkk

 

By the looks of it, are you also new to trading?

You're basing an ea on static support and resistance lines, I'm interested on what statistical method you defined those boundaries from?

 

hi

r u already used that system manually ? and how about performance?

You can learn how to coding with mql here in this forum ,find it I forgot the thread

===================

Forex Indicators Collection

Reason: