How to code? - page 319

 
Tomcat98:
Hello coders,

How to code some extra coding lines so that an Experts stops after a winning trade?

Pips are in the bag, then make the Expert stops...

Thanks a lots

Tomcat98

See below if you have some coding experience. Else get a coder.

1) after each trade close, do a loop in OrdersHistoryTotal() to check trades.

2) check for the last trade close ( OrderCloseTime() ) .

3) if last trade, check OrderProfit() == profit.

If in profit == true, set EndDayTrade == true && LastTradeDay == DayofYear().

If in profit == false, set EndDayTrade == false.

4) When the program goes thru start(), you will need to insert ==> if EndDayTrade == false before starting any new trade. Since it is true, then it will not trigger new trades.

5) you will need a timer function to check for new day. (assuming new day is what you want to trigger new trades)

simplest form would be if (LastDay != DayofYear() ).

6) within the above timer function, set LastDay = DayofYear().

if ( LastTradeDay != DayofYear() && EndDayTrade == true)

set EndDayTrade == false, which starts all over again.

user defined variables

bool EndDayTrade = false;

int LastTradeDay = 9999999;

int LastDay = 999999;

hope this explanation is clear enough.

 
dasio:
Hi,

i'm try to merge this two code but i have trouble with it.

I need that when one pending order is filled the other must be cancelled.

Thank you for your disponibility

int opened =0;

int pending =0;

for(int i=OrdersTotal()-1; i>=0; i--)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol() !=Symbol()) continue;

if(OrderMagicNumber()!=Magic) continue;

if(OrderType()==OP_BUY || OrderType()==OP_SELL)

opened++;

else pending++;

}

if (opened>0 && pending>0)

{

for(i=OrdersTotal()-1; i>=0; i--)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol() !=Symbol()) continue;

if(OrderMagicNumber()!=Magic) continue;

if(OrderType()!=OP_BUY && OrderType()!=OP_SELL)

OrderDelete(OrderTicket());

}

} [/PHP]

[PHP] extern int Magic = 68415;

extern int Orario_Inizio = 0;

extern int Orario_Fine = 6;

extern int Buffer = 0;

extern double Lotti = 0.1;

extern int TakeProfit = 10;

extern int StopLoss = 50;

double Massimo;

double Minimo;

int BarCount;

int BarStart;

int BarShift;

double MinLot;

double LotSize;

int i;

int ticket;

string Status;

string BuyStatus1;

string SellStatus1;

double Range;

string CommentoRange;

double pipMultiplier = 1;

int init()

{

}

int start()

{

if (Digits==3 || Digits==5)

{pipMultiplier = 10;}

else {pipMultiplier = 1; }

double TakeProfit1 = TakeProfit*Point*pipMultiplier;

double StopLoss1 = StopLoss*Point*pipMultiplier;

double Buffer1 = Buffer*Point*pipMultiplier;

double StopLossPrice = NormalizeDouble(StopLoss1,Digits);

double TakeProfitPrice = NormalizeDouble(TakeProfit1,Digits);

double BufferPrice = NormalizeDouble(Buffer1,Digits);

//CALCOLA LE BARRE DEL RANGE

if(Orario_Inizio>Orario_Fine)

{

BarCount=24+Orario_Fine-Orario_Inizio;

}

if(Orario_Inizio<Orario_Fine)

{

BarCount=Orario_Fine-Orario_Inizio;

}

//CALCOLA IL MASSIMO E IL MINIMO DEL RANGE

if(Hour()>=Orario_Fine)

{

BarStart=Hour()-Orario_Fine;

BarShift=BarStart+BarCount;

Minimo=iLow(NULL,PERIOD_H1,BarStart);

Massimo=0;

for(i=BarStart;i<=BarShift;i++)

{

Massimo=MathMax(Massimo,iHigh(NULL,PERIOD_H1,i));

Minimo=MathMin(Minimo,iLow(NULL,PERIOD_H1,i));

Range=(Massimo-Minimo)/Point;

}

}

else

{

Massimo=0;

Minimo=0;

return(0);

}

//CONTROLLA SE E' L'ORARIO PER POTER TRADARE

if(Hour()==Orario_Fine && OrdersTotal()<2)

{

//CONTROLLA SE IL MASSIMO E' STATO ROTTO. CONDIZIONE BUY

double OpenPriceBuy = NormalizeDouble((Massimo+BufferPrice),Digits);

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lotti,OpenPriceBuy,0,OpenPriceBuy-StopLossPrice,OpenPriceBuy+TakeProfitPrice,NULL,Magic,0,Blue);

//CONTROLLA SE IL MINIMO E' STATO ROTTO. CONDIZIONE SELL

double OpenPriceSell = NormalizeDouble((Minimo-BufferPrice),Digits);

ticket=OrderSend(Symbol(),OP_SELLSTOP,Lotti,OpenPriceSell,0,OpenPriceSell+StopLossPrice,OpenPriceSell-TakeProfitPrice,NULL,Magic,0,Red);

if (ticket != -1)

return(0);

}

}

Someone can help?

 

dasio

Try placing that whole code a the begining of the start() procedure. You will probably have to filter out some more the way when you are opening pending orders, but if you place that code at the start it will clean up pending orders if any of the before opened pending orders beca,me a "regular" order

dasio:
Someone can help?
 

Hi,

i'm learning a lot from this thread it is why I continue to ask questions.

Now. I try to do it alone but i haven't succes.

Premise i want to use this indicator in an offline renko chart.

My purpose is to plot above or below the candle How long did the construction.

So i know that in specification of the candle there is the time when it opened. So if i do the time of current candle minus the candle of the previous i have what i need.

So how i can code it?

Thank you very much

 

Can't Figure Out Why This Code Is Trying To Modify Closed Orders

I added the OrderCloseTime() to both if statements thinking that would put an end to this invalid ticket for ordermodify function error but every once in awhile my EA will lose control of all the orders and somehow mix in a closed trade and continously try to modify it over and over making huge log files and won't continue trading unless I retart the MT4. I'm not exactly sure how it's picking up a closed order, maybe while it's in the process of modifying all the orders one of them closes in that short time and throws it off? Like I said this will happen maybe twice out of 30-50 trades a day.

Anyone have any ideas on how to put an end to this?

if (NewOrdersPlaced_s3) {

if (flag_s3 == TRUE) {

for (cnt_s3 = OrdersTotal() - 1; cnt_s3 >= 0; cnt_s3--) {

OrderSelect(cnt_s3, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_3 || OrderCloseTime()!=0) continue;

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_3 && OrderCloseTime()==0)// OrderModify(OrderTicket(), AveragePrice_s3, OrderStopLoss(), PriceTarget_s3, 0, Yellow);

//===

while(!OrderModify(OrderTicket(), AveragePrice_s3, OrderStopLoss(), PriceTarget_s3, 0, Yellow))

{Sleep(1000);RefreshRates();}

//===

NewOrdersPlaced_s3 = FALSE;

}

}
 

Signal Problems

mladen

Thank you so much the code is now working.The alert no more repeating itself.Please I want to host a scripts that will be sending trading alerts to multiple recipients, like hundreds of them, how can i do that...Are there companies that can handle that which you or anyone on this forum know.

Mastercash:
Mladen Thank you, I ve looked closely....Im still experimenting the code.I will be notifying when through.
 

...

2 thoughts :

1. If you are going to send it, then I think that the only reasonable way is sending mail and in that case why don't you simply use one of the email spamming programs that are out there in the wild?

2. Sending signals has too much problems (that is my opinion, some of the problems with sending are practically unsolvable). So why don't you invert the logic : instead of sending, make a code that will be reading (with user name, pass , and so on ...) from a given location and that way you have almost all problems that sending can not solve, solved (including the prevention of usage from multiple IPs at the same time)

So, just some thoughts ...

Mastercash:
mladen Thank you so much the code is now working.The alert no more repeating itself.Please I want to host a scripts that will be sending trading alerts to multiple recipients, like hundreds of them, how can i do that...Are there companies that can handle that which you or anyone on this forum know.
 

Try something like this :

#include

#define PAUSE_BEFORE_RETRY 1000

#define NumberOfReTries 3

if (NewOrdersPlaced_s3 && flag_s3 == TRUE)

{

for (cnt_s3 = OrdersTotal() - 1; cnt_s3 >= 0; cnt_s3--)

{

if (!OrderSelect(cnt_s3, SELECT_BY_POS, MODE_TRADES)) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderMagicNumber() != MagicNumber_3) continue;

for (int retry=0; retry<NumberOfReTries; retry++)

{

OrderModify(OrderTicket(), AveragePrice_s3, OrderStopLoss(), PriceTarget_s3, 0, Yellow);

int error = GetLastError();

switch (error)

{

case ERR_SERVER_BUSY:

case ERR_NO_CONNECTION:

case ERR_INVALID_PRICE:

case ERR_OFF_QUOTES:

case ERR_BROKER_BUSY:

case ERR_TRADE_CONTEXT_BUSY:

Sleep(PAUSE_BEFORE_RETRY);

continue;

case ERR_PRICE_CHANGED:

case ERR_REQUOTE:

continue;

default:

retry=NumberOfReTries;

}

}

NewOrdersPlaced_s3 = FALSE;

}

}
beakon:
I added the OrderCloseTime() to both if statements thinking that would put an end to this invalid ticket for ordermodify function error but every once in awhile my EA will lose control of all the orders and somehow mix in a closed trade and continously try to modify it over and over making huge log files and won't continue trading unless I retart the MT4. I'm not exactly sure how it's picking up a closed order, maybe while it's in the process of modifying all the orders one of them closes in that short time and throws it off? Like I said this will happen maybe twice out of 30-50 trades a day.

Anyone have any ideas on how to put an end to this?

if (NewOrdersPlaced_s3) {

if (flag_s3 == TRUE) {

for (cnt_s3 = OrdersTotal() - 1; cnt_s3 >= 0; cnt_s3--) {

OrderSelect(cnt_s3, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber_3 || OrderCloseTime()!=0) continue;

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_3 && OrderCloseTime()==0)// OrderModify(OrderTicket(), AveragePrice_s3, OrderStopLoss(), PriceTarget_s3, 0, Yellow);

//===

while(!OrderModify(OrderTicket(), AveragePrice_s3, OrderStopLoss(), PriceTarget_s3, 0, Yellow))

{Sleep(1000);RefreshRates();}

//===

NewOrdersPlaced_s3 = FALSE;

}

}
 

Alert Solutions

I think I need more explanation on this, can you just hint me on how to write and set up a code that will help me send the alert to all my clients at the same time.Is it by storing their email address in the database.....but how will the server language,e.g, php script,collect the alerts from the mt4 platform automatically?......I think this is the problem,if there can be a way, it can be sent to multiple mobile phones or email address.Your advice, please?

mladen:
2 thoughts :

1. If you are going to send it, then I think that the only reasonable way is sending mail and in that case why don't you simply use one of the email spamming programs that are out there in the wild?

2. Sending signals has too much problems (that is my opinion, some of the problems with sending are practically unsolvable). So why don't you invert the logic : instead of sending, make a code that will be reading (with user name, pass , and so on ...) from a given location and that way you have almost all problems that sending can not solve, solved (including the prevention of usage from multiple IPs at the same time)

So, just some thoughts ...
 

Mastercash

Try googling "sending mass emails" and I think that you will find an answer for that

As of "collecting alerts" : you have to have something that will "export" it to some readable format that will be recognized then by a software of your choice that will distribute signals or allow access to that signal

PS: signaling services are much more complex than it looks at the wirst glance and, if you plan to make one, you can count on substantial costs to make one works as it should

Mastercash:
I think I need more explanation on this, can you just hint me on how to write and set up a code that will help me send the alert to all my clients at the same time.Is it by storing their email address in the database.....but how will the server language,e.g, php script,collect the alerts from the mt4 platform automatically?......I think this is the problem,if there can be a way, it can be sent to multiple mobile phones or email address.Your advice, please?
Reason: