Alternatives to MarketInfo()

 

I developed my EA using MT4 on Alpari and have come to transfer it over onto my broker and found that

MarketInfo(Symbol(),MODE_TICKVALUE)

and

MarketInfo(Symbol(),MODE_STOPLEVEL)

both return a value of 0. I tried using DoubleToStr to see how many decimal places it could be but there is nothing up to 10 decimal places

are there any alternatives I could use to get these levels I'm guessing StopLevel is prob broker specific so would just have to use a defined value but I'm not sure about Tick Value.

 
falsedave:

I developed my EA using MT4 on Alpari and have come to transfer it over onto my broker and found that

MarketInfo(Symbol(),MODE_TICKVALUE)

and

MarketInfo(Symbol(),MODE_STOPLEVEL)

both return a value of 0. I tried using DoubleToStr to see how many decimal places it could be but there is nothing up to 10 decimal places

are there any alternatives I could use to get these levels I'm guessing StopLevel is prob broker specific so would just have to use a defined value but I'm not sure about Tick Value.

Hi falsedave,

You mention Alpari (UK, US, FS, NZ ?) however you did not mention the current broker.

If value of both MarketInfo's MODE_STOPLEVEL and MODE_FREEZELEVEL are zero, that's indicating the broker is ECN broker. I have no idea if MODE_TICKVALUE is zero, I guess you have to define it yourself.


 
Talk to your broker if they have this info and hardcod it in your EA. If you's is ECN broker then the value should not vary much across other ECN brokers.
 

To add a little context to it most of the problem come from my Trailing Stop Code.

void useTrailingStop()
{
   double TS_price; 
   int Type;
   double stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL);
   
   for(int i = OrdersTotal(); i >= 0; i--)
   {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC)
      {
         if(TrailingStop < stoplevel) 
         {
         TrailingStop = stoplevel;
         }      // Makes sure Trailing Stop level cannot be less than minimum.
          
         if(OrderType() != 1)
         {
            if (NormalizeDouble(OrderProfit()/OrderLots()/MarketInfo(Symbol(),MODE_TICKVALUE),0) > TrailingStop)
            {
               TS_price = Bid - (TrailingStop*Point);
               deletePendingOrders();
               Alert(Symbol()," - ",OrderType()," - ",NormalizeDouble(OrderProfit()/OrderLots()/MarketInfo(Symbol(),MODE_TICKVALUE) ,0)," - ",OrderTicket());
               if(TS_price > OrderStopLoss()+stoplevel*Point && (TS_price > OrderOpenPrice()))
               {
                  if(!OrderModify(OrderTicket(), OrderOpenPrice(), TS_price, OrderTakeProfit(), 0, Pink))
                  {
                  Print(Symbol() +" (OrderModify Error) ", GetLastError());
                  }
               }
            }
         }
          
        if(OrderType() != 0 && NormalizeDouble(OrderProfit()/OrderLots()/MarketInfo(Symbol(),MODE_TICKVALUE) ,0) > TrailingStop) 
         {
             TS_price = Ask + (TrailingStop*Point);
             deletePendingOrders();
             
             if(TS_price < OrderStopLoss()-stoplevel*Point && (TS_price < OrderOpenPrice()))
             {
               if(!OrderModify(OrderTicket(), OrderOpenPrice(), TS_price, OrderTakeProfit(), 0, Pink))
               {
                    Print(Symbol() +" (OrderModify Error) ",GetLastError());
               }
             }
         }
      }
   }
}

I am using GKFX which is a spread betting platform here in the U.K. Rather than a traditional broker. As far as I know it is not ECN. I can use order send without a slippage value, and pass the takeprofit and stop loss with the order rather that having to modify the order later on.

The problem is the StopLevel Changes depending on which pair is trading eg. USDJPY is 30 points but GBPUSD is only 20 points. It would be possible to code that but its a bit of a pain in the ass when I could have just got the value from one function.

 

Managed to get round the MODE_TICKVALUE by using

((OrderOpenPrice() - Bid) * Point) - MarketInfo(Symbol(),MODE_SPREAD)

previous line was to return profit as pips rather than currency.

As for the ECN I have no idea now.

If I backtest on Alpari it works perfectly but if I backtest on GKFX it crashes on the first trade.

Even if I change the OrderSends to have no TP and no SL it crashes the strategy tester with no error.

 

Just to update further.

No EA will work on the GKFX backtester they all however run fine on the Alpari backtest. They all stop the backtest as soon as the first order is placed.

They both have the same History data as I copied the .HST files from one to the other. Whats the problem ?

 

Have you looked at the backtester journal?

 
Ickyrus:

Have you looked at the backtester journal?


Only this that backtester journal says is.

2012.08.16 15:10:46     2012.07.30 00:26  Adams Daily Pivot v3 GBPUSDSB,H1: open #1 buy stop 2.00 GBPUSDSB at 1.57488 ok
2012.08.16 15:10:46     Adams Daily Pivot v3 inputs: MAGIC=87520; riskpertrade=0.02; lots=0.1; IdleFromHour=0; IdleToHour=0; BreakevenStart=30; TrailingStop=30; Spacer=100; 
2012.08.16 15:10:46     Tester: margin exchange rate cannot be calculated
2012.08.16 15:10:46     Tester: exchange rate cannot be calculated
2012.08.16 15:10:45     Adams Daily Pivot v3 GBPUSDSB,H1: loaded successfully

Then stops running. Doesnt crash MT4 or anything just stops the backtester.

Happens with all EA so its not just my code thats at fault. Phew !

 

Ha ha found it and sorted it.

For anyone that has this problem in future the solution is.

On the backtester

Go to expert properties - testing tab - and change initial deposit to the correct currency.

Mine was USD should have been GBP.

Reason: