simple problem with IF function

 

Hello,


Im writing some simple EA based on bollinger bands, i would like to use IF function:

double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
bid = NormalizeDouble(bid,_Digits);

double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
ask = NormalizeDouble(ask,_Digits);

double current_bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double current_ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); 

    if(close1 > bbUpper[1] && close2 < bbUpper[0] && current_bid < X*close1){

      double sls = B*bid;
      sls = NormalizeDouble(sls,_Digits);
      
      double tps = bid - A;
      tps = NormalizeDouble(tps,_Digits);
      
      trade.Sell(Lots,_Symbol,bid,sls,tps);


When I put current_BID < X close1 EA does not make any trades.
Short story long, I would like to make an order if:

- close2 was below the band

- close1 was above the band

- current prices is different X% vs close1


Thanks in advance,


it might be silly question for you guys, but I dont have any experience with coding :) thanks
Bollinger Bands - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
Bollinger Bands - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
Bollinger Bands (BB) are similar to Envelopes. The only difference is that the bands of Envelopes are plotted a fixed distance (%) away from the...
 
Tomasz Kustra: Short story long, I would like to make an order if:

- close2 was below the band

- close1 was above the band

- current prices is different X% vs close1

    if(close1 > bbUpper[1] && close2 < bbUpper[0] && current_bid < X*close1){

You wrote close2 below the upper band. You wrote current price is below a fraction of price (always false).

So write it that way. Exactly that way.

bool c1 = close2 < …;                  // close2 was below the band
bool c2 = close1 > bbUpper[1];         // close1 was above the band
bool c3 = MathAbs( Bid - close1 ) > …  // current prices is different X% vs close1
if(c1 && c2 && c3){
 

Thanks for your help, but still no idea how to do it :(

E.g.

Close1 = 10, bbUpper1 = 9

Close2 = 7, bbUpper0 = 8


So, I would like to sell when:

close2 < bbUpper0 - correct

close1 > bbUpper1 - correct

and also when price goes down by 1% so I would like to sell, when the price is 9.99


Im not sure if MathAbs helps here

 
Tomasz Kustra #: Thanks for your help, but still no idea how to do it :(

You have only four choices:

  1. Search for it (CodeBase or Market). Do you expect us to do your research for you?

  2. Beg at:

  3. MT4: Learn to code it.
    MT5: Begin learning to code it.

    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 your code.

  4. Or pay (Freelance) someone to code it. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2019)

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
          No free help (2017)