Download MetaTrader 5

How to calculate average low and high

To add comments, please log in or register
Tony Chavez
236
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

Keith Watford
Moderator
10533
Keith Watford  
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()
Tony Chavez
236
Tony Chavez  

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

Keith Watford
Moderator
10533
Keith Watford  
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.

whroeder1
17081
whroeder1  
Tony Chavez: I tried it but
  1. 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.
  2. 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.
Tony Chavez
236
Tony Chavez  
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(LastTick.ask > HighV) {
      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
TradeKing-Demo(R) (Build 1031)

SymbolUSDJPYpro (US Dollar vs Japanese Yen)
PeriodDaily (D1) 2016.12.01 00:00 - 2017.01.05 00:00 (2016.12.01 - 2017.01.06)
ModelEvery tick (the most precise method based on all available least timeframes)


Bars in test1032Ticks modelled1507510Modelling quality90.00%
Mismatched charts errors0
Initial deposit10000.00SpreadCurrent (81)
Total net profit-2002.96Gross profit1420.34Gross loss-3423.29
Profit factor0.41Expected payoff-200.30
Absolute drawdown2002.96Maximal drawdown3570.27 (30.87%)Relative drawdown30.87% (3570.27)
Total trades10Short 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%)
Largestprofit trade159.15loss trade-3423.29
Averageprofit trade157.82loss trade-3423.29
Maximumconsecutive wins (profit in money)9 (1420.34)consecutive losses (loss in money)1 (-3423.29)
Maximalconsecutive profit (count of wins)1420.34 (9)consecutive loss (count of losses)-3423.29 (1)
Averageconsecutive wins9consecutive losses1


TradeScript Results

Files:
Tradecript.png 133 kb
whroeder1
17081
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. Perhaps you should read the manual.
    Your code
    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?
Tony Chavez
236
Tony Chavez  
Ok I am very new to both of these languages. It was my understanding that 14 on Tradescript was 14 days.
Fernando Carreiro
3945
Fernando Carreiro  
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.

To add comments, please log in or register