about tick's information on tester - page 2

 

attachment is not available.

code is as below:

EA:


int Bars_Sleep;
int init()
{
  Bars_Sleep=Time[1]-Time[2];
  return(0);
}


int deinit()
{
  
  return(0);
}

int start()
{
  if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
  if((OrderCloseTime()-OrderOpenTime())/Bars_Sleep<=10&&OrderProfit()<0&&(TimeCurrent()-OrderCloseTime())/Bars_Sleep<=2)
  return(0);
  Move_Stop_Loss();
  int Signal=iCustom(NULL,0,"PT_Ind",16,Bars_Sleep/60,1,0);
  if(Signal==-1) return(0);
  if(OrdersTotal()==0)
  {
    if(Signal==0){iWait();OrderSend(Symbol(),Signal,1,Ask,3,Ask-150*Point,0,0,0,0,0);}
    else if(Signal==1){iWait();OrderSend(Symbol(),Signal,1,Bid,3,Bid+150*Point,0,0,0,0,0);}
  }
  else if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS))
  {
    if(OrderType()==OP_BUY&&Signal==1) 
      {if(OrderClose(OrderTicket(),1,Bid,3,0)) OrderSend(Symbol(),Signal,1,Bid,3,Bid+150*Point,0,0,0,0,0);}
    else if(OrderType()==OP_SELL&&Signal==0) 
      {if(OrderClose(OrderTicket(),1,Ask,3,0)) OrderSend(Symbol(),Signal,1,Ask,3,Ask-150*Point,0,0,0,0,0);}
   }
  return(0);
}

void Move_Stop_Loss()             // Stop loss line will go when absolute value of current price minus stop loss price is  
{                                 // bigger than big stop level, and when order profit grows big, the stop level should 
  int OT=OrdersTotal();           // be changed to small stop level from the big one.                     
  if(OT==0) return;
    if(OrderSelect(OT-1,SELECT_BY_POS))
    {
      int Profit_Point=NormalizeDouble(MathAbs(Close[0]-OrderOpenPrice())/Point,0); 
      int Move_Stop=300; //if(Profit_Point>0&&Profit_Point<=500) 
      if(Profit_Point>500) Move_Stop=150;
      if(MathAbs(Close[0]-OrderStopLoss())>Move_Stop*Point)
      if(OrderType()==OP_BUY) {iWait();OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-Move_Stop*Point,0,0,0);}
      else if(OrderType()==OP_SELL) {iWait();OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+Move_Stop*Point,0,0,0);}
    }
  return;
}

void iWait()
{
  if(IsTradeContextBusy()||!IsTradeAllowed())
  Sleep(110);
  RefreshRates();
  return;
}


Indicator:

#property  indicator_chart_window
#property  indicator_buffers 1
#property  indicator_color1  Red

extern int Seek_Period = 15, Time_Frame=15;
double PT_Buffer[],Signal[1];

int init()
{ 
  IndicatorBuffers(2);
  SetIndexStyle(0,DRAW_SECTION, STYLE_SOLID, 2);
  SetIndexBuffer(0, PT_Buffer);
  SetIndexDrawBegin(0,Seek_Period*3);
  SetIndexBuffer(1,Signal);
  Print("Seek_Period and Time_Frame: ",Seek_Period," , ",Time_Frame);
  return(0);
}

int start()
{
  Signal[0]=-1.0;
  int counted_bars=IndicatorCounted();
  if(counted_bars==0) int Limit=Bars-counted_bars-1;
  else Limit=Bars-counted_bars;
  for(int i=Limit; i>=0; i--)
  {
    int P_Point=(High[iHighest(NULL, 0, MODE_HIGH, Seek_Period, i)]-Low[iLowest(NULL, 0, MODE_HIGH, Seek_Period, i)])/Point;
    PT_Buffer[i] = iMA(NULL, 0, P_Point/Time_Frame, 0, MODE_SMA, (PRICE_HIGH+PRICE_LOW+PRICE_CLOSE+PRICE_OPEN)/4, i);
  }

 if(Close[0]-PT_Buffer[0]>=50*Point) //buy  &&Low[iLowest(NULL,0,MODE_LOW,5,0)]>PT_Buffer[0]-50*Point
 { 
   int CNT=1;bool Check=false; //CNT's value has been changed to 0 from 1;
   while(CNT<=3)
   {
     if(Low[CNT]<PT_Buffer[CNT]+5*Point) Check=true; 
     if(Check==true&&Low[CNT]>PT_Buffer[CNT]) break;
     CNT++;
   }
   if(Check==true&&Uniformity(CNT)==1) Signal[0]=0.0; // ||Uni==0&&iLowest(NULL,0,MODE_LOW,Seek_Period*6,0)<=2*Seek_Period
   return(0);
 }
  if(PT_Buffer[0]-Close[0]>=50*Point)//sell &&High[iHighest(NULL,0,MODE_HIGH,5,0)]<PT_Buffer[0]+50*Point
 { 
   CNT=1;Check=false; //CNT's value has been changed to 1 from 0;
   while(CNT<=3)
   {
     if(High[CNT]>PT_Buffer[CNT]-5*Point) Check=true; 
     if(Check==true&&High[CNT]<PT_Buffer[CNT]) break;
     CNT++;
   }
   if(Check==true&&Uniformity(CNT)==0) Signal[0]=1.0; //||Uni==1&&iHighest(NULL,0,MODE_HIGH,Seek_Period*6,0)<=2*Seek_Period
 }
   
  return(0);
}


int Uniformity(int Bars_Shift) //check the uniformity of "Seek_Period" bars from the bar--Bars_Shift.
{
  int CNT=0,CNT_Up=0,CNT_Down=0;
  while(CNT<Seek_Period)
  {
    if((High[CNT+Bars_Shift]+Low[CNT+Bars_Shift])/2<PT_Buffer[CNT+Bars_Shift]) CNT_Up++;
    if((High[CNT+Bars_Shift]+Low[CNT+Bars_Shift])/2>PT_Buffer[CNT+Bars_Shift]) CNT_Down++;
    CNT++;
  }
  if(CNT-CNT_Up<=0) return(0);
  else if(CNT-CNT_Down<=0) return(1);
  else return(-1);
}
 

Sorry, but I do not like doing things via the email as that would be a one-to-one issue. I prefer people collaborate and share their problems and solutions openly on forums like this so that all can participate and benefit.

However, you misunderstand me. I was not requesting your code. I was asking about the timeframe, symbol and other factors. OK, so you say you are using USDJPY and M15 timeframe. That already tells me that it is more of short-term strategy and SPREAD is important.

There is also one VERY IMPORTANT factor which your code is NOT DOING. You are using "points" and that varies by a factor of 10 depending on the number of digits used by the broker. Is your broker using 2 or 3 digits for USDJPY? This is very important!

Your code tells me that you are using an initial stop-loss of 150 points but that is only 15 pips on a 3 digit broker. On a 2 digit broker, that would be 150 pips. That makes a VERY BIG difference to your strategy and to the spread used.

In fact all of your code (including the indicator) is written for "points" and not "pips". Your code should use variables (not constants) for values like stop-loss and trailing-stops in Pips (not points) and then adjust them by a factor of 10 depending on if the broker is 2 digit or 3 digit. As it is, I cannot tell from your code how it is going to trade and how spread will affect it.

Also an important question, what is your brokers average spread (in pips, not points) for the USDJPY? How high can it get at the opening and closing of the week and news events?

These questions about your brokers spread will tell you what you can work with and how your EA will be affected.

Take some time to learn about these very important terms. One recommendation I can give you besides the "MQL4 Book" on this very site, is for you to follow the "School of Pipsology" on the "BabyPips" site, but there are many other places, like "Investopedia's Dictionary", that offer learning material about these terms and concepts.

There may even be many sites offering this information in your own language that would make it easier for you to learn.

I hope all this has been helpful and takes you a step closer to your objective.

 
FMIC:

Sorry, but I do not like doing things via the email as that would be a one-to-one issue. I prefer people collaborate and share their problems and solutions openly on forums like this so that all can participate and benefit.

However, you misunderstand me. I was not requesting your code. I was asking about the timeframe, symbol and other factors. OK, so you say you are using USDJPY and M15 timeframe. That already tells me that it is more of short-term strategy and SPREAD is important.

There is also one VERY IMPORTANT factor which your code is NOT DOING. You are using "points" and that varies by a factor of 10 depending on the number of digits used by the broker. Is your broker using 2 or 3 digits for USDJPY? This is very important!

Your code tells me that you are using an initial stop-loss of 150 points but that is only 15 pips on a 3 digit broker. On a 2 digit broker, that would be 150 pips. That makes a VERY BIG difference to your strategy and to the spread used.

In fact all of your code (including the indicator) is written for "points" and not "pips". Your code should use variables (not constants) for values like stop-loss and trailing-stops in Pips (not points) and then adjust them by a factor of 10 depending on if the broker is 2 digit or 3 digit. As it is, I cannot tell from your code how it is going to trade and how spread will affect it.

Also an important question, what is your brokers average spread (in pips, not points) for the USDJPY? How high can it get at the opening and closing of the week and news events?

These questions about your brokers spread will tell you what you can work with and how your EA will be affected.

Take some time to learn about these very important terms. One recommendation I can give you besides the "MQL4 Book" on this very site, is for you to follow the "School of Pipsology" on the "BabyPips" site, but there are many other places, like "Investopedia's Dictionary", that offer learning material about these terms and concepts.

There may even be many sites offering this information in your own language that would make it easier for you to learn.

I hope all this has been helpful and takes you a step closer to your objective.

Thank you for your time, happy new year!

 
vx0532:

Thank you for your time, happy new year!



Thank you! Happy New Year to you too.

By the way, no one is saying goodbye, you are welcome to continue the discussion.

Have you discovered yet if your broker uses 2 digits or 3 digits for USDJPY and what the average spread is for that currency pair?

 
 
FMIC:



Thank you! Happy New Year to you too.

By the way, no one is saying goodbye, you are welcome to continue the discussion.

Have you discovered yet if your broker uses 2 digits or 3 digits for USDJPY and what the average spread is for that currency pair?


Haha, Ok, thank you.

in the fact, we use several broker, some is 2 digits and some is 3 digits; now I just test my EA on MT4 strategy tester for an demo account which use 3 digits; I have found the average spread is about 18 points.

when I set spread 18 points, I also change stop loss for ordersend() to 163 from 150 because of spread from 5 to 18, and Move_Stop_Loss()'s parameters have do similar change(if not, the result is more worse); I think after this change, the result should be very similar(just subtract more spread), but in the fact, very different.

By the way, just now I have use script--"period_converter" on H1 to get H2's "*.HST" file, but I don';t know how to review Bar chart on H2 and how to test it.

 

Thank you!
 
vx0532:


Haha, Ok, thank you.

in the fact, we use several broker, some is 2 digits and some is 3 digits; now I just test my EA on MT4 strategy tester for an demo account which use 3 digits; I have found the average spread is about 18 points.

when I set spread 18 points, I also change stop loss for ordersend() to 163 from 150 because of spread from 5 to 18, and Move_Stop_Loss()'s parameters have do similar change(if not, the result is more worse); I think after this change, the result should be very similar(just subtract more spread), but in the fact, very different.

By the way, just now I have use script--"period_converter" on H1 to get H2's "*.HST" file, but I don';t know how to review Bar chart on H2 and how to test it.


You should first correct your code (EA and Indicator) to use Pips (with digits correction) and not use points. Use "WHRoeder's" link to 4/5 digit brokers to help you understand and correct your code accordingly.

Also, you should review your code carefully as there are quite a few logic bugs in it which you should fix first before running further tests. for example the following ...

int P_Point=(High[iHighest(NULL, 0, MODE_HIGH, Seek_Period, i)]-Low[iLowest(NULL, 0, MODE_HIGH, Seek_Period, i)])/Point;

... probably should be the following (MODE_LOW instead of MODE_HIGH in iLowest):

int P_Point=(High[iHighest(NULL, 0, MODE_HIGH, Seek_Period, i)]-Low[iLowest(NULL, 0, MODE_LOW, Seek_Period, i)])/Point;

I have tested your code (after correcting a few bugs) for 3-digit broker with spreads up to 1.9 pips (19 points) for the whole of 2013 period and it makes money even with that much spread using your standard settings for stoploss and takeprofit.

It works better in the first half of 2013 but it still makes money in the second half, even thou it is less, but you can make it better by improving the following code:

PT_Buffer[i] = iMA(NULL, 0, P_Point/Time_Frame, 0, MODE_SMA, (PRICE_HIGH+PRICE_LOW+PRICE_CLOSE+PRICE_OPEN)/4, i);

You cannot use "(PRICE_HIGH+PRICE_LOW+PRICE_CLOSE+PRICE_OPEN)/4" as that is not the correct parameter for that function. Use something like "PRICE_WEIGHTED" from the list of "Applied price constants".

Also, to improve the strategy, you will have to have a better equation for "P_Point/Time_Frame" by maybe applying a ratio to it to have the strategy work better in the second half of 2013.

There are several other bugs but I will let you try to find them first and correct them yourself. If you still have difficulties, I will then help you out.

As for, testing with H2, first learn to "walk" before you try to "run". MetaTrader 4 does not have a native H2 (only H1 and H4), so don't try to complicate things for now. Stick to the timeframes available until you have a good working knowledge and practice of the current project.

Your Indicator and EA has potential on the USDJPY so first fix the bugs and also add position sizing and money management to the code. It does not work very well on EURUSD, but seems promising on USDJPY. So complete this code first, before jumping onto other projects.

By improving this code you will learn more, and then you will able to make some money while you work on other projects. That way you will be motivated to continue learning and improving your skills.

 
FMIC:


You should first correct your code (EA and Indicator) to use Pips (with digits correction) and not use points. Use "WHRoeder's" link to 4/5 digit brokers to help you understand and correct your code accordingly.

Also, you should review your code carefully as there are quite a few logic bugs in it which you should fix first before running further tests. for example the following ...

..........................

I have modified my code according to your nice advice as below:

1. int P_Point=(High[iHighest(NULL, 0, MODE_HIGH, Seek_Period, i)]-Low[iLowest(NULL, 0, MODE_LOW, Seek_Period, i)])/Pips_SL;

2. PT_Buffer[i] = iMA(NULL, 0, 10.5*P_Point/Time_Frame, 0, MODE_SMA,PRICE_WEIGHTED, i);

3. if(Digits%2==1) {Pips_SL=Point*10;Pips_Slip=10;Pips_Digits=1;}

else {Pips_SL=Point;Pips_Slip=1;Pips_Digits=0;}

4. changes which caused by item 3, such as: OrderSend(Symbol(),Signal,1,Bid,3*Pips_Slip,Bid+15*Pips_SL,0,0,0,0,0);} and so on.

I have check and run it for a long time, I think there is not other bug, is there?

Regarding the parameters in the procedure, such as" P_Point/Time_Frame", I have change a little for them. for one year, we can modify the parameter to get nice curve, but it often get worse when we run it on other year's data. In the fact, I have test this EA from 2009 to 2013 on usdjpy for M15, only bad for 2011, other years is ok i think. if change " 5" of " if(Close[0]-PT_Buffer[0]>=5*Pips_SL)" to "3", it is very well.

I don;t know whether still there is other bugs, if not, I will try to "add position sizing and money management" as you suggested.

 

Don't use a fixed factor for "10.5*P_Point/Time_Frame". Rather use a External Variable for that ratio. That way you can change and optimise the "Range_Ratio" for different periods as Market Conditions change. Also, you do not have to calculate or even set the "Time_Frame" variable. It already exists - it is called "Period()".

extern double Range_Ratio = 10.5;

...

PT_Buffer[i] = iMA(NULL, 0, Range_Ratio*P_Point/Period(), 0, MODE_SMA,PRICE_WEIGHTED, i);

...


Also, do not use constants in your code like in "if(Close[0]-PT_Buffer[0]>=5*Pips_SL)". Use a externally declared variable (like in "Range_Ratio") so that you can change and optimise in testing:

extern double DeltaRatio = 3;

....

if(Close[0]-PT_Buffer[0]>=DeltaRatio*Pips_SL)"

...


There is still more bugs you need to fix. Keep developing your code and testing it. Make your code readable and understandable. Don't just put everything into one line. That makes it difficult for you to debug. Divide the code up into logical blocks so that you can test and make sure each block is working correctly.

Reason: