condition based on a previous condition ... How ??

 

Hello everybody ,, I'm a newbie in the field of Expert programming ,, and i'm trying to make an expert based on ichimoku indicator ,, but i have a problem

when i put some conditions (if statement) ... for example entry buy order when the Close[2] < kijun line and Close[1] > kijun line ...
but i don't want to entry the buy order only when the Chicospan break the prices to above ,, and i think that (&&) Symbol dosn't work in this case because it mean that the two conditions (Close[2] < kijun line and Close[1] > kijun line and Chicospan break the prices to above) must be true in sametime ,, but what i want is that the expert check the first condition ,, if it is true ,, the expert will not do anything and wait for second condition ,, if it is true ,, then entry buy order. so, how can i put the conditions structure in this case ??

 
//Globalscope
enum condition{ None,CrossedUp,CrossedDown };
condition CrossCondition=None;
  if(Close[2] < kijun line and Close[1] > kijun line)
     CrossCondition=CrossedUp;  
  
  if(CrossCondition==CrossedUp && ChicospanCondition)
     {
     Place Order; 
     CrossCondition=None;
     } 

The above is pseudo code amd will allow only 1 trade per cross

You should also include code to check only when a new bar opens

 
walidabou:

Hello everybody ,, I'm a newbie in the field of Expert programming ,, and i'm trying to make an expert based on ichimoku indicator ,, but i have a problem

when i put some conditions (if statement) ... for example entry buy order when the Close[2] < kijun line and Close[1] > kijun line ...
but i don't want to entry the buy order only when the Chicospan break the prices to above ,, and i think that (&&) Symbol dosn't work in this case because it mean that the two conditions (Close[2] < kijun line and Close[1] > kijun line and Chicospan break the prices to above) must be true in sametime ,, but what i want is that the expert check the first condition ,, if it is true ,, the expert will not do anything and wait for second condition ,, if it is true ,, then entry buy order. so, how can i put the conditions structure in this case ??

Show your code, then we can help :)
 

108


code :

for example in this code i want the chicou span cross the prices above on H4 Timeframe ,, and the price should be above the kijun and tenken and span a and span b on M30 Timeframe ,, meaning that if the first condition which is "Close[2] < kijun line and Close[1] > kijun line" is true  ,, the expert will not place the order until the implementing of second condition. So when the second condition is true ,, then the expert place the order without return to the first condition.

//+------------------------------------------------------------------+
//|                                                        Kijun.mq4 |
//|                                                      |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

int Lot = 1.0;
int MagicNum = 232242;

double KijunH4_2 = iIchimoku(NULL, 240, 9, 26, 52, MODE_KIJUNSEN, 2);
double ChicouH4_2 = iIchimoku(NULL, 240, 9, 26, 52, MODE_CHIKOUSPAN, 2);
double KijunH4_1 = iIchimoku(NULL, 240, 9, 26, 52, MODE_KIJUNSEN, 1);
double ChicouH4_1 = iIchimoku(NULL, 240, 9, 26, 52, MODE_CHIKOUSPAN, 1);
double SpanB_H4 = iIchimoku(NULL, 240, 9, 26, 52, MODE_SENKOUSPANB, 0);
double SpanA_H4 = iIchimoku(NULL, 240, 9, 26, 52, MODE_SENKOUSPANA, 0);

//---------------------------------------------------------------------------

double Kijun_M30 = iIchimoku(NULL, 30, 9, 26, 52, MODE_KIJUNSEN, 0);
double Tenken_M30 = iIchimoku(NULL, 30, 9, 26, 52, MODE_TENKANSEN, 0);
double Chicou_M30 = iIchimoku(NULL, 30, 9, 26, 52, MODE_CHIKOUSPAN, 1);
double SpanB_M30 = iIchimoku(NULL, 30, 9, 26, 52, MODE_SENKOUSPANB, 0);
double SpanA_M30 = iIchimoku(NULL, 30, 9, 26, 52, MODE_SENKOUSPANA, 0);

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- 
         if(Close[2] < KijunH4_2 && Close[1] > KijunH4_1 && High[27] < ChicouH4_1 && Ask > Kijun_M30 && Ask > Tenken_M30 &&
    Ask > SpanB_M30 && Ask > SpanA_M30 && High[26] < Chicou_M30 && OrdersTotal() <= 0)
         {
            OrderSend(NULL, OP_BUY, 1.0, Ask, 3, NULL, NULL, NULL, MagicNum, NULL,clrBlue);
         }
         
         else if(Close[2] > KijunH4_2 && Close[1] < KijunH4_1 && Low[27] > ChicouH4_1 && Bid < Kijun_M30 && Bid < Tenken_M30 &&
    Bid < SpanB_M30 && Bid < SpanA_M30 && Low[26] > Chicou_M30 && OrdersTotal() <= 0)
         {
            OrderSend(NULL, OP_SELL, 1.0, Bid, 3, NULL, NULL, NULL, MagicNum, NULL,clrRed);
         }
  }
//+------------------------------------------------------------------+
 
  1. double KijunH4_2 = iIchimoku(NULL, 240, 9, 26, 52, MODE_KIJUNSEN, 2);
    double ChicouH4_2 = iIchimoku(NULL, 240, 9, 26, 52, MODE_CHIKOUSPAN, 2);
    double KijunH4_1 = iIchimoku(NULL, 240, 9, 26, 52, MODE_KIJUNSEN, 1);
    :
    
    These are constant. They are not changing. Assign them in OnTick.
  2. OrderSend(NULL, OP_BUY, 1.0, Ask, 3, NULL, NULL, NULL, MagicNum, NULL,clrBlue);
    Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. NULL is not a valid symbol, (you can only use NULL in place of a symbol where the documentation says it's allowed. Compare iMA to OrderSend.) NULL is not a valid SL. NULL is not a valid TP. NULL is not a valid expiration datetime.
 
GumRai:

The above is pseudo code amd will allow only 1 trade per cross

You should also include code to check only when a new bar opens


Thank you ,, but i didn't understand the code much ,, could you explain more if you don't mind
 
walidabou: could you explain more if you don't mind
Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
 
WHRoeder:
  1. These are constant. They are not changing. Assign them in OnTick.

  2. Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. NULL is not a valid SL. NULL is not a valid TP. NULL is not a valid expiration.

Yes i agree with you ,, these are constants ,, but this is not my problem.

and for the SL and TP and date expiration ,, what which can be placed if i don't want put any SL or Tp ??

thank you so much


 
GumRai:

The above is pseudo code amd will allow only 1 trade per cross

You should also include code to check only when a new bar opens


but this code mean that the both two conditions must be true in sametime ,, or not ??
 
  1. walidabou: and for the SL and TP and date expiration ,, what which can be placed if i don't want put any SL or Tp ??
    Zero. But no SL means infinite risk to your account.
    • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip)
    • Do NOT use TickValue by itself - DeltaPerLot
    • You must normalize lots properly and check against min and max.
    • You must also check FreeMargin to avoid stop out
  2. walidabou: but this code mean that the both two conditions must be true in sametime ,, or not ??
    A && B is the same time.  CrossCondition was seen and now ChicospanCondition is seen.
    CrossCondition==CrossedUp && ChicospanCondition
 
WHRoeder:
  1. walidabou: and for the SL and TP and date expiration ,, what which can be placed if i don't want put any SL or Tp ??
    Zero. But no SL means infinite risk to your account.
    • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip)
    • Do NOT use TickValue by itself - DeltaPerLot
    • You must normalize lots properly and check against min and max.
    • You must also check FreeMargin to avoid stop out
  2. walidabou: but this code mean that the both two conditions must be true in sametime ,, or not ??

    A && B is the same time.  CrossCondition was seen and now ChicospanCondition is seen.

  3. so what's the difference between this code and my own code ??
Reason: