- Why did you post your MT4 question in the Root / MT5 Indicators
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - Exactly what you labeled them as — MACD crossover.
-
double v1 = iMACD(…, MODE_MAIN,1), v2 = iMACD(…, MODE_MAIN,2), s1 = iMACD(…, MODE_SIGNAL, 1), s2 = iMACD(…, MODE_SIGNAL, 2); bool wasUp = v2 > s2, isUp = v1 > s1, crossed = isUp != wasUp;
- Why did you post your MT4 question in the Root / MT5 Indicators
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - Exactly what you labeled them as — MACD crossover.
Sorry for posting in the wrong section. I am very new to code do you mind taking your response a step further and explaining to me what you wrote here?
What are v1-v2 & s1-s2?
- Variables.
- Yes
-
MT4: Learn to code it.
MT5: Learn to code. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours. - or pay (Freelance) someone to code it.
Hiring to write script - General - MQL5 programming forum
1. I am trying to learn it. I am reading guides, readin forums and posting to forums.
2. They are varibales, but what is deliniating them? How can I indicate what line is signal and which is MACD?
All I need to make is a short order based on this cross. I do not know how to make it compare the values in the parenthesis.
void OnTick() { double v1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_MAIN,1), v2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_MAIN,2), s1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_MAIN,1), s2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_MAIN,2); bool wasUp = v2 > s2, isUp = v1 > s1, crossed = isUp != wasUp; //if(signal line goes above MACD)<-------------- OrderSend ( _Symbol, //Pair to use OP_SELL, //buy or sell operator 0.15, //how much Bid, //price to pay 3, //slippage ?? Ask+200*_Point, // Stop Loss Bid-125*_Point, // Take Prof NULL, // use if you want to ID the trade 0, // Magic Number 0, // Expiration, 0 for no expiration Green ); }
1. I am trying to learn it. I am reading guides, readin forums and posting to forums.
2. They are varibales, but what is deliniating them? How can I indicate what line is signal and which is MACD?
All I need to make is a short order based on this cross. I do not know how to make it compare the values in the parenthesis.
William Roeder gave you the right example, and you made a mistake, missed MODE_SIGNAL in variables s1 and s2
William Roeder gave you the right example, and you made a mistake, missed MODE_SIGNAL in variables s1 and s2
Pavel,
Yeah, I see that now! Thank you. My question is how to make my if statement know when the corss happens.
I am assuming its along theses lines:
if ( signal_period<macd)
or
If (signal>macd)
Pavel,
Yeah, I see that now! Thank you. My question is how to make my if statement know when the corss happens.
I am assuming its along theses lines:
if ( signal_period<macd)
or
If (signal>macd)
if(crossed)
You already have a solution provided by William Roeder
You already have a solution provided by William Roeder
I have the code set up on 2 different computers linked to two seperate acocunts. One to buy & one to sell.
The code executes on both computers at the same time.All I changes was the greater than & less than signs hoping one would sell on the
downard crossover and then later buy on the upwards crossover (see picture atatched to original post) .
Any idea how to fix this guys? I dont see how changing the signs didnt produce the opposite effect.
Sell Code: void OnTick() { double v1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_MAIN,1), v2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_MAIN,2), s1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_SIGNAL,1), s2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_SIGNAL,2); bool wasUp = v2 < s2, isUp = v1 < s1, crossed = isUp != wasUp; int total=OrdersTotal(); if(crossed) if(total<5) OrderSend ( _Symbol, //Pair to use OP_SELL, //buy or sell operator 0.15, // how much Bid, // price to pay 3, // slippage ?? Ask+100*_Point, // Stop Loss Bid-125*_Point, // Take Prof NULL, // use if you want to ID the trade 0, // Magic Number 0, // Expiration, 0 for no expiration Green ); }
Buy Code: void OnTick() { double v1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_MAIN,1), v2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_MAIN,2), s1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_SIGNAL,1), s2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE, MODE_SIGNAL,2); bool wasUp = v2 > s2, isUp = v1 > s1, crossed = isUp != wasUp; int total=OrdersTotal(); if(crossed) if(total<5) OrderSend ( _Symbol, //Pair to use OP_BUY, //buy or sell operator 0.15, // how much Ask, // price to pay 3, // slippage ?? Bid-100*_Point, // Stop Loss Ask+125*_Point, // Take Prof NULL, // use if you want to ID the trade 0, // Magic Number 0, // Expiration, 0 for no expiration Green ); }
You certainly need more practice. Take the code from @William Roeder and add these two lines:
double v1 = iMACD(…, MODE_MAIN,1), v2 = iMACD(…, MODE_MAIN,2), s1 = iMACD(…, MODE_SIGNAL, 1), s2 = iMACD(…, MODE_SIGNAL, 2); bool wasUp = v2 > s2, isUp = v1 > s1, crossed = isUp != wasUp; bool isUpCross = isUp && !wasUp; bool isDnCross = wasUp && !isUp;
You can use this block for both selling and buying. Just use the new variables like so:
if(isUpCross && total<5) OpenBuy(0.15); // buy some lots if(isDnCross && total<5) OpenSell(0.15); // sell some lots
You'll also need to find out when to close orders. Or if the signal is advising to close all contrary orders. It's a long road.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
On the screenshot attached you can see two places I want to focus in on. I have used the function in Mt4 (MACD>0) & (MACD<0). But the value when MACD = 0 is not this specific crossover, as I thought it was.
Does anyone know what my points (A & B) in the screenshot are called? Or how to locate them using mt4ql?