stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Making an ea trade on offline chart using OnTick function
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4586
Page 1 of 1
Author:  CharlesKiwitrader [ Wed Jan 27, 2016 6:18 am ]
Post subject:  Making an ea trade on offline chart using OnTick function

Hi coders,
I have some coding experience but need some help as I don't understand how to incorporate the OnTick() into my ea. Basically, I have bought a tick chart indicator from which I can run offline charts as tick charts with whatever no. of ticks etc.
Below is the code given to me from the vendor to add into my ea, so I added this, changed the start() function to OnTick() function (where all functions work from). Then tried to get action with EA on offline chart. Unfortunately I can get a trade to be placed IF there is a signal exactly on the bar when ea placed, but after more new candles have been painted as per new ticks etc, I don't get any more trades placed even if the conditions are correct. Also, all works fine on standard online charts in tester.

So, to make it obvious, I need help on what do I put in the OnTick() function (keep tick indicator updating information to offline chart, but EA not updating?), and what do i put in the start() function, so EA on offline trades as per signals. As my main function in the past has been start() to run my ea's on offline charts. Also, I can get EA initialised as it trades the first signal if on original bar.

OR, I may have totally overlooked something else which may be limiting the EA from actioning all trades!!

Hope someone has an idea for help, thanks.
Regards, Charles

Code: Select all

//+------------------------------------------------------------------+
//| OnChartEvent function                                            |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)		// this function gets executed when a chart event happens (http://docs.mql4.com/basis/function/events)
{
   if (id==CHARTEVENT_CUSTOM+3758)									// this part of code gets executed when RW Tick Chart sends a trigger event to this chart (with ID 3758)
     {
        	  OnTick();											// this is a call to the main function (OnTick)
     }
}
Author:  DigitalCrypto [ Tue Feb 09, 2016 1:43 pm ]
Post subject:  Making an ea trade on offline chart using OnTick function

At the very least you need to make sure you have DLLs enabled on both the generator chart and the offline chart.

FXBlue (fxblue dot come) has a free timeframe generator (tick,range, renko) that works well with most EAs. But keep in mind that a lot of code here wasn't designed to run on offline charts. In particular I was having an issue with spread detection but it could have just been me.

Also I don't know if you will get a response to 3rd party code. I could be wrong. Let me know how you make out.

- David
Author:  CharlesKiwitrader [ Tue Feb 09, 2016 8:56 pm ]
Post subject:  Making an ea trade on offline chart using OnTick function

Hi David,
All sorted .Thanks for your comments.
Regards, Charles
Author:  skinner36 [ Mon Feb 15, 2016 10:05 pm ]
Post subject:  Making an ea trade on offline chart using OnTick function

Hi Charles,

How did you solve the problem? I am having a similar issue.

Thanks,

John
Author:  skinner36 [ Tue Feb 16, 2016 10:39 am ]
Post subject:  Making an ea trade on offline chart using OnTick function

For anyone else who is looking for a solution to this problem I used the OnTimer() event

John
Author:  bda2206 [ Sat Dec 04, 2021 5:46 am ]
Post subject:  Making an ea trade on offline chart using OnTick function

just for the record, heres a onTick sender. its an EA that runs in the source (online) window and sends ticks to the ea in the offline window

Code: Select all

#import "user32.dll"
  int PostMessageW(       int hWnd, int Msg, int wParam, int lParam );
  int SendMessageA(       int hWnd, int Msg, int wParam, int lParam );
  int GetAncestor(        int hWnd, int gaFlags );
  int RegisterWindowMessageW( string message);
  int GetLastActivePopup( int hWnd );
  int GetDlgItem(         int hDlg, int nIDDlgItem );
#import

#import "kernel32.dll"
  int  FindFirstFileA(    string Path, int& Answer[] );
  bool FindNextFileA(     int handle,  int& Answer[] );
  bool FindClose(         int handle );
#import

#define WM_COMMAND 0x0111
#define WM_KEYDOWN 0x0100
#define VK_DOWN      0x28
#define BM_CLICK   0x00F5
#define GA_ROOT         2
#define PAUSE         100
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#property copyright "BDA"
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

#property version "1.3"
#property strict


int OnInit() {

    return(INIT_SUCCEEDED);
}

void hsUpdateChartWindow( string strSymbol, int intTF )
{
   int hwnd = WindowHandle( strSymbol, intTF );
   static int intMT4MsgID = 0;


   if(hwnd!=0)
     {
      PostMessageW(hwnd,WM_COMMAND,33324,0); // update the chart
      int msg = RegisterWindowMessageW("MetaTrader4_Internal_Message");
      if (PostMessageW(hwnd, msg, 2, 1) == 0) //fake a tick
         Print("error");
      else
         Print("Fake Tick triggered");
     }

}

void OnTick() {
hsUpdateChartWindow( "!T-GBPUSD", 10 ); //(use ontimer() in offline window to alert Symbol() and Period()

}

void OnDeinit(const int reason) {
}
//+------------------------------------------------------------------+

All times are UTC Page 1 of 1