How to code? - page 289

 

Need help finishing this EA

I'm trying to code an EA (using some already made codes) which does the following:

  • Opens two pending orders, a sell stop and a buy stop, at a specific time (in this case 23:00), both with an SL and a TP.
  • Expires the pending order at a certain time (for example at 10:00) and doesn't open any trades on Friday 23:00.
  • If two trades are opened and one reaches the SL, the other has its TP increased to a certain amount (I think an OrderModify will solve something like this).
  • Trades which are open automatically close by 23:00 the next day.
  • The EA is almost done and some previous issues I had were resolved and does most of the above but I still have the following issues and at this point I don't know how to go further, so if anyone could provide the code necessary that would be very helpful.

  • When two trades are open and one hits the stoploss, I need the other trade which is still open to have its take profit increased by a certain amount.
  • Trades are still being opened on Friday 23:00 which I do not want.
  • Any trades which are still open by 23:00 should be closed regardless if they are in loss or profit.

I am a noob at MQL and I have tried looking around for the solutions to some of the issues above and am having trouble finding them. I believe the issues can be resolved quite easily with not so much complicated coding required. If anyone could provide me with a solution or solutions to any of the issues above I would, once again, greatly appreciate it.

Thanks,

madmax3

 

...

Try something like this :

if((CurrentPriceBuy>UpperPriceTrigger) && TakeAction==1)

{

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

if (ticketBuy>-1)

OrderModify(ticketBuy,OrderOpenPrice(),stopLossToUse,takeProfitToUse,0,CLR_NONE);

}

Just replace stopLossToUse and takeLossToUse with the values you wish those to be

kasio:
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 questino:

if((CurrentPriceBuy>UpperPriceTrigger) && TakeAction==1)

{

OrderSend(Sym,OP_BUY,Lots,CurrentPriceBuy,0,0,0,Comm,0,0,CLR_NONE);

TakeAction=0;

}

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
 

help!

can someone help me make this indicator to not repaint please?

Files:
pi_bg_v2.mq4  3 kb
 

...

It is a decompiled code, but anyway look at this thread : https://www.mql5.com/en/forum/179650

It is one more renamed solar wind, so ...

phoenix:
can someone help me make this indicator to not repaint please?
 

Any ideas on how to code what I posted? My apologies if I'm being impatient or something, just want to know if it has been read.

Thanks,

madmax3

 

...

Add something like this in your EA at the beginning of start() procedure :
if (TimeDayOfWeek(TimeCurrent())==5 && TimeCurrent()>=StrToTime("22:59")) { CloseAll(); return(0); } [/PHP]

Add this into the code :

[PHP]void CloseAll()

{

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

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderMagicNumber()!=MagicNumber) continue;

//

//

//

//

//

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

{

for(int c=0; c<3; c++)

{

RefreshRates();

if (OrderType()==OP_BUY)

{ double cp = Bid;}

else { cp = Ask;}

OrderClose(OrderTicket(),OrderLots(),cp,0,Yellow);

int err=GetLastError();

if(err==4 || err==136 || err==137 || err==138 || err==146)

{

Sleep(5000); continue;

}

break;

}

break;

}

}

}

That will solve your points 2 and 3 (opened orders at Friday)

First point is rather complicated to code - you will probably need to redefine that rule

madmax3:
Any ideas on how to code what I posted? My apologies if I'm being impatient or something, just want to know if it has been read.

Thanks,

madmax3
 

Please help! Error number = 4103. pos = 10. Cannot Open FIle

Hi,

I am new here and new to MT programming as well. Can anyone help me on this?

I got "An error had occured. Error number = 4103. pos = 10 (cannot open file) message."

The file is saved correctly as gif but I am getting the above message. Where is the problem?

The code:

void Screenshot(int ticket, int cmd, datetime orderOpenTime, double orderOpenPrice)

{

RefreshRates();

if (cmd==OP_BUY) Comment (DateTimeInfo(),"\n","Order Open Time: ",TimeToStr(orderOpenTime,TIME_DATE|TIME_SECONDS)," Buy: ",DoubleToStr(orderOpenPrice,Digits)) ;

if (cmd==OP_SELL) Comment (DateTimeInfo(),"\n","Order Open Time: ",TimeToStr(orderOpenTime,TIME_DATE|TIME_SECONDS)," Sell: ",DoubleToStr(orderOpenPrice,Digits)) ;

string filename = Symbol()+"_"+"Demo"+"_"+ticket+"_Open.gif";

int handle = FileOpen(filename,FILE_CSV|FILE_READ);

if(handle<1)

{

if (GlobalVariableGet("_MonitorScreen_ScreenShot") != 0 )

{

if(!WindowScreenShot(filename,900,600)) Print("WindowScreenShot error: "+GetLastError());

}

}

else FileClose(handle);

}

Any help is appreciated. Thank you.

 

...

It works OK

The file must be in the experts\files sub-folder and I used as an example ticket number 0, so the full file name was in my example "EURUSD_Demo_0_Open.gif" and it opened it with no problem (it does it OK if you use FILE_CSV as well as with FILE_BIN). So, if it is saved in correct folder and correct name, your code works OK

Akkinmore:
Hi,

I am new here and new to MT programming as well. Can anyone help me on this?

I got "An error had occured. Error number = 4103. pos = 10 (cannot open file) message."

The file is saved correctly as gif but I am getting the above message. Where is the problem?

The code:

void Screenshot(int ticket, int cmd, datetime orderOpenTime, double orderOpenPrice)

{

RefreshRates();

if (cmd==OP_BUY) Comment (DateTimeInfo(),"\n","Order Open Time: ",TimeToStr(orderOpenTime,TIME_DATE|TIME_SECONDS)," Buy: ",DoubleToStr(orderOpenPrice,Digits)) ;

if (cmd==OP_SELL) Comment (DateTimeInfo(),"\n","Order Open Time: ",TimeToStr(orderOpenTime,TIME_DATE|TIME_SECONDS)," Sell: ",DoubleToStr(orderOpenPrice,Digits)) ;

string filename = Symbol()+"_"+"Demo"+"_"+ticket+"_Open.gif";

int handle = FileOpen(filename,FILE_CSV|FILE_READ);

if(handle<1)

{

if (GlobalVariableGet("_MonitorScreen_ScreenShot") != 0 )

{

if(!WindowScreenShot(filename,900,600)) Print("WindowScreenShot error: "+GetLastError());

}

}

else FileClose(handle);

}

Any help is appreciated. Thank you.
 
mladen:
It works OK The file must be in the experts\files sub-folder and I used as an example ticket number 0, so the full file name was in my example "EURUSD_Demo_0_Open.gif" and it opened it with no problem (it does it OK if you use FILE_CSV as well as with FILE_BIN). So, if it is saved in correct folder and correct name, your code works OK

Thanks. Yes the file is saved in the correct folder and correct name. I might try to use the FILE_BIN instead of FILE_CSV to check if the error message appears again.

 

...

How to make my computer show words in Russian in indicators correctly?...Thanks...

Reason: