MQL4 - EA - Placing an order based on iCustom indicator - Order placement did not follow the signal correctly?

 

Hi all,


I'm trying to do these simple things, but I don't know why it didn't work:

  1. Get a signal from iCustom indicator (Super-Arrow) for the 2 previous candle (shift 2 candles back),
  2. When a buy signal emerges, then place a BUY order, and also draw a vertical line so that I can see if the open position matches the position of the signal.

However - when I backtested the EA, it appears to me that the BUY order (and VLINE) didn't align with the iCustom signal (GREEN ARROW), please see below.

As you can see below, the BUY order (and VLINE) didn't seem to align with the signal (GREEN ARROW), I don't know what did I do wrong.

Order/VLINE doesn't seem to be in the correct position (2 candles after GREEN ARROW)

Here's the code for the EA:

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MT4"
#property link      "https://www.metatrader.com"
#property version   "1.00"
#property strict

input double Lots = 0.1;//Volume to trade
input int TakeProfitPoints = 50;//Take profit in points
input int StopLossPoints = 80;//Stop loss in points
input int SlippagePoints = 3;//Maximum slippage in points
input int PreviousCandle = 2;//Look back to X number of candles

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int op_result = 0;
   double buy = 0, sell = 0, tp_price = 0, sl_price = 0;
   buy = iCustom(_Symbol, 0, "super-arrow-indicator", 0, PreviousCandle);
   sell = iCustom(_Symbol, 0, "super-arrow-indicator", 1, PreviousCandle);

   if(OrdersTotal() == 0)
      if(buy != EMPTY_VALUE && buy > 0)
        {
         tp_price = Ask + NormalizeDouble(TakeProfitPoints * _Point, _Digits);
         sl_price = Ask - NormalizeDouble(StopLossPoints * _Point, _Digits);
         op_result = OrderSend(_Symbol, OP_BUY, Lots, Ask, SlippagePoints, sl_price, tp_price, NULL, 0, 0, clrGreen);
         CreateVerticalLine("BUY", clrYellow);
        }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CreateVerticalLine(string lineName, color lineColour)
  {
   ObjectCreate(0,StringConcatenate("VLine_", lineName, "_", (string)TimeCurrent()),OBJ_VLINE,0,TimeCurrent(),0);
   ObjectSetInteger(0,StringConcatenate("VLine_", lineName, "_", (string)TimeCurrent()),OBJPROP_COLOR, lineColour);
  }
//+------------------------------------------------------------------+


And I have also attached both the EA source file and the indicator EX4 file.


Please if you could help or at least point out what was my mistake, that'd be greatly appreciated.


Thank you,

insignificant.

 
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.
 
Keith Watford:
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.

Ah, apologise and thank you for moving it, will be more careful next time!

Reason: