How to code? - page 199

 
V-Force:
I am new to mq4 and i am trying to creat a display on screen when there is a crossover for MACD. Below is my code but the alerts keep poping up every few minutes.

How can i code it to display alerts only once every hour? Or one alert per bar?

int start()

{

string MACD1="";

color colt9;

double MACDM_S10 = iCustom(NULL, PERIOD_H1, "MACD", 8,17,9, MODE_MAIN, 0);

double MACDS_S10 = iCustom(NULL, PERIOD_H1, "MACD", 8,17,9, MODE_SIGNAL,0);

double MACDM_S11 = iCustom(NULL, PERIOD_H1, "MACD", 8,17,9, MODE_MAIN, 1);

double MACDS_S11 = iCustom(NULL, PERIOD_H1, "MACD", 8,17,9, MODE_SIGNAL,1);

if ((MACDM_S11 < MACDS_S11 && MACDM_S10 < MACDS_S10)) { MACD1="IN UPTREND"; colt9=LimeGreen; }

if ((MACDM_S11 > MACDS_S11 && MACDM_S10 > MACDS_S10)) { MACD1="IN DOWNTREND"; colt9=Red; }

if ((MACDM_S11 > MACDS_S11 && MACDM_S10 < MACDS_S10)) { MACD1="NEW UP CROSSING"; colt9=LimeGreen; }

if ((MACDM_S11 MACDS_S10)) { MACD1="NEW DOWN CROSSING"; colt9=Red; }

string MACD2="";

color colt14;

double MACDM_L10 = iCustom(NULL, PERIOD_H1, "MACD", 12,26,9, MODE_MAIN, 0);

double MACDS_L10 = iCustom(NULL, PERIOD_H1, "MACD", 12,26,9, MODE_SIGNAL,0);

double MACDM_L11 = iCustom(NULL, PERIOD_H1, "MACD", 12,26,9, MODE_MAIN, 1);

double MACDS_L11 = iCustom(NULL, PERIOD_H1, "MACD", 12,26,9, MODE_SIGNAL,1);

if ((MACDM_L11 < MACDS_L11 && MACDM_L10 < MACDS_L10)) { MACD2="IN UPTREND"; colt14=LimeGreen; }

if ((MACDM_L11 > MACDS_L11 && MACDM_L10 > MACDS_L10)) { MACD2="IN DOWNTREND"; colt14=Red; }

if ((MACDM_L11 > MACDS_L11 && MACDM_L10 < MACDS_L10)) { MACD2="NEW UP CROSSING"; colt14=LimeGreen; }

if ((MACDM_L11 MACDS_L10)) { MACD2="NEW DOWN CROSSING"; colt14=Red; }

if(MACD1=="NEW UP CROSSING"&&MACD2=="IN UPTREND")

Alert(Symbol()," - ","H1:"," MACD MAIN UPTREND MOVEMENT"," at ", Bid, " - ",TimeToStr(CurTime(),TIME_SECONDS));

if(MACD1=="NEW DOWN CROSSING"&&MACD2=="IN DOWNTREND")

Alert(Symbol()," - ","H1:"," MACD MAIN DOWNTREND MOVEMENT"," at ", Bid, " - ",TimeToStr(CurTime(),TIME_SECONDS));

if(MACD2=="NEW UP CROSSING"&&MACD1=="IN UPTREND")

Alert(Symbol()," - ","H1:"," MACD, MAIN TREND CHANGE TO UPTREND"," at ", Bid, " - ",TimeToStr(CurTime(),TIME_SECONDS));

if(MACD2=="NEW DOWN CROSSING"&&MACD1=="IN DOWNTREND")

Alert(Symbol()," - ","H1:"," MACD, MAIN TREND CHANGE TO DOWNTREND"," at ", Bid, " - ",TimeToStr(CurTime(),TIME_SECONDS));

return(0);

}

Try to USE Minute()==1; in condition

 

Trend Alexcud for modify

if (MaH11v < MaH1pr1v){H11v = " V "; co11v = Red; u1x5v = 0; d1x5v = 1;}

if (MaH11v > MaH1pr1v){H11v = " /\\ "; co11v = Blue; u1x5v = 1; d1x5v = 0;}

if (MaH11v == MaH1pr1v){H11v = " 0 "; co11v = Green; u1x5v = 0; d1x5v = 0;}

hy everyone, i'm trying to modify trend alexcud(attached)

i want only 2 signal up and down instead of 3 with "0"...

so calculation could be more accurate...

Any ideas ?

Files:
 

Can somebody help me understanding these programming lines? In simple English

It is about an EA starting something after a bar has finished.

The code is like this :

datetime timeprev=0;

// Only run once per completed bar

if(timeprev==Time[0]) return(0);

timeprev = Time[0];

As I look at MQ4 manual, Time[0] is for extracting the open time of bar [0]. It is stated as seconds from 1January1970.

I don't understand how that works. First we have "timeprev=0".

Then the next line "if (timeprev==Time[0]) return(0).

What is the value of Time[0] at this time? How come it can become 0 (the value of "timeprev"?

The next line is "timeprev=Time[0]".

How come the whole line makes the EA does nothing until a bar has finished?

 
crn:
Try to USE Minute()==1; in condition

This will still set off each tick in the first minute of each bar. That may significantly reduce the number, but it will still alert multiple times.

The best thing to do is set a global variable (or object) and set it to the Time[] of the last bar.

if (Time[0]!=lastTime) {

... alert, whatever...

lastTime=Time[0];

}

 
Jorged23:
Hi,

I cannot avoid the OrderModify error 1 : always show up even trying controlling that the data before to modify is different ! I have tried doublenormalize as well...not working...

This is the code:

if (Bid-OrderOpenPrice() >= VPoint*BreakEvenAtProfit)

{

if (OrderStopLoss() != OrderOpenPrice() + BreakEvenShift*VPoint)

{

Vresult = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+ BreakEvenShift*VPoint,OrderTakeProfit(),0,Green);

Any suggestions ?

Thanks.

Quick check... make sure you're not setting the breakeven distance too short. Check it against MarketInfo(Symbol(),MODE_STOPLEVEL) to be sure it's large enough.

What's the purpose of VPoint? If that number is wrong it'll mess things up. "Point" by itself will always be correct. If that number is off, that could definitely be causing the problem. IE it's accidentally 0 or less than what POINT actually is.

 

SIMPLE Coding question

OrderSelect(5555, SELECT_BY_TICKET);

RefreshRates();

if (Ask >= (OrderOpenPrice()+ (5 * Point)) && OrderLots() == 2 && (OrderType() == OP_BUY)) {

OrderClose(5555,1,Ask,10,Red); }

if (Bid <= (OrderOpenPrice()- (5 * Point)) && OrderLots() == 2 && (OrderType() == OP_SELL)) {

OrderClose(5555,1,Bid,10,Blue); }

Still trying to learn...

would this work for basically closing half (2 lots down to 1) of a position when the price hits 5 pips away from open price?

THANKS!!!!!!

 

Looks about right. It's a bit messy though. You could also use OrderProfit depending on what you actually want to achieve.

Lux

PS: Forgot to mention to watch out for 5 decimal place brokers. Everything needs to be multiplied by 10 so in your example 5 would be 50. Good luck!

 
luxinterior:
Looks about right. It's a bit messy though. You could also use OrderProfit depending on what you actually want to achieve.

Lux

PS: Forgot to mention to watch out for 5 decimal place brokers. Everything needs to be multiplied by 10 so in your example 5 would be 50. Good luck!

Thanks LUX

Problem is that I have it running just to debug on a 1 minute GBP/USD chart with Windsor direct and it is Not closing 1 lot when it hits the 5 pips so I don't know what the deal is.

ALSO,

I'm trying to close a buy and immediately open a Sell and THAT"S NOT GOING to well either.

It works and then it doesn't...

I WISH THIS WAS ALOT easier to program

if (*******************) {

RefreshRates();

OrderSelect(5555,SELECT_BY_TICKET);

if (OrdersTotal() > 0 && OrderType()==OP_BUY) {OrderClose(5555, OrderLots(), Bid, Slippage, MediumSeaGreen);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");}

Sleep(1500);

RefreshRates();

if (OrdersTotal() ==0) Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 10, 0, 0, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);

if(Ticket<0)Print("OrderSend failed with error #",GetLastError());

}

 

Debugging Indicators

I am new to this language and I am trying to write an indicator. I am having problems since there is no debugger. I tried to use the Print() but nothing gets printed. Using the Alert() I get ZERO as an output for the buffer[1] . Can anyone explain this to me please. How can I use the Print() and Alert() to debugg without getting all ZEROs. If anyone has any ideas please let me know. Thanks so much.

tigger.longtail@gmail.com

ExtMapBuffer1 = iMA(NULL,0,ExtParam1,0,MODE_EMA,PRICE_CLOSE,i);

ExtMapBuffer2 = iMA(NULL,0,ExtParam2,0,MODE_EMA,PRICE_CLOSE,i);

CurrentBar = Time;

if( ExtMapBuffer1 >= ExtMapBuffer2 && CurrentBar == Time && Flag == 0)

{

Alert("ExtMapBuffer1 =", ExtMapBuffer1," Short is Above. ",Hour()," Minute ",Minute());

Alert("ExtMapBuffer2 =", ExtMapBuffer2," Short is Above. ",Hour()," Minute ",Minute());

Print("ExtMapBuffer1 = ", ExtMapBuffer1);

Print("ExtMapBuffer2 = ", ExtMapBuffer2);

 

no way anyway

Reason: