Coding help - page 19

 

i have completed my EA with ur Help ThanX again

Hello, mLaden,

ThanX again for ur great help

i have completed my EA with ur Help ThanX again

ThanXXXXXXXXXX

 

Repainting Indicators

I posted this question to this thread 'Coding Help' a couple weeks ago, but got no response.

Most MTF indicators repaint, some more than others. I have one that repaints slightly, but has one factor that is very good and could be included in a method. Problem is that I need to manually update/refresh constantly in order for it to make sense. Is there a way to code an auto refresh every tick or every 'x' seconds/ticks?

Currently, to refresh, I either change chart times and then go back, or go to Charts/Refresh tab, or add another indicator to the chart and delete the previous one.......over and over again! Very time consuming!

If there is a way of doing this auto refresh, I will share what I have found............

Thx,

el bee

 

...

el bee

Metatrader is sending an autorefresh signal to each and every indicator in the window when a new tick comes in, so it is not a problem of refreshing. Usually that kind of a problem you have happens when an indicator does not find the count of changed bars (usually named in indicators as "limit") properly ... so it is a problem f the indicator. When you change time frames it recalculates all the bars again and that is why it shows it properly in that case and does not do it properly when there is just 1 bars value changed

To conclude : check the code of the indicator - it has a bug in it

el bee:
I posted this question to this thread 'Coding Help' a couple weeks ago, but got no response.

Most MTF indicators repaint, some more than others. I have one that repaints slightly, but has one factor that is very good and could be included in a method. Problem is that I need to manually update/refresh constantly in order for it to make sense. Is there a way to code an auto refresh every tick or every 'x' seconds/ticks?

Currently, to refresh, I either change chart times and then go back, or go to Charts/Refresh tab, or add another indicator to the chart and delete the previous one.......over and over again! Very time consuming!

If there is a way of doing this auto refresh, I will share what I have found............

Thx,

el bee
 

indicator help

I could use an indicator thay puts a vertical line on the most recent candle, adjustible, if someone has one and can share or if one could be made, it would be most appreciated

 

There is wrong code ?

I'm trying to write an EA that base on open and close of the bar

but I have a problem about condition to open a trade .

my method is something like that :

+ SELL when open of the current bar is higher than the close of the previous bar . TP is close of the previour bar

+ BUY when open of the current bar is lower than the open of the Previous bar . TP is open of the previous bar

+ CLOSE when the current bar close .

and here is the code (I'm still trying to learn mql4 , so I know that it's not the best code)

#property link "sando"

#define MAGICMA 20050610

//====================parameter===================//

extern double solantang =3;

extern double solangiam =3;

extern double LotsSize =1;

//==============================================//

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

//| check for open trade |

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

int CalculateCurrentOrders(string symbol)

{

int buys=0,sells=0;

//----

for(int i=0;i<OrdersTotal();i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)

{

if(OrderType()==OP_BUY) buys++;

if(OrderType()==OP_SELL) sells++;

}

}

//---- return orders volume

if(buys>0) return(buys);

else return(-sells);

}

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

//| Moneymanagement (Type 3) |

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

double moneymanagement3()

{

double LotsSize = 0.1;

if(OrdersHistoryTotal()>0)

{

OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);

if(OrderProfit() > 0)

{

if(OrderLots() > LotsSize)

{

LotsSize = OrderLots()/solangiam;

}

else

{

LotsSize = LotsSize;

}

}

else

{

LotsSize = OrderLots() * solantang;

}

}

return (NormalizeDouble(LotsSize,2));

}

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

//| CONDITION to open a trade |

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

void opentrade()

{

int res;

if(Close[0]<Open[1])

{

res=OrderSend(Symbol(),OP_SELL,moneymanagement3(),Bid,3,Close[0],Close[1],"",MAGICMA,0,Red);

return;

}

if(Open[0]>Open[1])

{

res=OrderSend(Symbol(),OP_BUY,moneymanagement3(),Ask,3,Open[0],Close[1],"",MAGICMA,0,Blue);

return;

}

}

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

//| expert start function |

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

void start()

{

//---- check for history and trading

if(Bars<100 || IsTradeAllowed()==false) return;

//---- calculate open orders by current symbol

if(CalculateCurrentOrders(Symbol())==0) opentrade();

// else donggiaodich();

//----

}

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

and please check the picture in attachment

I think something is wrong in the code

sometime the EA doesn't do the trade when meet the condition T_T I don't know why

and sometime the EA does the trade when doesn't meet the condition !

Please help me fix the wrong in the code .

Files:
1_2.gif  12 kb
new_edge.mq4  4 kb
 
7thman:
I'm trying to write an EA that base on open and close of the bar

but I have a problem about condition to open a trade .

my method is something like that :

+ SELL when open of the current bar is higher than the close of the previous bar . TP is close of the previour bar

+ BUY when open of the current bar is lower than the open of the Previous bar . TP is open of the previous bar

+ CLOSE when the current bar close .

and here is the code (I'm still trying to learn mql4 , so I know that it's not the best code)

and please check the picture in attachment

I think something is wrong in the code

sometime the EA doesn't do the trade when meet the condition T_T I don't know why

and sometime the EA does the trade when doesn't meet the condition !

Please help me fix the wrong in the code .

[lang=pl]+ SELL when open of the current bar is higher than the close of the previous bar . TP is close of the previour bar

+ BUY when open of the current bar is lower than the open of the Previous bar . TP is open of the previous bar

Here is first mistake:

if(Close[0]Close[1])

if(Open[0]>Open[1]) (Should be Open[0]<Open[1])

The second is StopLoss. In your code you set StopLose, but in description above

you told that you want to close trades if new bar turns up.

Here is one more problem. Suppose that Open[0]<Open[1]. Difference can be so small

that when your order will be execute price will be over Open[1] and TP will

less than order open price . Below i add condition which allow catch this case.

If I good understand that you want to close all orders at the end of the bar here is code.

#property link "sando"

#define MAGICMA 20050610

//====================parameter===================//

extern double solantang =3;

extern double solangiam =3;

extern double LotsSize =1;

//==============================================//

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

//| check for open trade |

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

int CalculateCurrentOrders(string symbol)

{

int buys=0,sells=0;

//----

for(int i=0;i<OrdersTotal();i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) break;

if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)

{

if(OrderType()==OP_BUY) buys++;

if(OrderType()==OP_SELL) sells++;

}

}

//---- return orders volume

if(buys>0) return(buys);

else return(-sells);

}

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

//| Moneymanagement (Type 3) |

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

double moneymanagement3()

{

double LotsSize = 0.1;

if(OrdersHistoryTotal()>0)

{

OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);

if(OrderProfit() > 0)

{

if(OrderLots() > LotsSize)

{

LotsSize = OrderLots()/solangiam;

}

else

{

LotsSize = LotsSize;

}

}

else

{

LotsSize = OrderLots() * solantang;

}

}

return (NormalizeDouble(LotsSize,2));

}

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

//| CONDITION to open a trade |

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

void opentrade()

{

int res;

if(Close[1] Close[1] )

{

res=OrderSend(Symbol(),OP_SELL,moneymanagement3(), Bid,3,0,Close[1],"",MAGICMA,0,Red);

return;

}

if(Open[0]<Open[1] && Ask < Open[1])

{

res=OrderSend(Symbol(),OP_BUY,moneymanagement3(),Ask,3,0,Open[1],"",MAGICMA,0,Blue);

return;

}

}

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

//| expert start function |

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

void start()

{

if(isNewBar())

{

closeOrders(MAGICMA,OP_BUY);

closeOrders(MAGICMA,OP_SELL);

}

Print(Close[1]-Open[0]);

//---- check for history and trading

if(Bars<100 || IsTradeAllowed()==false) return;

//---- calculate open orders by current symbol

if(CalculateCurrentOrders(Symbol())==0) opentrade();

// else donggiaodich();

//----

}

void closeOrders(int oMagic,int oType) {

for(int i=0;i<OrdersTotal();i++) {

if(OrderSelect(i,SELECT_BY_POS)) {

if(OrderMagicNumber()==oMagic || oMagic<0) {

if(OrderSymbol()==Symbol()) {

if(OrderType()==oType || oType<0) {

if(OrderType()==OP_BUY) {

OrderClose(OrderTicket(),OrderLots(),Bid,0);

i--;

}

if (OrderType() == OP_BUYSTOP)

{

OrderDelete(OrderTicket());

i--;

}

if(OrderType()==OP_SELL) {

OrderClose(OrderTicket(),OrderLots(),Ask,0);

i--;

}

if (OrderType() == OP_SELLSTOP)

{

OrderDelete(OrderTicket());

i--;

}

}

}

}

}

}

}

bool isNewBar() {

static int prevTime;

bool newBar=false;

if(Time[0]!=prevTime) {

newBar=true;

prevTime=Time[0];

}

return(newBar);

}

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

Cheers,

Grzesiek[/lang]

 

Coding Help: Placing Stop Loss & Take Profit with EA using an ECN Broker

Stop Loss, Take Profit with ECN Broker

Friends,

I'm a newbie to MQL4 programming and need help attaching a SL & TP to an ORDERSEND with an ECN broker.

Initially, I couldn't understand why the SL & TPs were making my order result in an error until someone pointed out that one has to set the StopLoss & TakeProfit field within the ORDERSEND to "0" or else an ECN/STP broker will not execute the order.

So, my question is: How can I execute an order at Market and then immediately (or within a second or two) attach a SL/TP to that ticket?

Here's a piece of the code pertinent to my question:

if(CurrentPriceBuy>UpperPriceTrigger)

{

OrderSend(Sym,OP_BUY,Lots,CurrentPriceBuy,0,0,0,Co mm,0,0,CLR_NONE);

}

Can anyone help me insert code right after the OrderSend command so that I can attach a TP/SL of say arbitrarily 25pips to that specific ticket?

Any help would be greatly appreciated. Thanks in advance.

Regards,

Kasio

 
kasio:
Stop Loss, Take Profit with ECN Broker

Friends,

I'm a newbie to MQL4 programming and need help attaching a SL & TP to an ORDERSEND with an ECN broker.

Initially, I couldn't understand why the SL & TPs were making my order result in an error until someone pointed out that one has to set the StopLoss & TakeProfit field within the ORDERSEND to "0" or else an ECN/STP broker will not execute the order.

So, my question is: How can I execute an order at Market and then immediately (or within a second or two) attach a SL/TP to that ticket?

Here's a piece of the code pertinent to my question:

if(CurrentPriceBuy>UpperPriceTrigger)

{

OrderSend(Sym,OP_BUY,Lots,CurrentPriceBuy,0,0,0,Co mm,0,0,CLR_NONE);

}

Can anyone help me insert code right after the OrderSend command so that I can attach a TP/SL of say arbitrarily 25pips to that specific ticket?

Any help would be greatly appreciated. Thanks in advance.

Regards,

Kasio

Hi kasio,

If you trading in ECN broker you shoulod send order without SL/TP and modify it.

here is an example:

extern double StopLoss = 25;

extern double TakeProfit = 25;

if(isECN==true )

{

ticket=OrderSend(Symbol(),OP_BUY,lots,Ask, slippage,0,0,comment,magic);

OrderSelect(ticket,SELECT_BY_TICKET);

OrderModify(ticket,OrderOpenPrice(),sltpValue(Bid - StopLoss*Point, StopLoss),sltpValue(Ask+ TakeProfit*Point,TakeProfit),0);

}

double sltpValue(double w1, int w2)

{

if(w2 == 0)

return (0);

return (NormalizeDouble(w1, Digits));

}

I hope that its clear

PM me if have more question.

cheers,

grzesiek

 

Information not updated every tic

Hi Guys,

I wrote this ea which shows me information on various indicators on my screen.

However when I attach the ea to my chart, the information is only updated every 5 min (on 5 min. chart),

instead of every tic. Is there something wrong i my coding? I would like to see the information to change every tic.

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

//| test.mq4 |

//| Copyright © 2011, Test Inc. |

//| test.net - Test Resources and Information. |

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

#property copyright "Copyright © 2011, Test Inc."

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

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

//| labels |

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

#define ccilabel "CCIValue"

#define rsilabel "RSIValue"

#define stochlabel "StochValue"

#define upperbandlabel "UpperBandValue"

#define lowerbandlabel "LowerBandValue"

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{

//----

//===================================================================

// Dynamic Relative Strength Index berekenen

//===================================================================

double RSI;

double UpperBand;

double LowerBand;

RSI=iCustom(NULL,0,"Dynamic Zone RSI",14,0,1);

UpperBand=iCustom(NULL,0,"Dynamic Zone RSI",14,1,1);

LowerBand=iCustom(NULL,0,"Dynamic Zone RSI",14,2,1);

//===================================================================

// CCI berekenen

//===================================================================

double CCI;

CCI=iCCI(NULL,0,14,PRICE_TYPICAL,1);

//===================================================================

// Stochastic berekenen

//===================================================================

double Stoch;

Stoch=iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);

//===================================================================

// Display information

//===================================================================

// CCIValue

ObjectDelete(ccilabel);

ObjectCreate(ccilabel, OBJ_LABEL, 0, 0, 0);

ObjectSet(ccilabel, OBJPROP_XDISTANCE, 20);

ObjectSet(ccilabel, OBJPROP_YDISTANCE, 20);

ObjectSetText(ccilabel, "CCIValue is " + DoubleToStr(CCI,2), 10, "Arial", DeepSkyBlue);

// StochValue

ObjectDelete(stochlabel);

ObjectCreate(stochlabel, OBJ_LABEL, 0, 0, 0);

ObjectSet(stochlabel, OBJPROP_XDISTANCE, 20);

ObjectSet(stochlabel, OBJPROP_YDISTANCE, 40);

ObjectSetText(stochlabel, "StochValue is " + DoubleToStr(Stoch,2), 10, "Arial", DeepSkyBlue);

// RSIValue

ObjectDelete(rsilabel);

ObjectCreate(rsilabel, OBJ_LABEL, 0, 0, 0);

ObjectSet(rsilabel, OBJPROP_XDISTANCE, 20);

ObjectSet(rsilabel, OBJPROP_YDISTANCE, 60);

ObjectSetText(rsilabel, "RSIValue is " + DoubleToStr(RSI,2), 10, "Arial", DeepSkyBlue);

// UpperBandValue

ObjectDelete(upperbandlabel);

ObjectCreate(upperbandlabel, OBJ_LABEL, 0, 0, 0);

ObjectSet(upperbandlabel, OBJPROP_XDISTANCE, 20);

ObjectSet(upperbandlabel, OBJPROP_YDISTANCE, 80);

ObjectSetText(upperbandlabel, "UpperbandValue is " + DoubleToStr(UpperBand,2), 10, "Arial", DeepSkyBlue);

// LowerBandValue

ObjectDelete(lowerbandlabel);

ObjectCreate(lowerbandlabel, OBJ_LABEL, 0, 0, 0);

ObjectSet(lowerbandlabel, OBJPROP_XDISTANCE, 20);

ObjectSet(lowerbandlabel, OBJPROP_YDISTANCE, 100);

ObjectSetText(lowerbandlabel, "LowerBandValue is " + DoubleToStr(LowerBand,2), 10, "Arial", DeepSkyBlue);

//----

return(0);

}

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

 

KG Support And Resistance mod

Hello,

I need someone to modify one of the attached support and resistance indicators. The first one has an alert when a breakout is made. I need an alert as soon as a new support or resistance bar appears.This indicator is one of the best support/resistance indicators and also very powerful especially on higher timeframes.

Thanks

kg_support_and_resistance.mq4 or

kg_support_and_resistance_alert_revision_2.ex4