• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 9:51pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 9:51pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 34
Attachments: MyCodeCorner
Exit Attachments

MyCodeCorner

  • Last Post
  •  
  • Page 1 2 3
  • Page 1 2 3
  •  
  • Post #1
  • Quote
  • First Post: Edited Jun 1, 2015 3:11pm May 22, 2015 10:59am | Edited Jun 1, 2015 3:11pm
  •  Kilian19
  • Joined Jan 2011 | Status: Currently in Asia | 839 Posts
I have been writing mql indicators for a long time now and while looking through my collection I thought it would be nice to collect the interesting pieces and put it into one place.

Notice:
I put all my code out here publicly for free (Open Source!) but I do not guarantee that everything works without flaws and I do not take responsibility for harm done to a person in any ways. If you find any bugs or have improvements feel free to contact me. There is no reason for me to keep the code to myself and I annotate it as much as possible as I want the time that went into the creation to be of help for others. Even if my code might not be the best coding style looking at other examples might help people with their programming. All in all please please please always post the mql4 file if you want to distribute anything related to the code posted here and keep the copy right notice in the file. If I find anyone who intentionally ignores this I will simply leave and keep everything for myself again.


Table of content

  1. Code

    1. CustomChartScale
    2. ScreenSynchronization
    3. SimpleChartNavigation
    4. PABacktester
    5. ChartSetup








  2. Whats up next
  3. Help the File xxx does not work.
  4. Mt4 navigational tips
  5. Ranting about programming requests


Upcoming releases: (Whenever I have time)

  1. CommonFunctionLibrary
  2. MoneyManagement class
  3. OfflineChartFramework
  4. Java Mt4 Bridge + API
  5. Mql4 video capture support
  6. Greasymonkey script (FF) mql4 code syntax highlighting

----------------------------------------------------------------------------------------------------------------------------------------------------

CustomChartScale

Type:Indicator

JensG asked if there is a possibility to increse the font size of the price scale for better visibility. (http://www.forexfactory.com/showthre...77#post8271277)
The code hides the charts original price scale as well as the grid and draws a new customizable scale and grid on the chart.
If the chart width or height changes due to resizing it needs little bit time to readjust the background of the scale. Scrolling back and forth helps.

Parameters

clrNone usually means use the chart default color

------Label Settings------
color Label Color | Color of the price tags
uint Font Size
int xLabelOffset | Left and right adjustment
int yLabelOffset | Up and down adjustments

The greater the value the further away. The offset also gets adjusted automatically with the font size and screen width.. Negative values are allowed to shift in the other direction.

------Price Background -------
color backgroundColor;
color borderColor; | in pixel
int widthScale = 110;

------Grid Settings------
color Grid Colory;
ENUM_LINE_STYLE Line Style
int Grid Line Width
int Number Grid Lines | number label lines


Preview:

Inserted Video


Attached File
File Type: mq4 CustomScale_v2.mq4   13 KB | 1,820 downloads

----------------------------------------------------------------------------------------------------------------------------------------------------

ScreenSynchronization

Type:Indicator

This is a really really simple indicator which mirrors the chart scrolling of one chart to defined other charts. It tries to set the open time of the right most candle equal on all charts. Due to mql sometimes counting half candles on the chart and sometimes not here can be an offset of 1 2 bars occasionally.
The code is not fancy or nice but it's doing it's job

Parameters

enum ChartSelection
{

ALL_CHARTS,

SAME_CURRENCY,

SAME_CURRENCY_AND_TF,

SAME_TF

};

ChartSelection syncronize = ALL_CHARTS;

Preview:

Inserted Video


Attached File
File Type: mq4 ChartSynchronization.mq4   6 KB | 1,026 downloads

----------------------------------------------------------------------------------------------------------------------------------------------------

SimpleChartNavigation Widget

Type:Indicator

I am trading news events and finding the exact time on a chart can be bothersome. (You can press enter and input the symbol and time but I never really liked that feature) Simply put in the desired time symbol and timeframe and the widget will move the chart there. I just finished it yesterday and it was one of the first times I worked with the mt4 gui.


Parameters:

bool autoDisableAutoScrolling //Disable Autoscrolling After Jump
bool markJumpWithTrendline // Draw Trendline At Destination
color trendlineColor /Trendline Color
int tWidth //Trendline Width


Preview

Inserted Video


Attached File
File Type: mq4 SimpleChartNavigator.mq4   12 KB | 3,546 downloads

----------------------------------------------------------------------------------------------------------------------------------------------------

PA Backtester

Type:Indicator

A few years ago Tyoon asked for an indicator which could hide parts of the screen (http://www.forexfactory.com/showthre...92#post5316792) A few days ago I was asked by a member of this forum if I can make it support jumping between multiple timeframes and decided to rewrite the entire thing.
All it does it moving a huge lable over the candles in the desired speed enabling you to practice pa during the weekend or to look at charts and compare your prediction with reality in an easy way. You can do the same with the visual strategy tester mode but you can not look at different time frames or set the speed exactly to what you want. I am not sure if it's useful or not but I leaned a lot about gui programming when creating it.

Parameters:

clrNONE = chart background color

color hideAreaColor
color trendlineColor //Border Color
int initialMSSpeed //Scroll Delay Speed

Inserted Video


Attached File
File Type: mq4 PABacktesterV3.1.mq4   21 KB | 972 downloads | Uploaded Jun 1, 2015 3:10pm


Changelog:

 

  1. 01.06.15 V3 Fixed a bug that covered half the last candle.
  2. 25.05.15 V2 Indicator now also hides the indicator window. (See http://www.forexfactory.com/showthre...51#post8282851 for the original version). Everything seems to work alright until you add a new indicator after the PA_Backtester has been added to the chart. This seems to break this indicator but due to me being on holiday tomorrow for a week and me wanting to release this version before you have to live with that for now.

Attachment 1681059

------------------------

ChartSetup

Type:Script

This is a 2 line script which allows you to hide the price and time scale. I have not found a way to do this without a script. (I guess here is no copyright needed ).

Parameters
bool showTimeScale;
bool showPriceScale;

Attached File
File Type: mq4 SetUpChart.mq4   1 KB | 724 downloads

----------------------

Up Next

CommonFunctionLibrary:

Type:IncludeFile

This looks roughly like hanovers common library but with less string functions and more focus to object orientation, byte and network support.
I think very useful is the implemented of hashtables which allows you to store Key/Value pairs. For that all primitive data types are wrapped into an own class.


MoneyManagement library.

Type:IncludeFile

This is probably one of the most useful code selections I have. It performs the tp sl and lot calculation based on defined values. You can switch between 4 or 5 different money management models like risk based,fractional,fixed fractional, (anti/martingale (maybe I take this out)) etc ..

OfflineChartFramework.

Type:IncludeFile

Offline charts are simply charts whose data feed is written by ourselves meaning we push what ever values we want to the candle whenever we want. This allows us the creation of renko tick and all kinds of other charts which behave almost exactly like usual mt4 charts.

If you have a lot of different offline charts writing the hist file is probably the most annoying task to do which is exactly the same for all kinds of offline charts so I decided to create a framework for it.

The superclass takes care of all the file handling and the emulation of the update commands.

Every custom chart type has a subclasses which has to take care about what happens with the current data every tick. If a custom bar opening different from the attached chart is wanted this condition has also be stated.

In depth documentation will be posted when released and this one is cleaner and better commented than everything else I have posted here.

Example to implement an own chart which shows how the spread changed during the time:

Attached Image (click to enlarge)
Click to Enlarge

Name: OfflineChartGenerator.png
Size: 74 KB


Red: An indicator with 3 lines of self written code has to be applied to the chart.

Orange: TickManipulation: The logic about what data should be displayed in the current bar.

And you are basically done. Now you get a chart which shows you how the spread changed and you could analyze it with moving averages or your super macd if you wanted.

Attached Image (click to enlarge)
Click to Enlarge

Name: SpreadChart.jpg
Size: 683 KB


Already implemented and ready to use

TICK_CHART = 1, (with # of ticks/chart as input)
RENKO_CHART = 2,
SPREAD_CHART = 3,
BASKET_CHART = 4, (multi currency)
CUSTOM_RENKO_CHART = 5, (taking vertain properties of tf based and renko charts and combining them)
PERIOD_CHART = 6, (12 min chart? No problem)
RANDOM_CHART = 7; (simple randomly gaus number generated chart with x% probability to increase and 100 - x% probability to decrease every tick)

I want a ranged bar chart as well but it's not finished yet.

Java bridge and api: Not much to say, I just like programming in Java

------------------------------------------------------------------------------------------------------------------------------

Help the code does not work

While there might be bugs in the code the indicator should usually initialize and run at your terminal. I did my best to test everything before releasing it but if you find any bugs feel free to post them.
If you put the file in the correct folder and it still does not run there might be some important include files missing which should usually already be included in the default installation of your terminal. If you encounter this problem you open the corresponding indicator in your metaeditor and try to compile it.

At the bottom warnings and errors displayed. You can ignore everything with a yellow sign next to it but if there is a red circle the code will not run. Keep an eye out for something that says

"can't open" ...........

Attached Image (click to enlarge)
Click to Enlarge

Name: error.jpg
Size: 24 KB
.

It tells us that the file DateDropList.mqh can not be found and opened. To fix this you have to put the missing file in the correct directory and you should be good.
Here are all files that could be missing at your terminal (if you can't find a certain file just tell me and I will upload it).

Attached File
File Type: rar Include.rar   175 KB | 590 downloads




Mt4 navigational tips:

While these might be obvious for frequent traders I have only found those little arrow recently (or found them earlier and forgot about them again ).

Attached Image (click to enlarge)
Click to Enlarge

Name: chartExplanation.jpg
Size: 507 KB


1: if you enabled the chart shift you can drag the little arrow at the top of the chart to determine how much space you have at the edge of the chart.
2: this arrow has been hiding from me for a long time. If you disable! autoscrolling you can drag this arrow to a position on the chart and the bar which is at the same height as this arrow will be the fix point for zooming. If bar A is 300 px from the left side of the screen it will always stay these 300 px away from the side during zooming in and out.



Please for the sake of programming requests:

Creating a thread about mql4 carries the risk that people send pms requesting to program eas for them. I am not interested in creating EAs as past has thought me that this is mostly wasted time. It took me years of preparation and roughly 15 months of designing testing and coding my personal ea. There is no such thing as you having a good idea while showering and it's magically working if put into code. Either you have a concept and can prove it for a long timeframe (not just eyeballing) or it's most likely not going to work. Do your homework before contacting someone you want to work for you for free.
Someone here on the forum said a person who can formulate requirements can program himself, and sadly this is true in most cases. I have never seen a mechanical EA request which could be translated 1:1 into code. Gems include the ea should differentiate between real breakouts and fake spikes or if the price moves to far away do something.
While this is a little bit of topic a few words to system design. You first should make up your mind about what could work and why it could work.
I have seen so many eas being write which got heavily curve fitted to the past. It's essentially the same thing like telling the ea the exact timestamps it should take trades for back test purpose. Either it already works like you intended from the beginning or it's most likely not going to work at all.
If you start to add filters to make it profitable you might want to stop already and try to think about another way to achieve your goal. I have seen so many filters requests being made to existing eas and how many have improved them? 0!
The best suggestion I can give you is to focus on money management. While it can not turn an unprofitable system into a profitable one (like martingale people are claiming!) it will certainly have the biggest impact on your trading results.

Additionally I do not create indicators or simply add an alert. I like to write utility code which differentiates from the great mass of already existing indicators. Basically things that could be beneficial in one way or another apart from telling you where the price is going. Indicators usually get requested, it takes a long time to program them and then they are thrown away after a few minutes of testing. Next step is to add an alert and after that another filter a dashboard and mtf support. I have had no luck with technical indicators but only with a combination of technical and fundamentals and believe me I have coded more indicators myself as most of you have probably tried out in your trading carrier.
  • Post #2
  • Quote
  • Edited May 23, 2015 8:00am May 22, 2015 2:00pm | Edited May 23, 2015 8:00am
  •  j4d
  • Joined Jan 2009 | Status: Time to vacate... | 8,336 Posts
Quoting Kilian19
Disliked
SimpleChartNavigation Widget I am trading news events and finding the exact time on a chart can be bothersome. .
Ignored
Hey Killian...

This indicator has just saved me a lot of work..

Thanks for posting ..its really appreciated ..

Jay
Memories caught in time but never forgotten
 
 
  • Post #3
  • Quote
  • May 22, 2015 2:53pm May 22, 2015 2:53pm
  •  braintheboss
  • Joined Nov 2012 | Status: Coder | 8,507 Posts
Very good work
Try don't lose pants never...
 
 
  • Post #4
  • Quote
  • May 22, 2015 6:19pm May 22, 2015 6:19pm
  •  Shabs19
  • Joined Aug 2006 | Status: Member | 2,955 Posts
Hi Kilian,

The PA Backtester does not seem to compile, I assume it is an indicator.
I have attached the text file showing errors.
Am I doing something wrong here ?

Attached Image (click to enlarge)
Click to Enlarge

Name: PABacktester.jpg
Size: 566 KB
Follow the Money
 
 
  • Post #5
  • Quote
  • May 22, 2015 11:18pm May 22, 2015 11:18pm
  •  KeroroQ
  • | Additional Username | Joined Oct 2013 | 92 Posts
Thank you for the backtester killian, really neat work!
One Punch, One Kill
One Punch Trader All Time Return: -3.2%
 
 
  • Post #6
  • Quote
  • May 23, 2015 2:01am May 23, 2015 2:01am
  •  francisakz
  • | Joined Mar 2013 | Status: Member | 249 Posts
Beautiful concept and a fantastic thread. Wish you the Best man
 
 
  • Post #7
  • Quote
  • May 23, 2015 7:18am May 23, 2015 7:18am
  •  Kilian19
  • Joined Jan 2011 | Status: Currently in Asia | 839 Posts
Quoting Jaywalking;
Disliked
This indicator has just saved me a lot of work..
Thanks for posting ..its really appreciated ..

Jaywalking
Ignored
Great I could help

Quoting Shabs19
Disliked
Hi Kilian, The PA Backtester does not seem to compile, I assume it is an indicator. I have attached the text file showing errors. Am I doing something wrong here ? {image}
Ignored
That is because it is an indicator. Just put it in the indicator folder and you should be good. With the new changes to mt4 you can basically do everything in an indicator which you can do in an EA except trading and since you can have multiple indicators / charts this is the preferred way to code for me.
The next time I edit the main post I will explicitly state what type of code it is. (Include, Script, Indicator, EA etc ...)

Edit: It seems like the file you have is already in the indicator folder. The errors already start at the 2nd or 3rd line of code which is kind of weird. Could you please re download the indicator put it in the indicator folder then load it up in the meta editor compile it and tell me if any errors appear?

One thing I forgot to mention is that 1 Folder and file was missing for me when I created the indicator which was Tools/DateTime.mqh I am not sure if it was only missing in my installation or it's a wide spread issue but I simply copied it over from mt5. I wanted to include it in the original post but forgot to do so. I will also explain this in the first post once I have more time. (work around the house needs to be done )
Attached File
File Type: zip DateTime.zip   2 KB | 539 downloads




How about we convert the PA Backtester to an Trade backtester? You can hypothetically take trades and it will calculate the equity and balance for you at any given time as well as draw the trades on the chart? If you can enable or disable this feature nobody should object against that.

I always overload my code with features (the reason why I did not get the common library release ready by now ...) so I have to hold back sometimes.

As well thank you everyone else for posting. It's always good to see if the work gets appreciated.
 
 
  • Post #8
  • Quote
  • May 23, 2015 7:21am May 23, 2015 7:21am
  •  Shabs19
  • Joined Aug 2006 | Status: Member | 2,955 Posts
I have loaded PA Backtester as an indicator in MQL4/indicator folder using the data folder in MT4
Still can't get it to load.
Any help appreciated.

Also same with 2 other indicators, Simple Chart Navigator & Chart synchronization
Follow the Money
 
 
  • Post #9
  • Quote
  • May 23, 2015 7:54am May 23, 2015 7:54am
  •  Shabs19
  • Joined Aug 2006 | Status: Member | 2,955 Posts
I have uploaded the PA Backtester file again, added the DateTime.mqh in to the include file and compiled via metaeditor
Still not working, showing 30 errors now. See screenshots ( in 2 parts)

It will be a great tool if we can get it to work.

Attached Image (click to enlarge)
Click to Enlarge

Name: PA Errors 1.jpg
Size: 300 KB

Attached Image (click to enlarge)
Click to Enlarge

Name: PA Errors 2.jpg
Size: 472 KB
Follow the Money
 
 
  • Post #10
  • Quote
  • May 23, 2015 8:21am May 23, 2015 8:21am
  •  dragan9
  • | Commercial Member | Joined May 2012 | 108 Posts
Kilian,
Thank you very much for PA backtester, if it would be trade backtester, it would be even better

Dragan
fxkeys
 
 
  • Post #11
  • Quote
  • May 23, 2015 10:16am May 23, 2015 10:16am
  •  Kilian19
  • Joined Jan 2011 | Status: Currently in Asia | 839 Posts
Quoting Shabs19
Disliked
I have uploaded the PA Backtester file again, added the DateTime.mqh in to the include file and compiled via metaeditor Still not working, showing 30 errors now. See screenshots ( in 2 parts) It will be a great tool if we can get it to work. {image} {image}
Ignored
Already the first error tells us what is wrong.

Attached Image (click to enlarge)
Click to Enlarge

Name: error.jpg
Size: 24 KB
.

Usually the date drop list should be already included in the installation.

Attached Image (click to enlarge)
Click to Enlarge

Name: datedroplist.jpg
Size: 81 KB

Attached File
File Type: mqh DateDropList.mqh   15 KB | 352 downloads


--------------------------------------------------
To the date time I posted earlier

When you added the DateTime.mqh to the includes folder please be aware that you not only copy the mqh file, but also the tools folder itself.

Attached Image (click to enlarge)
Click to Enlarge

Name: tools.jpg
Size: 92 KB
 
 
  • Post #12
  • Quote
  • May 23, 2015 11:36am May 23, 2015 11:36am
  •  Shabs19
  • Joined Aug 2006 | Status: Member | 2,955 Posts
Hi Kilian,

I think you need to show step by step the installation as if it was a new install of metatrader.
All required files with location etc.

The above steps have completely frozen the current metatrader install, I will have to re-install it now.

I will wait until you can sort out the issues that I am having. Anyone else here has got it working ?
Follow the Money
 
 
  • Post #13
  • Quote
  • May 23, 2015 12:03pm May 23, 2015 12:03pm
  •  Kilian19
  • Joined Jan 2011 | Status: Currently in Asia | 839 Posts
Quoting Shabs19
Disliked
Hi Kilian, I think you need to show step by step the installation as if it was a new install of metatrader. All required files with location etc. The above steps have completely frozen the current metatrader install, I will have to re-install it now. I will wait until you can sort out the issues that I am having. Anyone else here has got it working ?
Ignored
In this case you do not have to reinstall the terminal you can simply delete the indicator file and everything should work correctly again.

I suppose it is working for the people posted above. At least no one else has contacted me so far that it does not work.

It is working for me and if you did the steps stated in Help the code does not work in the main post I don't know how else to help you.
 
 
  • Post #14
  • Quote
  • Edited at 1:59pm May 23, 2015 12:32pm | Edited at 1:59pm
  •  j4d
  • Joined Jan 2009 | Status: Time to vacate... | 8,336 Posts
hey guys... TheSimpleChartNavigation indicator won't compile in my platform ... I will have a further look over the weekend..

Thanks..
Memories caught in time but never forgotten
 
 
  • Post #15
  • Quote
  • May 23, 2015 2:12pm May 23, 2015 2:12pm
  •  erikerxon
  • | Joined Apr 2015 | Status: Member | 20 Posts
great thread! killian, you are da man!
i will test your stuff out tomorrow and will get back with my feedback.
in pips we trust!
 
 
  • Post #16
  • Quote
  • May 24, 2015 2:29am May 24, 2015 2:29am
  •  dragan9
  • | Commercial Member | Joined May 2012 | 108 Posts
Hi Kilian,

Can you make the PA Backtester hide also the bottom indicator window? In this case RSI.

Dragan

Attached Image (click to enlarge)
Click to Enlarge

Name: EURJPY-ProDaily PA Backtester.png
Size: 49 KB
fxkeys
 
 
  • Post #17
  • Quote
  • Edited at 12:18pm May 24, 2015 4:44am | Edited at 12:18pm
  •  Shabs19
  • Joined Aug 2006 | Status: Member | 2,955 Posts
Hi Kilian,

I have discovered that the missing files are only relevant to MT4 build lower than 825
After updating, these files are within the the new build. I would not have had all the issues
had I known that.

One snag with the PA Backtester tool, how do you remove the panel after taking the indicator off ?
It does not appear in the objects list.

edit: The build 825 update caused some of my indicators to stop working & this caused platform freeze, not Kilian's indicators.
Follow the Money
 
 
  • Post #18
  • Quote
  • May 24, 2015 5:54am May 24, 2015 5:54am
  •  FerruFx
  • Joined May 2007 | Status: MT4/MT5 EAs/Indicators/Alerts coder | 6,398 Posts | Online Now
Quoting Shabs19
Disliked
It does not appear in the objects list.
Ignored
The objects may be hidden. Try to click on "list all" in the objects list window.
MT4/MT5 EAs/Indicators/Alerts coder
 
 
  • Post #19
  • Quote
  • May 24, 2015 11:44am May 24, 2015 11:44am
  •  Kilian19
  • Joined Jan 2011 | Status: Currently in Asia | 839 Posts
I am busy today. I will take a look at this thread again tomorrow and reply to everything.
 
 
  • Post #20
  • Quote
  • May 25, 2015 6:26am May 25, 2015 6:26am
  •  Shabs19
  • Joined Aug 2006 | Status: Member | 2,955 Posts
Hi Kilian,

The reason that your indicators did not compile or work and those missing files, was that my platform had not yet updated to buid 825
I was not be able to use 3 indicators, PA Backtester, Chart synchronisation & Simple Chart Navigator without the update.
The other indicators had worked fine without the update.

Some of the older indicators that I had, even though they were ex4 files, stopped working & caused the platform to freeze. I had to
remove these indicators, so that I could recover my platform to some kind of normality. I apologise to Kilian, as I thought his indicators
were at fault, they are working just fine now.

I would also like what Dragan has requested in post #16 for the PA Backtester, this was how it was with the Hide Screen.

Thanks again Kilian.
Follow the Money
 
 
  • Platform Tech
  • /
  • MyCodeCorner
  • Reply to Thread
    • Page 1 2 3
    • Page 1 2 3
0 traders viewing now
  • More
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022