Unstoppable orders

 

Hi there i have question

UPDATE 

i been able to came up with a solution but it seems the strategy tester crash when i uplode the advisor to it , just to keep up with what it is going on this is my attempt to open only one buy order above kijun sen and same thing goes to sell , i think i know the issue which it is infinte loop i guess any clue guys any help will be appreciated, the funny thing is when i replace OP_SELL with OP_BUY the tester work just fine //but the logic and idea will be invalid and one more thing it worked much less orders but still i need only one order per side view attached pictures 


    //+------------------------------------------------------------------+
//|                                                     kjexpert.mq4 |
//|                                   Copyright 2019, MOHAMMEDJAFFAR |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MOHAMMEDJAFFAR"
#property link      ""
#property version   "1.00"
#property strict
extern double kj=52;
 extern int StopLoss=50;
 extern int TakeProfit=10;
 extern double lots=0.05;
void OnTick()
  {
  double kijun_sen=iIchimoku(NULL,0,9,kj,52,MODE_KIJUNSEN,0);
  for(int i=0; i<10; i++)
  {
//****************BUY**************************  
  if(isitoktotrade()==true)
  {
    if(iClose(Symbol(),0,1)>kijun_sen)
  {
  OrderSend(Symbol(), OP_BUY,lots, Ask, 10*10, Bid-StopLoss*Point*10, Bid+TakeProfit*Point*10, "My 1st Order!");
  i=i-1;
  }
  if(iClose(Symbol(),0,1)<kijun_sen)
  {
  break;
  }
  }
  }
for(int y=0; y<10; y++)
  {
///****************SELL**************************  
  if(isitoktotrade()==true)
  {
    if(iClose(Symbol(),0,1)<kijun_sen)
  {
  OrderSend(Symbol(), OP_SELL,lots, Ask, 10*10, Bid-StopLoss*Point*10, Bid+TakeProfit*Point*10, "My 1st Order!");
  y=y-1;
  }
  if(iClose(Symbol(),0,1)>kijun_sen)
  {
  break;
  }
  }
  }
      
  }
  
  //Alert("close price =",iClose(Symbol(),0,1));}
  
//+------------------------------------------------------------------+
bool isitoktotrade()
{
int maxorders=1;
if(OrdersTotal()<=maxorders)

{return true;}

else

return false;
}


Files:
sell.PNG  45 kb
BUY.PNG  68 kb
 
Hi, just add new condition "if price close below moving avereage then open position". If this not resolve your problem add screenshot to better describe this case. Regards Greg
 
Greg Pawlak:
Hi, just add new condition "if price close below moving avereage then open position". If this not resolve your problem add screenshot to better describe this case. Regards Greg
Hi greg thanks for the response 
As you see in the code I attached and the picture i only want trade once above the kijun sen purple line and one trade bellow the line 
 
  1. 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
              Messages Editor

  2. if(OrdersTotal()<=maxorders){return true;}
    else                         return false;
    Simplify your code.
    return OrdersTotal()<=maxorders;
              Increase Order after stoploss - MQL4 programming forum № 3
  3. Using OrdersTotal (or OrdersHistoryTotal) directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

  4.   OrderSend(Symbol(), OP_SELL,lots, Ask, 10*10, Bid-StopLoss*Point*10, Bid+TakeProfit*Point*10, "My 1st Order!");
    
    You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP is longer.
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger 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.)
  5. Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  6.     if(iClose(Symbol(),0,1)>kijun_sen){   OrderSend( … ); }
      if(iClose(Symbol(),0,1)<kijun_sen)
    When can the second if ever be true?