please, give me an advice

 

Good day, I would like to ask for advice. I am a complete beginner in programming and I wanted to program a simple EA for the exam, which enters stores only on the basis of SMA. I added the function of shifting SL to BE and I also defined the variable PLUS, which is used to add the gain to BE. Everything works fine, only for retail trades moving to BE with a profit of PLUS does not work! I can't find a mistake, can anyone help me? Thank you in advance! Below I enclose the entire EA code


//+------------------------------------------------------------------+
//|                                                       Runner.mq4 |
//|                         Copyright 2020,MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020"
#property link      "https://www.mql5.com" 
#property version   "1.11"
#property strict

//+------------------------------------------------------------------+
//| Vstupní parametry strategie                                      |
//+------------------------------------------------------------------+
input double Stoploss_v_pipech = 3000;        // Stop loss (3000=300 pips)
input double Profit_Target_v_pipech = 3000;   // Take profit (3000=300 pips)
input double Velikost_pozice = 0.01;          // Velikost pozice
input double Posun_na_BE_v_pipech = 2000;     // posun na BE při zisku (2000=200 pips)
input double Plusova_hodnota_BE = 1000;       // plusova hodnota k BE (1000=100 pips)
input double SMA_Period = 55;                 // hodnota SMA
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//+------------------------------------------------------------------+
//| Definice proměnných                                              |
//+------------------------------------------------------------------+
  int ticket, p, q, modify;                                                     // promenna pro zadani prikazu, pocitadlo
  double SL = Stoploss_v_pipech*Point;                                          // prevod pipoveho stoplosu na cenove vyjadreni
  double PT = Profit_Target_v_pipech*Point;                                     // prevod pipoveho profitu na cenove vyjadreni
  double BE = Posun_na_BE_v_pipech*Point;                                       // prevod pipove hodnoty na cenove vyjadreni
  double PLUS = Plusova_hodnota_BE*Point;                                       // prevod pipove hodnoty na cenove vyjadreni
  double SMA = iMA(NULL, NULL, SMA_Period, 0, MODE_SMA, PRICE_CLOSE, 0);        //hodnota SMA
  double C = iClose(NULL, NULL, 0);                                             // zjisti hodnotu pocatecniho Close
  double Spread = MarketInfo(NULL, MODE_SPREAD)*Point;                          // zjisti hodnotu spreadu
  int Magic_number = 1001;                                                      // identifikacni cislo strategie
  string Text = "Runner";                                                       // komentar

//+------------------------------------------------------------------+
//| Posun na BE                                                      |
//+------------------------------------------------------------------+
  for(p=0; p<OrdersTotal(); p++)
  {
  
  if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES)==true && OrderType()==OP_BUY && OrderMagicNumber()==Magic_number && Bid>=OrderOpenPrice()
  +BE && OrderStopLoss()<OrderOpenPrice())
  {
  modify = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+PLUS, OrderTakeProfit(), 0, clrBlue);
  }}
  
  {if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES)==true && OrderType()==OP_SELL && OrderMagicNumber()==Magic_number && Ask<=OrderOpenPrice()
  -BE && OrderStopLoss()>OrderOpenPrice())
  {
  modify = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-PLUS, OrderTakeProfit(), 0, clrRed);
  }  
  } 
  
//+------------------------------------------------------------------+
//| Omezovac poctu vstupu                                            |
//+------------------------------------------------------------------+
  for(q=0; q<OrdersTotal(); q++) 
  
  {if(OrderSelect(q, SELECT_BY_POS, MODE_TRADES)&& OrderSymbol()==Symbol()&& OrderMagicNumber()== Magic_number){return;} }
  
  
//+------------------------------------------------------------------+
//| Vstup BUY (LONG)                                                 |
//+------------------------------------------------------------------+
  if (SMA<C)
  { ticket = OrderSend(Symbol(), OP_BUY, Velikost_pozice, Ask, 0, Ask-SL, Ask+PT, Text, Magic_number, 0, clrBlue);}

//+------------------------------------------------------------------+
//| Vstup SELL (SHORT)                                                 |
//+------------------------------------------------------------------+
  if (SMA>C)
  { ticket = OrderSend(Symbol(), OP_SELL, Velikost_pozice, Bid, 0, Bid+SL, Bid-PT, Text, Magic_number, 0, clrRed);}  
  }
//+------------------------------------------------------------------+





Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
One Click Close The script allows users to easily close positions if their profit/loss reaches or exceeds a value specified in pips. Please set slippage value first. Sometimes some positions do not close due to high volatility of the market. Please set larger slippage or restart the script. The free demo version is: ...
 
Please edit your post and
use the code button (Alt+S) when pasting code
 
  1. Keith Watford:
    Please edit your post and
    use the code button (Alt+S) when pasting code
    @michalhrubes what part of edit your original post was unclear. Why didn't you?
  2. michalhrubes:Everything works fine, only for retail trades moving to BE with a profit of PLUS does not work! I can't find a mistake, can anyone help me? Than1k you in advance! Below I enclose the entire AOS code
    1. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
           How To Ask Questions The Smart Way. 2004
                When asking about code

    2. Help you with what? You haven't state a problem in concrete terms with understandable information.
    3. What the heck is AOS?

      Define your acronyms before using them.
         WATCH YOUR LANGUAGE! Use initialisms sparingly to prevent snafus
            How To Ask Questions The Smart Way. 2004
                Be precise and informative about your problem

 

I have deleted your post with the code.

Edit your original post. That is the first post that people will read.

 
Keith Watford:

I have deleted your post with the code.

Edit your original post. That is the first post that people will read.

fixed, thanks for the warning

 

Always loop the order queue back to front.

for(q=OrdersTotal()-1; q>=0; q--)
 
lippmaje:

Always loop the order queue back to front.

Please lippmaje, thanks a lot for the answer, I just didn't understand exactly where to enter: for (q = OrdersTotal () - 1; q> = 0; q--)?

Will it be to the input count limiter or to the shift section on BE? What do I need to delete or replace for (q = OrdersTotal () - 1; q> = 0; q--) in my existing code?

Thank you!

 
michalhrubes: What do I need to delete or replace for (q = OrdersTotal () - 1; q> = 0; q--) in my existing code? 

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.

or pay (Freelance) someone to code it. Top of every page is the link Code Base.
          Hiring to write script - General - MQL5 programming forum 2019.08.21

Reason: