Ichimoku EA

 

I'm working on an EA and it executes correctly when the buy signal is confirmed but does not execute the sell signal. "Price Below Cloud"  returns "False" when it should be "True".

Can't find the problem...

Please see code attached and comment.  Appreciated!

 
code attached....
Files:
buy4sell.png  57 kb
chart.png  35 kb
pricemcloud.png  34 kb
 
skelling #:
code attached....

Image is not a code.

---------------------

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.

 
Copy of code now attached.
 
 //Buy Condition
     if(FutureCloudGreen==true && PriceaboveCloud==true && TenkanaboveKijun==true && ChikouaboveCloud==true){
        double entry   = Closex1;
        double sl      = Kijun - 50*_Point;
        double tp      = entry + (entry-sl)*2;
        double lots    = calcLots(entry-sl);
        
        trade.Buy(lots,_Symbol,entry,sl,tp,"Open long here");
        SetAllConditionstofalse();     
     }

   //Sell Condition
     if(FutureCloudRed==true && PricebelowCloud==true && TenkanbelowKijun==true && ChikoubelowCloud==true){
        double entry   = Closex1;
        double sl      = Kijun + 50*_Point;
        double tp      = entry - (entry-sl)*2;
        double lots    = calcLots(entry-sl);
 
   // Exit Cloud Up OR Exit Cloud Below (price 2 bars back was in or below/above the cloud and now 1 bar back it is no longer)
      if(PriceaboveCloud==false && (Closex2<SpanAx2 || Closex2<SpanBx2) && Closex1>SpanAx1 && Closex1>SpanBx1){
         PriceaboveCloud=true;
         PricebelowCloud=false;
      }
      if(PricebelowCloud==false && (Closex2>SpanAx2 || Closex2>SpanBx2) && Closex1<SpanAx1 && Closex1<SpanBx1){
         PricebelowCloud=true;
         PriceaboveCloud=false;
         
      }   
 
  1. skelling #:
         if(FutureCloudGreen==true && PriceaboveCloud==true && TenkanaboveKijun==true && ChikouaboveCloud==true){
    

    You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.

  2.         double tp      = entry + (entry-sl)*2;
            double sl      = Kijun + 50*_Point;

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

 
William Roeder #:
  1. skelling #:

    You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.

  2. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

Thank you, I will study your response. Much appreciated. I'm new to coding and trading pretty much!