Code is not backtesting

 
Create an instance of Ctrade which is a library
testing basically

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
CTrade trade;
//intializing a global trend variable through and enum class since the trend is either up or down
string Trend = "";
void OnStart()
  {
   Alert(" A simple Ea the currently identified a trend");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
// get the ask price
   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
// to create and array for the prices on a weekly timefreame
   MqlRates W1PriceInfo[];
// then we sort the price array from the current candle downwards
   ArraySetAsSeries(W1PriceInfo,true);
// we fill the array with the price data
   int W1PriceData = CopyRates(_Symbol,PERIOD_W1,0,5,W1PriceInfo);
// understanding the trend here is very simple, if the latest weekly close is lower then first weekely open then theb  trned is down
   if(W1PriceInfo[0].open > W1PriceInfo[4].close)
     {
      Trend = "Down";
     }
   else
      if(W1PriceInfo[0].open < W1PriceInfo[4].close)
        {
         Trend = "Up";
        }
//initializing and declaring arryas for both D1 and H4 price data
   MqlRates D1PriceInfo[];
   MqlRates H4PriceInfo[];
// setting the arrays as a series from the current candle downwards
   ArraySetAsSeries(D1PriceInfo,true);
   ArraySetAsSeries(H4PriceInfo,true);
// copying the values into the priceinfo array
   int D1PriceData = CopyRates(_Symbol,PERIOD_D1,0,4,D1PriceInfo);
   int H4PriceData = CopyRates(_Symbol,PERIOD_H4,0,4,H4PriceInfo);
   Comment(Trend);
// sorting both of those arrays downwards
// set up and if structure to get positions that follow the trends
   if((Trend == "Up") && (D1PriceInfo[2].close>D1PriceInfo[3].open) && (PositionsTotal() <= 10) && (H4PriceInfo[2].close>H4PriceInfo[3].open))
     {
      trade.Buy(0.05,NULL,Ask,Ask-150*_Point,Ask+200*_Point,NULL);
     }
   else
      if((Trend == "Down") && (D1PriceInfo[2].close<D1PriceInfo[3].open) && (PositionsTotal() <= 10) && (H4PriceInfo[2].close<H4PriceInfo[3].open))
        {
         trade.Sell(0.05,NULL,Bid,Bid+150*_Point,Bid+200*_Point,NULL);
        }
  }
//+------------------------------------------------------------------+

Hello guys I have put my code, and it does compile but I am un able to test it does anyone know why. For context I am trying to back test through the strategy tester.

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
Smivedor:

Hello guys I have put my code, and it does compile but I am un able to test it does anyone know why. For context I am trying to back test through the strategy tester.

Please edit your post and  paste code wth the </>  

 
Smivedor :
Create an instance of Ctrade which is a library
testing basically

Hello guys I have put my code, and it does compile but I am un able to test it does anyone know why. For context I am trying to back test through the strategy tester .

Please:

  1. Use the Styler in the MetaEditor Code Editor
  2. insert the code correctly: when editing a message, press the button Codeand paste your code into the pop-up window (for the first time I corrected your message and pasted the code correctly)
Styler - Developing programs - MetaEditor Help
Styler - Developing programs - MetaEditor Help
  • www.metatrader5.com
The styler quickly brings a source code design in line with the recommended standard. This makes the code look professional and easy to read. A...
 

Recommendations:

instead of

   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

use SymbolInfoTick (and DO NOT USE 'NormalizeDouble'!!!)


Carefully read all the messages in the "Journal" tab - error messages from the terminal are published there.

Documentation on MQL5: Market Info / SymbolInfoTick
Documentation on MQL5: Market Info / SymbolInfoTick
  • www.mql5.com
SymbolInfoTick - Market Info - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: