What i want is if price cross above MA and revised back to be lower than. then i want to sell (HELP)

 

Please how can i code this? I tried coding it this way (i will send the code) . what i want is if price cross above MA and revised back to be lower that MA . the i want to sell

bool WasCrossAbove;

bool WasCrossBelow;





//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

   

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {


   bool PriceCrossAbove;

   bool PriceCrossBelow;


   

   //MOVING AVAREGE-----------------------------------------------------]

   double MA30 = iMA(NULL,30,200,0,MODE_EMA,PRICE_CLOSE,0);

   double MAValue30 = NormalizeDouble(MA30,Digits);

   

   double MA5 = iMA(NULL,5,200,0,MODE_EMA,PRICE_CLOSE,0);

   double MAValue5 = NormalizeDouble(MA5,Digits);

   //-------------------------------------------------------------------]


   //MA CROSS CONDITION--------------------------------------------] 

   PriceCrossAbove = Low[1] < MAValue5 && Bid >MAValue5;

   PriceCrossBelow = High[1] > MAValue5 && Bid < MAValue5;

   

   WasCrossAbove = PriceCrossAbove && Bid >MAValue5;

   WasCrossBelow = PriceCrossBelow && Ask <MAValue5;

Files:
code_bot.png  75 kb
 
Please edit your post and

use the code button (Alt+S) when pasting code


I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

 
  1. WasCrossAbove = PriceCrossAbove && Bid >MAValue5;
    WasCrossBelow = PriceCrossBelow && Ask <MAValue5;

    The moment price goes below the MA, you reset your variable to false, making it useless for your test. Save the previous value to a new variable, then set your current global/static variables. Then you can test wasAbove and isAbove.
              MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  3. Post in the correct section.



 
Emmanuel Tom: what i want is if price cross above MA and revised back to be lower that MA

Your title is

What i want is if price cross above MA and revised back to be lower than. then i want to sell (HELP)

Then code that: H[0] ≥ MA && MA ≥ Bid; no need for your variables.