![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Coding is not actually about "finding" a solution, but rather about applying logic and "creating" a solution. Coding is not about copy/pasting "pieces" of code.
Think about it as "painting", where you first lean the basics of the craft (the code language structure) and the various tools (functions and libraries) that you can use. Then with practice and research you slowly learn how to apply that knowledge in a step-by-step method in order to "paint" (define the logic) of the what you want to achieve.
That is why many times, the questions that newbie coders ask here on the forum are not easy to answer, because it requires that the one that decides to answer, to actually do the work of thinking out the logic that is required in order to achieve the solution.
The original poster then receives a completed "picture" but does not understand how the "picture" was constructed or what the steps where that coder used to get to that answer. And so, the poster gets his answer, but learns very little about the process, and then has to come back with yet another request for another problem, because he has still not learned the process, the logic, of how to "create" solutions on his own, nor has he taken the time to learn the basic structure of the language nor does he understand what every available function does nor what libraries he has at his disposal.
I am still unable to start my picture as I cannot get clarification on simple coding logic. I am not looking for anyone to develop my 'logic path' or provide code, only how the code functions. I think I already have enough MQL4 language skills to complete the finished picture except I am missing one very small piece. I am happy to be pointed at a suitable resource but it must be relevant to my problem, suggestions of looking in the 'code base' dont help at all, I have already done that, how do you look up something you dont know?
I have researched every suggestion I have been give but have found nothing on how to code multiple logic gates (if statements), I have no idea why this is such a secret.
I am still unable to start my picture as I cannot get clarification on simple coding logic. I am not looking for anyone to develop my 'logic path' or provide code, only how the code functions. I think I already have enough MQL4 language skills to complete the finished picture except I am missing one very small piece. I am happy to be pointed at a suitable resource but it must be relevant to my problem, suggestions of looking in the 'code base' dont help at all, I have already done that, how do you look up something you dont know?
I have researched every suggestion I have been give but have found nothing on how to code multiple logic gates (if statements), I have no idea why this is such a secret.
Then what specifically are you having trouble with? Which functionality or logic are you stuck on? Be precise and be detailed!
Its not a secret! We just don't understand what it is you want to know! An "if" statement is quite basic, so we don't understand what your difficulty is with it.
OK I will try again,
I have several "if" statements that must run in sequence to get to the desired end function if all true OR move on if false.
What I dont want is every "if" statement read and end function completed regardless of any true or false conditions on every tick.
What I dont want is every "if" statement read and end function completed regardless of any true or false conditions on every tick.
Sorry. but you will have to be more clear about what it is you mean. It may be easier if show the code with lots of comments to try explain what it is you are trying to achieve.
I have several "if" statements that must run in sequence to get to the desired end function if all true OR move on if false.
What I dont want is every "if" statement read and end function completed regardless of any true or false conditions on every tick.
It may help if you break your conditionals down into boolean variables.
For example:
Then you can see the encompassing conditional more easily:
OK
I have an indicator which I will call from the EA, it produces an up or down arrow output.
When an up arrow signal is received at the close of a candle.
1) I am looking at the next candle building
2) If the price moves up by 4 points I enter a trade.
3) If the price doesn't move by 4 points but is more than 2 points up at close of candle I enter a trade.
4) I need to add something to confirm the close of the candle.
5) If neither occur I look at the next candle in the same way
6) If the price moves up by 4 points I enter a trade.
7) If the price doesn't move by 4 points but is more than 2 points up at close of candle I enter a trade.
8) If neither happens again, the signal is dead and I wait for another.
(The same for a down arrow signal)
So
if(Close[i]-Close[i+1]>=4)
{take trade}
if(rates_total!=prev_calculated)//new candle 1
if(Close[i+1]-Close[i+2]>=2)//closed candle 1
{take trade}
if(Close[i]-Close[i+2]>=4)//new candle 2
{take trade}
if(rates_total!=prev_calculated)//new candle 2
if(Close[i+1]-Close[i+2]>=2)//closed candle 2
{take trade}
wait for next signal.
OK
I have an indicator which I will call from the EA, it produces an up or down arrow output.
When an up arrow signal is received at the close of a candle.
1) I am looking at the next candle building
2) If the price moves up by 4 points I enter a trade.
3) If the price doesn't move by 4 points but is more than 2 points up at close of candle I enter a trade.
4) I need to add something to confirm the close of the candle.
5) If neither occur I look at the next candle in the same way
6) If the price moves up by 4 points I enter a trade.
7) If the price doesn't move by 4 points but is more than 2 points up at close of candle I enter a trade.
8) If neither happens again, the signal is dead and I wait for another.
(The same for a down arrow signal)
So
if(Close[i]-Close[i+1]>=4)
{take trade}
if(rates_total!=prev_calculated)//new candle 1
if(Close[i+1]-Close[i+2]>=2)//closed candle 1
{take trade}
if(Close[i]-Close[i+2]>=4)//new candle 2
{take trade}
if(rates_total!=prev_calculated)//new candle 2
if(Close[i+1]-Close[i+2]>=2)//closed candle 2
{take trade}
wait for next signal.
EDIT: I just realised that I am unsure if you describing the logic for an Indicator or for a Expert Advisor, because you mixing concepts of both.
So, we need to establish this. You cannot mix Indicator an EA code. They must be coded separately. An Indicator cannot have any trading functions.
Please ignore the following until we separate things and decide what is part of the Indicator and what is part of the Expert advisor.
...
Although I am ultimately writing an EA I was trying to get the logic to work in an indicator first which provides outputs to test. So in this case the 'take trade' could be an arrow on the chart or a comment.
With regards to the new candle indication, my attempt was,
int time1=TimeMinute(TimeCurrent());
double Min=(0);
Min=time1%=5;
if(Min<1)//new candle formed.
The problem is having it in the right place to be effective.
Of course this only works on the 5min time scale, so your solution would be fool proof.
Although I am ultimately writing an EA I was trying to get the logic to work in an indicator first which provides outputs to test. So in this case the 'take trade' could be an arrow on the chart or a comment.
With regards to the new candle indication, my attempt was,
int time1=TimeMinute(TimeCurrent());
double Min=(0);
Min=time1%=5;
if(Min<1)//new candle formed.
The problem is having it in the right place to be effective.
Of course this only works on the 5min time scale, so your solution would be fool proof.
Indicators and EAs work completely differently, so we need to separate things.
In Indicators, we should not use the "New Bar" functionality at all, because of the why the OnCalculate() works.
In EAs you can use my method of the new bar. Don't use your method because bars do not necessarily always form based on time. If there is no activity, bars will be skipped and the current bar will remain open until a new tick arrives.
In Indicators, values are kept in running buffers, which can be recalculated at any time the system triggers a new recalculation cycle, so you have to think in those terms.
The arrows for the Up or Down will also be stored in these buffers.
So, I ask you to show your complete code as you have at the moment. Attach your Indicator ".mq4" file so we can see what you have done till now.