How to code? - page 162

 

Need Help on coding error

Hi

I`m quite new to forex trading as well as to coding in MQL4. I need help in setting up ordersend for SellLimit orders and BuyLimit orders. This is my code but I keep getting a Ordersend error 130 or 3. I don`t know what is wrong with the code.

if (Bid <= LowEnvelope) {OrderSend(Symbol(),OP_SELLLIMIT,lotMM,Bid-EmergencyProfit*Point,0,0,0," Sell Limit Order",MagicNumber,0,Orange);}

Please can someone Help me? Thank You

 

This is a fantastic Place to learn

I just want to take the opportunity to say thanks to all the people whom make this forum possible and to all the other traders who are willing to share their knowledge freely with every one else. Thank you, I have learned quite a bit and still feel like I know nothing.

 
simonkoen:
Hi

I`m quite new to forex trading as well as to coding in MQL4. I need help in setting up ordersend for SellLimit orders and BuyLimit orders. This is my code but I keep getting a Ordersend error 130 or 3. I don`t know what is wrong with the code.

if (Bid <= LowEnvelope) {OrderSend(Symbol(),OP_SELLLIMIT,lotMM,Bid-EmergencyProfit*Point,0,0,0," Sell Limit Order",MagicNumber,0,Orange);}

Please can someone Help me? Thank You

Price for SellLimit order should be higher then real price, not lower.

 

Thanks

Thank You Roger9. I`m using seelstop and buystopp now instead and it is working fine.

 

get CurrentTime Frame() ?

Simple request - can anyone tell me how to get the current time frame / period being viewed? I.e. 1 hour, 4 hour, 1 day etc.

Have searched docs etc can't find it.

Thanks.

 
djl:
Simple request - can anyone tell me how to get the current time frame / period being viewed? I.e. 1 hour, 4 hour, 1 day etc.

Have searched docs etc can't find it.

Thanks.

This function can to help you.

int Period( )

Returns the amount of minutes determining the used period (chart timeframe).

Sample:

Print("Period is ", Period());

 

Two more questions

Hi Everybody.

Sorry for my bad spelling yesterday.

I would like how to go about it that when I open a buy or sell position and at the same time a stopsell or stopbuy how do i assign the same number to the orders so that if the one is Triggered it will automatically close the other order. I know you must be able to do it with the magic number but also something about the time in the Magic Number? The second question. When i place code into my orders section I force the program to only open one order on that bar but when I do this the Ea don`t Trigger orders when the conditions are met to open orders When I remove the code It does open orders where it meet the conditions. Any thoughts as to why this is so? Here is the code.

if(CurrBar != iTime(NULL,0,0))

{

double HighEnvelope = iEnvelopes(Symbol(),0,EnvelopePeriods,MODE_EMA,0,PRICE_MEDIAN,EnvelopeDev,MODE_UPPER,0);

if (Bid >= HighEnvelope && OrdersTotal() <=MaxAllowable_Trades)

{

OrderSend(Symbol(),OP_SELL,lotMM,(Bid),Slippage,(0),0," Sell Order ",MagicNumber,0,White);

OrderSend(Symbol(),OP_BUYSTOP,lotMM,Bid+EmergencyProfit*Point,0,0,0," Pending Buy Order ",MagicNumber,0,DodgerBlue);

CurrBar = iTime(NULL,0,0);

}

}

return;

}

Thanks in advance for your patience and support.

 

Thank you.

 

Let's say Period() =5. How can I read the ticks current trade minute and seconds within that Period?? Example: Minute =3, Seconds=42.

What I want to do is check a condition within my ea every 4 minutes 50 seconds into the 5 minute period - Can you help!

Dave

 
1Dave7:
Let's say Period() =5. How can I read the ticks current trade minute and seconds within that Period?? Example: Minute =3, Seconds=42.

What I want to do is check a condition within my ea every 4 minutes 50 seconds into the 5 minute period - Can you help!

Dave

In a 5min timeframe, i think that only you can check some situation at a determined time is when a new tick arise. You will can to view if the time elapsed from the opened bar is the time that you want.

At each new tick the start function of mql code will run, then you will need to monitor if the time elapsed from the last bar opened is the time that you want with Date & Time Functions of MQL.

If no new tick arise between your time (4min50sec) and a new bar opened period (5min) i don't know how to check because i never need to do that.

Reason: