# How to calculate average low and high

236

I am new to MQL I am trying to calculate average low for a given timeframe, I know how to do it in TradeScript but not sure about MQL.

TradeScript: (Ref(Low,14)) - would give the 14 day average low

Moderator
10533

Tony Chavez:

I am new to MQL I am trying to calculate average low for a given timeframe, I know how to do it in TradeScript but not sure about MQL.

TradeScript: (Ref(Low,14)) - would give the 14 day average low

Use iMA()
236

I tried it but the result I was getting vs the TradeScript on the other platform was night and day different.

On a side note when I run my expert in MT4 (back testing) I get good results except at the end date which I take a huge negative is that normal?

22 trades of \$120+ each over a year span then -\$4747 at close of dates

Moderator
10533

Tony Chavez:

I tried it but the result I was getting vs the TradeScript on the other platform was night and day different.

That may make sense to you, it makes no sense to me.

Tony Chavez:

On a side note when I run my expert in MT4 (back testing) I get good results except at the end date which I take a huge negative is that normal?

22 trades of \$120+ each over a year span then -\$4747 at close of dates

Trades are being closed with profit which looks good.

You have a lot of losing open floating trades that are only closed at the end of the test which reveals the truth.

17081

 Tony Chavez: I tried it but Tried what? There are no mind readers her. We can't see your code. We can't see your chart We can't see your result.At the end of a run, all open orders are closed. We can't see your code, but I'll bet you are running without a SL on the orders so instead of seeing the losses periodically, you're seeing them all at the end.
236

void OnTick()
{
//---

HighV = iMA(NULL,0,PERIOD_W1,0,MODE_EMA,5,0)+0.0015;

MqlTick LastTick;

if(SymbolInfoTick(Symbol(),LastTick))
{
double BuyPrice = LastTick.bid + 0.005;
double SellPrice = LastTick.ask + 0.005;
}
if(OrdersTotal() < 5)
OrderSend(Symbol(),OP_SELL,2,Bid,3,0,Bid-0.090,NULL,756,0,Green); }

}

//------------------------- Above MT4 & Below TradeScript

( LAST  <  REF(LOW, 14) )   //-------------Buy Command

( LAST  >  REF(LOW, 5)+.0015) //------------- Sell Command

MT4 Results

H&L

 Symbol USDJPYpro (US Dollar vs Japanese Yen) Period Daily (D1) 2016.12.01 00:00 - 2017.01.05 00:00 (2016.12.01 - 2017.01.06) Model Every tick (the most precise method based on all available least timeframes) Bars in test 1032 Ticks modelled 1507510 Modelling quality 90.00% Mismatched charts errors 0 Initial deposit 10000.00 Spread Current (81) Total net profit -2002.96 Gross profit 1420.34 Gross loss -3423.29 Profit factor 0.41 Expected payoff -200.30 Absolute drawdown 2002.96 Maximal drawdown 3570.27 (30.87%) Relative drawdown 30.87% (3570.27) Total trades 10 Short positions (won %) 10 (90.00%) Long positions (won %) 0 (0.00%) Profit trades (% of total) 9 (90.00%) Loss trades (% of total) 1 (10.00%) Largest profit trade 159.15 loss trade -3423.29 Average profit trade 157.82 loss trade -3423.29 Maximum consecutive wins (profit in money) 9 (1420.34) consecutive losses (loss in money) 1 (-3423.29) Maximal consecutive profit (count of wins) 1420.34 (9) consecutive loss (count of losses) -3423.29 (1) Average consecutive wins 9 consecutive losses 1

Files:
17081

1.  Play video Please edit your post. For large amounts of code, attach it

2. Perhaps you should read the manual.
Documentation
HighV = iMA(
NULL,
0,
PERIOD_W1,
0,
MODE_EMA,
5,
0
)
double  iMA(
string       symbol,           // symbol
int          timeframe,        // timeframe
int          ma_period,        // MA averaging period
int          ma_shift,         // MA shift
int          ma_method,        // averaging method
int          applied_price,    // applied price
int          shift             // shift
);
"TradeScript: (Ref(Low,14))" Doesn't use a 10080 for the period, it uses 14.
Don't know EMA vs SMA.
"TradeScript: (Ref(Low,14))" uses the Low of each bar, not Typical price, (high + low + close)/3
"the result I was getting vs the TradeScript on the other platform was night and day different." Why would you expect them to be the same?
236

Ok I am very new to both of these languages. It was my understanding that 14 on Tradescript was 14 days.
3945

Tony Chavez: Ok I am very new to both of these languages. It was my understanding that 14 on Tradescript was 14 days.

Correct, but "PERIOD_W1" is One Week expressed in Minutes, namely 10080. So how is 10080 the same as 14?

Even if I try to follow your "logic" how could "One Week" be the same as 14 days?

If TradeScript is new to you, then stop comparing them. Learn MQL from scratch and and learn it as if you had never heard of TradeScript before.