Help in coding Trading View strategy in Metaeditor - page 3

 

Could you please provide a sample in visual mode and the problem on EURUSD?

Are you sure that your history data is up to date ?


 

Here you can see a similar case on EURUSD. On 01/03 the code executes a short order. Then, we can see how on 26/03, the daily close is above the close of the 20 previous daily bars, but the code does not launch the corresponding close of the short order and new  buy order on 27/03.

Not sure what you meant by "sample in visual mode", I hope this is clear enough.

Files:
Example_3.jpg  399 kb
 

This is visual mode:

The first order is initiated while omitting the rules so that it starts to trade on the first candle, other wise it can take a long time until the first trade appears that meets one of the two rules.

If you want that just remove the two slashes in the oninit function so that it does not open an immediate order.

So change this:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
// time=iTime(_Symbol,PERIOD_D1,0);   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+ 

To this:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   time=iTime(_Symbol,PERIOD_D1,0);   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
 

I am afraid that was not the problem. I implemented the change you suggested, but I still get the same behaviour. Please check the attached visualization, where you can see how on 26/03, the daily close is above the close of the 20 previous daily bars, but the code does not trigger the corresponding close of the short order and new buy order, on 27/03.

I have seen similar examples on other currency pairs, would it be possible for you to have a look at it? I can provide you further details if required.

Thanks again!

Files:
Example_4.JPG  391 kb
 


Please check visualization.

It seems to be working on this end.

I will try 4th time.

Please specify your testing dates from - to
 

Using your previous visualization, we can see how on 26/03, the daily close is above the close of the 20 previous daily bars, but the code does not launch the corresponding close of the short order and new  buy order on 27/03.


Checking the last image you sent (you can find it below), I think I have realized where the error is. My strategy should be based only on the CLOSE of the last 20 days, and compare it with the CLOSE of the current day. I think your code, by the picture you sent (blue bands), is taking into account the maximum and minimum price of each day, of the last 20 days, instead of taking only the maximum/minimum CLOSE of the last 20 days. My strategy only focuses on the value of the close of the daily bar, it does not care about the open, the maximum or the minimum of the day.

Sorry if the capital letters seemed offensive, I just wanted to make sure you understood what I meant. Have a look and let me know your opinion!

Thanks for everything Marco

 

The blue bands is just a standard 20 Donchian it has nothing to do with the strategy.

I will try to revise the code when i have some time.

 

Hi Marco,

How are you doing? Did you have some time to take a look at the code? 

Thanks for all your help!

 

Marco so nice of you mate.

can you help me please. i found free ea from here https://www.mql5.com/en/forum/42014 but it only opens one trade per trend line. after closing at break even , stop loss or tp it does not reopen new trade. i would like that after a trade is closed at be or sl it should reopen a trade afain on the trend line crossing as original setup is. and i need breakeven too...after certain pips. and if possible partial closing of trades like after 30,50, 100 pips which i can choose myself.

if you could help thanks.

here is the ea attached.




}

不能初始化原因代码 - 命名常量 - 标准常量,列举和架构 - MQL4参考
不能初始化原因代码 - 命名常量 - 标准常量,列举和架构 - MQL4参考
  • docs.mql4.com
//| get text description                                             | //| Expert deinitialization function                                 |
Files:
Reason: